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 +193 -367
- snapctl/commands/byosnap.py +397 -315
- snapctl/commands/game.py +63 -57
- snapctl/commands/generate.py +93 -0
- snapctl/commands/snapend.py +361 -281
- snapctl/config/constants.py +72 -8
- snapctl/config/hashes.py +14 -0
- snapctl/main.py +106 -124
- snapctl/types/definitions.py +20 -4
- snapctl/utils/echo.py +10 -2
- snapctl/utils/helper.py +60 -3
- snapctl-0.32.1.dist-info/LICENSE +29 -0
- {snapctl-0.31.1.dist-info → snapctl-0.32.1.dist-info}/METADATA +100 -70
- snapctl-0.32.1.dist-info/RECORD +23 -0
- snapctl-0.31.1.dist-info/RECORD +0 -21
- {snapctl-0.31.1.dist-info → snapctl-0.32.1.dist-info}/WHEEL +0 -0
- {snapctl-0.31.1.dist-info → snapctl-0.32.1.dist-info}/entry_points.txt +0 -0
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
|
|
17
|
-
|
|
18
|
-
|
|
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,
|
|
41
|
-
|
|
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
|
-
|
|
51
|
-
|
|
52
|
-
self.
|
|
53
|
-
|
|
54
|
-
|
|
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
|
-
|
|
66
|
-
self.
|
|
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) ->
|
|
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
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
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
|
-
|
|
114
|
-
|
|
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) ->
|
|
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
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
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
|
-
|
|
150
|
-
|
|
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) ->
|
|
135
|
+
def _docker_build(self) -> None:
|
|
153
136
|
# Get the data
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
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
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
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
|
-
|
|
188
|
-
|
|
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) ->
|
|
174
|
+
def _docker_tag(self) -> None:
|
|
191
175
|
# Get the data
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
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
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
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
|
-
|
|
219
|
-
|
|
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) ->
|
|
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'{
|
|
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
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
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
|
-
|
|
252
|
-
|
|
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) ->
|
|
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
|
-
|
|
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
|
-
|
|
273
|
-
|
|
274
|
-
|
|
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.
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
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) ->
|
|
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
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
return True
|
|
286
|
+
self._check_dependencies()
|
|
287
|
+
self._docker_login()
|
|
288
|
+
self._docker_build()
|
|
364
289
|
|
|
365
|
-
def push(self) ->
|
|
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
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
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
|
|
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
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
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')
|