snapctl 0.31.1__py3-none-any.whl → 0.32.1__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.

Potentially problematic release.


This version of snapctl might be problematic. Click here for more details.

snapctl/commands/byogs.py CHANGED
@@ -3,21 +3,19 @@
3
3
  """
4
4
  import base64
5
5
  from binascii import Error as BinasciiError
6
- import json
7
6
  import os
8
- import re
9
7
  import subprocess
10
8
  from sys import platform
11
9
  from typing import Union
12
- import requests
13
- from requests.exceptions import RequestException
14
10
 
11
+ import typer
15
12
  from rich.progress import Progress, SpinnerColumn, TextColumn
16
- from snapctl.config.constants import SERVER_CALL_TIMEOUT
17
- from snapctl.config.constants import ERROR_SERVICE_VERSION_EXISTS, ERROR_TAG_NOT_AVAILABLE
18
- from snapctl.types.definitions import ResponseType
13
+ from snapctl.config.constants import SNAPCTL_BYOGS_DEPENDENCY_MISSING, \
14
+ SNAPCTL_BYOGS_ECR_LOGIN_ERROR, SNAPCTL_BYOGS_BUILD_ERROR, \
15
+ SNAPCTL_BYOGS_TAG_ERROR, SNAPCTL_BYOGS_PUBLISH_ERROR, \
16
+ SNAPCTL_BYOGS_PUBLISH_DUPLICATE_TAG_ERROR, SNAPCTL_INPUT_ERROR
19
17
  from snapctl.utils.echo import error, success
20
- from snapctl.utils.helper import get_composite_token
18
+ from snapctl.utils.helper import get_composite_token, snapctl_error, snapctl_success
21
19
 
22
20
 
23
21
  class ByoGs:
@@ -25,11 +23,7 @@ class ByoGs:
25
23
  BYOGS CLI commands
26
24
  """
27
25
  SID = 'byogs'
28
- SUBCOMMANDS = [
29
- 'build', 'push',
30
- 'create', 'publish-image', 'publish-version',
31
- 'publish'
32
- ]
26
+ SUBCOMMANDS = ['publish']
33
27
  PLATFORMS = ['linux/amd64']
34
28
  LANGUAGES = ['go', 'python', 'ruby', 'c#', 'c++', 'rust', 'java', 'node']
35
29
  DEFAULT_BUILD_PLATFORM = 'linux/amd64'
@@ -37,34 +31,26 @@ class ByoGs:
37
31
  TAG_CHARACTER_LIMIT = 80
38
32
 
39
33
  def __init__(
40
- self, subcommand: str, base_url: str, api_key: str | None, sid: str, name: str, desc: str,
41
- platform_type: str, language: str, input_tag: Union[str, None], path: Union[str, None],
42
- dockerfile: str, version: Union[str, None], http_port: Union[int, None],
43
- debug_port: Union[int, None]
34
+ self, subcommand: str, base_url: str, api_key: str | None,
35
+ input_tag: Union[str, None], path: Union[str, None], dockerfile: str,
44
36
  ) -> None:
45
37
  self.subcommand: str = subcommand
46
38
  self.base_url: str = base_url
47
39
  self.api_key: str = api_key
48
- self.sid: str = sid
49
- if subcommand == 'publish':
50
- self.sid = ByoGs.SID
51
- self.name: str = name
52
- self.desc: str = desc
53
- self.platform_type: str = platform_type
54
- self.language: str = language
55
- self.token: Union[str, None] = None
56
- if subcommand != 'create':
57
- self.token: Union[str, None] = get_composite_token(
58
- base_url, api_key, 'byogs', {'service_id': self.sid}
59
- )
40
+ # self.sid: str = sid
41
+ # if subcommand == 'publish':
42
+ # self.sid = ByoGs.SID
43
+
44
+ self.token: Union[str, None] = get_composite_token(
45
+ base_url, api_key, 'byogs', {'service_id': ByoGs.SID}
46
+ )
60
47
  self.token_parts: Union[list, None] = ByoGs._get_token_values(
61
48
  self.token) if self.token is not None else None
62
49
  self.input_tag: Union[str, None] = input_tag
63
50
  self.path: Union[str, None] = path
64
51
  self.dockerfile: str = dockerfile
65
- self.version: Union[str, None] = version
66
- self.http_port: Union[int, None] = http_port
67
- self.debug_port: Union[int, None] = debug_port
52
+ # Validate input
53
+ self.validate_input()
68
54
 
69
55
  # Protected methods
70
56
 
@@ -90,279 +76,218 @@ class ByoGs:
90
76
  pass
91
77
  return None
92
78
 
93
- def _check_dependencies(self) -> bool:
79
+ def _check_dependencies(self) -> None:
80
+ progress = Progress(
81
+ SpinnerColumn(),
82
+ TextColumn("[progress.description]{task.description}"),
83
+ transient=True,
84
+ )
85
+ progress.start()
86
+ progress.add_task(
87
+ description='Checking dependencies...', total=None
88
+ )
94
89
  try:
95
90
  # Check dependencies
96
- with Progress(
97
- SpinnerColumn(),
98
- TextColumn("[progress.description]{task.description}"),
99
- transient=True,
100
- ) as progress:
101
- progress.add_task(
102
- description='Checking dependencies...', total=None)
103
- try:
104
- subprocess.run([
105
- "docker", "--version"
106
- ], stdout=subprocess.DEVNULL, stderr=subprocess.STDOUT, check=False)
107
- except subprocess.CalledProcessError:
108
- error('Docker not present')
109
- return False
110
- success('Dependencies Verified')
111
- return True
91
+ result = subprocess.run([
92
+ "docker", "info"
93
+ ], stdout=subprocess.DEVNULL, stderr=subprocess.STDOUT, check=False)
94
+ if not result.returncode:
95
+ return snapctl_success('BYOGS dependencies verified', progress, no_exit=True)
112
96
  except subprocess.CalledProcessError:
113
- error('CLI Error')
114
- return False
97
+ snapctl_error('Snapctl Exception',
98
+ SNAPCTL_BYOGS_DEPENDENCY_MISSING, progress)
99
+ snapctl_error('Docker not running. Please start docker.',
100
+ SNAPCTL_BYOGS_DEPENDENCY_MISSING, progress)
115
101
 
116
- def _docker_login(self) -> bool:
102
+ def _docker_login(self) -> None:
117
103
  # Get the data
118
104
  ecr_repo_url = self.token_parts[0]
119
105
  ecr_repo_username = self.token_parts[1]
120
106
  ecr_repo_token = self.token_parts[2]
107
+ progress = Progress(
108
+ SpinnerColumn(),
109
+ TextColumn("[progress.description]{task.description}"),
110
+ transient=True,
111
+ )
112
+ progress.start()
113
+ progress.add_task(
114
+ description='Logging into Snapser Image Registry...', total=None)
121
115
  try:
122
116
  # Login to Snapser Registry
123
- with Progress(
124
- SpinnerColumn(),
125
- TextColumn("[progress.description]{task.description}"),
126
- transient=True,
127
- ) as progress:
128
- progress.add_task(
129
- description='Logging into Snapser Image Registry...', total=None)
130
- if platform == 'win32':
131
- response = subprocess.run([
132
- 'docker', 'login', '--username', ecr_repo_username,
133
- '--password', ecr_repo_token, ecr_repo_url
134
- ], shell=True, stdout=subprocess.DEVNULL, stderr=subprocess.STDOUT, check=False)
135
- else:
136
- response = subprocess.run([
137
- f'echo "{ecr_repo_token}" | docker login '
138
- f'--username {ecr_repo_username} --password-stdin {ecr_repo_url}'
139
- ], shell=True, stdout=subprocess.DEVNULL, stderr=subprocess.STDOUT, check=False)
140
- if response.returncode:
141
- error(
142
- 'Unable to connect to the Snapser Container Repository. '
143
- 'Please confirm if docker is running or try restarting docker'
144
- )
145
- return False
146
- success('Login Successful')
147
- return True
117
+ if platform == 'win32':
118
+ response = subprocess.run([
119
+ 'docker', 'login', '--username', ecr_repo_username,
120
+ '--password', ecr_repo_token, ecr_repo_url
121
+ ], shell=True, stdout=subprocess.DEVNULL, stderr=subprocess.STDOUT, check=False)
122
+ else:
123
+ response = subprocess.run([
124
+ f'echo "{ecr_repo_token}" | docker login '
125
+ f'--username {ecr_repo_username} --password-stdin {ecr_repo_url}'
126
+ ], shell=True, stdout=subprocess.DEVNULL, stderr=subprocess.STDOUT, check=False)
127
+ if not response.returncode:
128
+ return snapctl_success('BYOGS ECR login successful', progress, no_exit=True)
148
129
  except subprocess.CalledProcessError:
149
- error('CLI Error')
150
- return False
130
+ snapctl_error('Snapctl Exception',
131
+ SNAPCTL_BYOGS_ECR_LOGIN_ERROR, progress)
132
+ snapctl_error('BYOGS ECR login failure',
133
+ SNAPCTL_BYOGS_ECR_LOGIN_ERROR, progress)
151
134
 
152
- def _docker_build(self) -> bool:
135
+ def _docker_build(self) -> None:
153
136
  # Get the data
154
- image_tag = f'{self.sid}.{self.input_tag}'
155
- build_platform = ByoGs.DEFAULT_BUILD_PLATFORM
156
- if len(self.token_parts) == 4:
157
- build_platform = self.token_parts[3]
137
+ progress = Progress(
138
+ SpinnerColumn(),
139
+ TextColumn("[progress.description]{task.description}"),
140
+ transient=True,
141
+ )
142
+ progress.start()
143
+ progress.add_task(
144
+ description='Building your snap...', total=None)
158
145
  try:
146
+ image_tag = f'{ByoGs.SID}.{self.input_tag}'
147
+ build_platform = ByoGs.DEFAULT_BUILD_PLATFORM
148
+ if len(self.token_parts) == 4:
149
+ build_platform = self.token_parts[3]
159
150
  # Build your snap
160
- with Progress(
161
- SpinnerColumn(),
162
- TextColumn("[progress.description]{task.description}"),
163
- transient=True,
164
- ) as progress:
165
- progress.add_task(
166
- description='Building your snap...', total=None)
167
- docker_file_path = f"{self.path}/{self.dockerfile}"
168
- if platform == "win32":
169
- response = subprocess.run([
170
- # f"docker build --no-cache -t {tag} {path}"
171
- 'docker', 'build', '--platform', build_platform, '-t', image_tag,
172
- '-f', docker_file_path, self.path
173
- ], shell=True, check=False)
174
- # stdout=subprocess.DEVNULL, stderr=subprocess.STDOUT)
175
- else:
176
- response = subprocess.run([
177
- # f"docker build --no-cache -t {tag} {path}"
178
- f"docker build --platform {build_platform} -t {image_tag} -f {docker_file_path} {self.path}"
179
- ], shell=True, check=False)
180
- # stdout=subprocess.DEVNULL, stderr=subprocess.STDOUT)
181
- if response.returncode:
182
- error('Unable to build docker')
183
- return False
184
- success('Build Successful')
185
- return True
151
+ docker_file_path = os.path.join(self.path, self.dockerfile)
152
+ if platform == "win32":
153
+ response = subprocess.run([
154
+ # f"docker build --no-cache -t {tag} {path}"
155
+ 'docker', 'build', '--platform', build_platform, '-t', image_tag,
156
+ '-f', docker_file_path, self.path
157
+ ], shell=True, check=False)
158
+ # stdout=subprocess.DEVNULL, stderr=subprocess.STDOUT)
159
+ else:
160
+ response = subprocess.run([
161
+ # f"docker build --no-cache -t {tag} {path}"
162
+ f"docker build --platform {build_platform} -t {image_tag} "
163
+ f"-f {docker_file_path} {self.path}"
164
+ ], shell=True, check=False)
165
+ # stdout=subprocess.DEVNULL, stderr=subprocess.STDOUT)
166
+ if not response.returncode:
167
+ return snapctl_success('BYOGS build successful', progress, no_exit=True)
186
168
  except subprocess.CalledProcessError:
187
- error('CLI Error')
188
- return False
169
+ snapctl_error('Snapctl Exception',
170
+ SNAPCTL_BYOGS_BUILD_ERROR, progress)
171
+ snapctl_error('BYOGS build failure',
172
+ SNAPCTL_BYOGS_BUILD_ERROR, progress)
189
173
 
190
- def _docker_tag(self) -> bool:
174
+ def _docker_tag(self) -> None:
191
175
  # Get the data
192
- ecr_repo_url = self.token_parts[0]
193
- image_tag = f'{self.sid}.{self.input_tag}'
194
- full_ecr_repo_url = f'{ecr_repo_url}:{image_tag}'
176
+ progress = Progress(
177
+ SpinnerColumn(),
178
+ TextColumn("[progress.description]{task.description}"),
179
+ transient=True,
180
+ )
181
+ progress.start()
182
+ progress.add_task(
183
+ description='Tagging your snap...', total=None)
195
184
  try:
185
+ ecr_repo_url = self.token_parts[0]
186
+ image_tag = f'{ByoGs.SID}.{self.input_tag}'
187
+ full_ecr_repo_url = f'{ecr_repo_url}:{image_tag}'
196
188
  # Tag the repo
197
- with Progress(
198
- SpinnerColumn(),
199
- TextColumn("[progress.description]{task.description}"),
200
- transient=True,
201
- ) as progress:
202
- progress.add_task(
203
- description='Tagging your snap...', total=None)
204
- if platform == "win32":
205
- response = subprocess.run([
206
- 'docker', 'tag', image_tag, full_ecr_repo_url
207
- ], shell=True, stdout=subprocess.DEVNULL, stderr=subprocess.STDOUT, check=False)
208
- else:
209
- response = subprocess.run([
210
- f"docker tag {image_tag} {full_ecr_repo_url}"
211
- ], shell=True, stdout=subprocess.DEVNULL, stderr=subprocess.STDOUT, check=False)
212
- if response.returncode:
213
- error('Unable to tag your snap')
214
- return False
215
- success('Tag Successful')
216
- return True
189
+ if platform == "win32":
190
+ response = subprocess.run([
191
+ 'docker', 'tag', image_tag, full_ecr_repo_url
192
+ ], shell=True, stdout=subprocess.DEVNULL, stderr=subprocess.STDOUT, check=False)
193
+ else:
194
+ response = subprocess.run([
195
+ f"docker tag {image_tag} {full_ecr_repo_url}"
196
+ ], shell=True, stdout=subprocess.DEVNULL, stderr=subprocess.STDOUT, check=False)
197
+ if not response.returncode:
198
+ return snapctl_success('BYOGS tag successful', progress, no_exit=True)
217
199
  except subprocess.CalledProcessError:
218
- error('CLI Error')
219
- return False
200
+ snapctl_error('Snapctl Exception',
201
+ SNAPCTL_BYOGS_TAG_ERROR, progress)
202
+ snapctl_error('BYOGS tag failure', SNAPCTL_BYOGS_TAG_ERROR, progress)
220
203
 
221
- def _docker_push(self) -> bool:
204
+ def _docker_push(self) -> None:
205
+ progress = Progress(
206
+ SpinnerColumn(),
207
+ TextColumn("[progress.description]{task.description}"),
208
+ transient=True,
209
+ )
210
+ progress.start()
211
+ progress.add_task(
212
+ description='Pushing your snap...', total=None)
222
213
  try:
223
214
  ecr_repo_url = self.token_parts[0]
224
- image_tag = f'{self.sid}.{self.input_tag}'
215
+ image_tag = f'{ByoGs.SID}.{self.input_tag}'
225
216
  full_ecr_repo_url = f'{ecr_repo_url}:{image_tag}'
226
-
227
217
  # Push the image
228
- with Progress(
229
- SpinnerColumn(),
230
- TextColumn("[progress.description]{task.description}"),
231
- transient=True,
232
- ) as progress:
233
- progress.add_task(
234
- description='Pushing your snap...', total=None)
235
- if platform == "win32":
236
- response = subprocess.run([
237
- 'docker', 'push', full_ecr_repo_url
238
- ], shell=True, check=False)
239
- # stdout=subprocess.DEVNULL, stderr=subprocess.STDOUT)
240
- else:
241
- response = subprocess.run([
242
- f"docker push {full_ecr_repo_url}"
243
- ], shell=True, check=False)
244
- # stdout=subprocess.DEVNULL, stderr=subprocess.STDOUT)
245
- if response.returncode:
246
- error('Unable to push your snap')
247
- return False
248
- success('Snap Upload Successful')
249
- return True
218
+ if platform == "win32":
219
+ response = subprocess.run([
220
+ 'docker', 'push', full_ecr_repo_url
221
+ ], shell=True, check=False)
222
+ # stdout=subprocess.DEVNULL, stderr=subprocess.STDOUT)
223
+ else:
224
+ response = subprocess.run([
225
+ f"docker push {full_ecr_repo_url}"
226
+ ], shell=True, check=False)
227
+ # stdout=subprocess.DEVNULL, stderr=subprocess.STDOUT)
228
+ if not response.returncode:
229
+ return snapctl_success('BYOGS upload successful', progress, no_exit=True)
250
230
  except subprocess.CalledProcessError:
251
- error('CLI Error')
252
- return False
231
+ snapctl_error('Snapctl Exception',
232
+ SNAPCTL_BYOGS_PUBLISH_ERROR, progress)
233
+ snapctl_error('BYOGS upload failure. Duplicate image error.',
234
+ SNAPCTL_BYOGS_PUBLISH_DUPLICATE_TAG_ERROR, progress)
253
235
 
254
236
  # Public methods
255
237
 
256
238
  # Validator
257
- def validate_input(self) -> ResponseType:
239
+ def validate_input(self) -> None:
258
240
  """
259
241
  Validator
260
242
  """
261
- response: ResponseType = {
262
- 'error': True,
263
- 'msg': '',
264
- 'data': []
265
- }
266
243
  # Check API Key and Base URL
267
244
  if not self.api_key or self.base_url == '':
268
- response['msg'] = "Missing API Key."
269
- return response
245
+ snapctl_error("Missing API Key.", SNAPCTL_INPUT_ERROR)
270
246
  # Check subcommand
271
247
  if not self.subcommand in ByoGs.SUBCOMMANDS:
272
- response['msg'] = f"Invalid command. Valid commands are {', '.join(ByoGs.SUBCOMMANDS)}."
273
- return response
274
- # Validate the SID
275
- if not self.sid.startswith(ByoGs.SID):
276
- response['msg'] = (
277
- "Invalid Game Server ID. Valid Game Server IDs start "
278
- f"with {ByoGs.SID}."
279
- )
280
- return response
281
- if len(self.sid) > ByoGs.SID_CHARACTER_LIMIT:
282
- response['msg'] = (
283
- "Invalid Game Server ID. "
284
- f"Game Server ID should be less than {ByoGs.SID_CHARACTER_LIMIT} characters"
285
- )
286
- return response
248
+ snapctl_error(
249
+ f"Invalid command. Valid commands are {', '.join(ByoGs.SUBCOMMANDS)}.",
250
+ SNAPCTL_INPUT_ERROR)
287
251
  # Validation for subcommands
288
- if self.subcommand == 'create':
289
- if self.name == '':
290
- response['msg'] = "Missing name"
291
- return response
292
- if self.language not in ByoGs.LANGUAGES:
293
- response['msg'] = (
294
- "Invalid language. Valid languages "
295
- f"are {', '.join(ByoGs.LANGUAGES)}."
296
- )
297
- return response
298
- if self.platform_type not in ByoGs.PLATFORMS:
299
- response['msg'] = (
300
- "Invalid platform. Valid platforms "
301
- f"are {', '.join(ByoGs.PLATFORMS)}."
302
- )
303
- return response
304
- else:
305
- if self.token_parts is None:
306
- response['msg'] = 'Invalid token. Please reach out to your support team'
307
- return response
308
- # Check tag
309
- if self.input_tag is None or len(self.input_tag.split()) > 1 or \
310
- len(self.input_tag) > ByoGs.TAG_CHARACTER_LIMIT:
311
- response['msg'] = (
312
- "Tag should be a single word with maximum of "
313
- f"{ByoGs.TAG_CHARACTER_LIMIT} characters"
314
- )
315
- return response
316
- if self.subcommand in ['build', 'publish-image', 'publish']:
317
- if not self.input_tag:
318
- response['msg'] = "Missing required parameter: tag"
319
- return response
320
- if not self.path:
321
- response['msg'] = "Missing required parameter: path"
322
- return response
323
- # Check path
324
- if not os.path.isfile(f"{self.path}/{self.dockerfile}"):
325
- response['msg'] = f"Unable to find {self.dockerfile} at path {self.path}"
326
- return response
327
- elif self.subcommand == 'push':
328
- if not self.input_tag:
329
- response['msg'] = "Missing required parameter: tag"
330
- return response
331
- elif self.subcommand == 'publish-version':
332
- if not self.version:
333
- response['msg'] = "Missing required parameter: version"
334
- return response
335
- if not self.http_port:
336
- response['msg'] = "Missing required parameter: Ingress HTTP Port"
337
- return response
338
- pattern = r'^v\d+\.\d+\.\d+$'
339
- if not re.match(pattern, self.version):
340
- response['msg'] = "Version should be in the format vX.X.X"
341
- return response
342
- if not self.http_port.isdigit():
343
- response['msg'] = "Ingress HTTP Port should be a number"
344
- return response
345
- if self.debug_port and not self.debug_port.isdigit():
346
- response['msg'] = "Debug Port should be a number"
347
- return response
348
- # Send success
349
- response['error'] = False
350
- return response
252
+ if self.token_parts is None:
253
+ snapctl_error('Invalid token. Please reach out to your support team',
254
+ SNAPCTL_INPUT_ERROR)
255
+ # Check tag
256
+ if self.input_tag is None:
257
+ snapctl_error("Missing required parameter: tag",
258
+ SNAPCTL_INPUT_ERROR)
259
+ if len(self.input_tag.split()) > 1 or len(self.input_tag) > ByoGs.TAG_CHARACTER_LIMIT:
260
+ snapctl_error(
261
+ "Tag should be a single word with maximum of "
262
+ f"{ByoGs.TAG_CHARACTER_LIMIT} characters",
263
+ SNAPCTL_INPUT_ERROR
264
+ )
265
+ if self.subcommand in ['build', 'publish']:
266
+ if not self.path:
267
+ snapctl_error("Missing required parameter: path",
268
+ SNAPCTL_INPUT_ERROR)
269
+ # Check path
270
+ if not os.path.isfile(f"{self.path}/{self.dockerfile}"):
271
+ snapctl_error(
272
+ f"Unable to find {self.dockerfile} at path {self.path}", SNAPCTL_INPUT_ERROR)
273
+ # elif self.subcommand == 'push':
274
+ # if not self.input_tag:
275
+ # error("Missing required parameter: tag", SNAPCTL_INPUT_ERROR)
276
+ # raise typer.Exit(code=SNAPCTL_INPUT_ERROR)
351
277
 
352
278
  # CRUD methods
353
- def build(self) -> bool:
279
+ def build(self) -> None:
354
280
  """
355
281
  Build the image
356
282
  1. Check Dependencies
357
283
  2. Login to Snapser Registry
358
284
  3. Build your snap
359
285
  """
360
- if not self._check_dependencies() or not self._docker_login() or \
361
- not self._docker_build():
362
- return False
363
- return True
286
+ self._check_dependencies()
287
+ self._docker_login()
288
+ self._docker_build()
364
289
 
365
- def push(self) -> bool:
290
+ def push(self) -> None:
366
291
  """
367
292
  Tag the image
368
293
  1. Check Dependencies
@@ -370,55 +295,13 @@ class ByoGs:
370
295
  3. Tag the snap
371
296
  4. Push your snap
372
297
  """
373
- if not self._check_dependencies() or not self._docker_login() or \
374
- not self._docker_tag() or not self._docker_push():
375
- return False
376
- return True
298
+ self._check_dependencies()
299
+ self._docker_login()
300
+ self._docker_tag()
301
+ self._docker_push()
377
302
 
378
303
  # Upper echelon commands
379
- def create(self) -> bool:
380
- """
381
- Create a new game server
382
- """
383
- with Progress(
384
- SpinnerColumn(),
385
- TextColumn("[progress.description]{task.description}"),
386
- transient=True,
387
- ) as progress:
388
- progress.add_task(
389
- description='Creating your game server...', total=None)
390
- try:
391
- payload = {
392
- "service_id": self.sid,
393
- "name": self.name,
394
- "description": self.desc,
395
- "platform": self.platform_type,
396
- "language": self.language,
397
- }
398
- res = requests.post(
399
- f"{self.base_url}/v1/snapser-api/byogs",
400
- json=payload, headers={'api-key': self.api_key},
401
- timeout=SERVER_CALL_TIMEOUT
402
- )
403
- if res.ok:
404
- return True
405
- response_json = res.json()
406
- if "api_error_code" in response_json:
407
- if response_json['api_error_code'] == ERROR_SERVICE_VERSION_EXISTS:
408
- error(
409
- 'Version already exists. Please update your version and try again'
410
- )
411
- if response_json['api_error_code'] == ERROR_TAG_NOT_AVAILABLE:
412
- error('Invalid tag. Please use the correct tag')
413
- else:
414
- error(
415
- f'Server error: {json.dumps(response_json, indent=2)}'
416
- )
417
- except RequestException as e:
418
- error(f"Exception: Unable to create your game server {e}")
419
- return False
420
-
421
- def publish_image(self) -> bool:
304
+ def publish(self) -> None:
422
305
  """
423
306
  Publish the image
424
307
  1. Check Dependencies
@@ -428,66 +311,9 @@ class ByoGs:
428
311
  5. Push the image
429
312
  6. Upload swagger.json
430
313
  """
431
- if not self._check_dependencies() or not self._docker_login() or \
432
- not self._docker_build() or not self._docker_tag() or not self._docker_push():
433
- return False
434
- return True
435
-
436
- def publish(self) -> bool:
437
- """
438
- Publish the image
439
- 1. Check Dependencies
440
- 2. Login to Snapser Registry
441
- 3. Build your snap
442
- 4. Tag the repo
443
- 5. Push the image
444
- 6. Upload swagger.json
445
- """
446
- if not self._check_dependencies() or not self._docker_login() or \
447
- not self._docker_build() or not self._docker_tag() or not self._docker_push():
448
- return False
449
- return True
450
-
451
- def publish_version(self) -> bool:
452
- """
453
- Publish your game server version
454
- """
455
- with Progress(
456
- SpinnerColumn(),
457
- TextColumn("[progress.description]{task.description}"),
458
- transient=True,
459
- ) as progress:
460
- progress.add_task(
461
- description='Publishing your snap...', total=None)
462
- try:
463
- payload = {
464
- "version": self.version,
465
- "image_tag": self.input_tag,
466
- "http_port": self.http_port,
467
- }
468
- if self.debug_port:
469
- payload['debug_port'] = self.debug_port
470
- res = requests.post(
471
- f"{self.base_url}/v1/snapser-api/byogs/{self.sid}/versions",
472
- json=payload, headers={'api-key': self.api_key},
473
- timeout=SERVER_CALL_TIMEOUT
474
- )
475
- if res.ok:
476
- return True
477
- response_json = res.json()
478
- if "api_error_code" in response_json:
479
- if response_json['api_error_code'] == ERROR_SERVICE_VERSION_EXISTS:
480
- error(
481
- 'Version already exists. Please update your version and try again'
482
- )
483
- if response_json['api_error_code'] == ERROR_TAG_NOT_AVAILABLE:
484
- error('Invalid tag. Please use the correct tag')
485
- else:
486
- error(
487
- f'Server error: {json.dumps(response_json, indent=2)}'
488
- )
489
- except RequestException as e:
490
- error(
491
- f"Exception: Unable to publish a version for your snap {e}"
492
- )
493
- return False
314
+ self._check_dependencies()
315
+ self._docker_login()
316
+ self._docker_build()
317
+ self._docker_tag()
318
+ self._docker_push()
319
+ snapctl_success('BYOGS publish successful')