gitlab-runner-tart-driver 0.1.4__py3-none-any.whl → 0.1.6__py3-none-any.whl
Sign up to get free protection for your applications and to get access to all the features.
- gitlab_runner_tart_driver/__init__.py +1 -1
- gitlab_runner_tart_driver/commands/cleanup.py +29 -7
- gitlab_runner_tart_driver/commands/prepare.py +53 -21
- gitlab_runner_tart_driver/commands/run.py +18 -4
- gitlab_runner_tart_driver/modules/gitlab_custom_command_config.py +11 -4
- {gitlab_runner_tart_driver-0.1.4.dist-info → gitlab_runner_tart_driver-0.1.6.dist-info}/METADATA +2 -1
- {gitlab_runner_tart_driver-0.1.4.dist-info → gitlab_runner_tart_driver-0.1.6.dist-info}/RECORD +11 -11
- {gitlab_runner_tart_driver-0.1.4.dist-info → gitlab_runner_tart_driver-0.1.6.dist-info}/LICENSE.txt +0 -0
- {gitlab_runner_tart_driver-0.1.4.dist-info → gitlab_runner_tart_driver-0.1.6.dist-info}/WHEEL +0 -0
- {gitlab_runner_tart_driver-0.1.4.dist-info → gitlab_runner_tart_driver-0.1.6.dist-info}/entry_points.txt +0 -0
- {gitlab_runner_tart_driver-0.1.4.dist-info → gitlab_runner_tart_driver-0.1.6.dist-info}/top_level.txt +0 -0
@@ -1 +1 @@
|
|
1
|
-
__version__ = "0.1.
|
1
|
+
__version__ = "0.1.6"
|
@@ -1,3 +1,5 @@
|
|
1
|
+
import re
|
2
|
+
|
1
3
|
import click
|
2
4
|
|
3
5
|
from gitlab_runner_tart_driver.modules.gitlab_custom_command_config import GitLabCustomCommandConfig
|
@@ -13,16 +15,36 @@ def cleanup(tart_executable):
|
|
13
15
|
tart = Tart(exec_path=tart_executable)
|
14
16
|
tart_vm_name = p.vm_name()
|
15
17
|
|
18
|
+
# remove specific VM that we started
|
19
|
+
_remove_vm(tart, tart_vm_name)
|
20
|
+
|
21
|
+
# cleanup leftovers from previous runs
|
22
|
+
_remove_vm(tart, f"{p.vm_name_prefix}-.*", stopped_only=True)
|
23
|
+
|
24
|
+
|
25
|
+
def _remove_vm(tart, pattern, stopped_only=False):
|
16
26
|
tart_images = tart.list()
|
17
27
|
tart_vm_map = dict()
|
18
28
|
# create map from images
|
19
29
|
for i in tart_images:
|
20
30
|
tart_vm_map[i.name] = i
|
21
31
|
|
22
|
-
|
23
|
-
|
24
|
-
if
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
32
|
+
for vm_name, vm in tart_vm_map.items():
|
33
|
+
m = re.match(pattern, vm_name)
|
34
|
+
if not m:
|
35
|
+
break
|
36
|
+
|
37
|
+
try:
|
38
|
+
if not vm.running and stopped_only:
|
39
|
+
click.echo(f"[INFO] deleting '{vm_name}'")
|
40
|
+
tart.delete(vm.name)
|
41
|
+
elif vm.running and not stopped_only:
|
42
|
+
click.echo(f"[INFO] stopping '{vm_name}'")
|
43
|
+
tart.stop(vm.name)
|
44
|
+
click.echo(f"[INFO] deleting '{vm_name}'")
|
45
|
+
tart.delete(vm.name)
|
46
|
+
elif not vm.running:
|
47
|
+
click.echo(f"[INFO] deleting '{vm_name}'")
|
48
|
+
tart.delete(vm.name)
|
49
|
+
except:
|
50
|
+
click.secho(f"[ERROR] failed to delete '{vm_name}'", fg="red")
|
@@ -194,8 +194,22 @@ def prepare(
|
|
194
194
|
click.echo(f"[INFO] Found VM '{tart_vm_name}'. Going to delete it...")
|
195
195
|
tart.delete(tart_vm_name)
|
196
196
|
|
197
|
+
# verfiy that the limit of running VMs is not exceeded
|
198
|
+
list_running_vms = []
|
199
|
+
for vm in tart.list():
|
200
|
+
if vm.running:
|
201
|
+
list_running_vms.append(vm)
|
202
|
+
|
203
|
+
if len(list_running_vms) >= p.tart_max_vm_count:
|
204
|
+
click.secho("[ERROR] The limit of running VMs is exceeded.", fg="red")
|
205
|
+
sys.exit(1)
|
206
|
+
|
197
207
|
click.echo(f"[INFO] Cloning VM instance '{tart_vm_name}' from '{p.ci_job_image}'")
|
198
|
-
|
208
|
+
try:
|
209
|
+
tart.clone(p.ci_job_image, tart_vm_name)
|
210
|
+
except:
|
211
|
+
click.secho(f"[ERROR] failed to clone image f'{p.ci_job_image}'", fg="red")
|
212
|
+
sys.exit(1)
|
199
213
|
|
200
214
|
if cpu or memory or display:
|
201
215
|
click.echo(f"[INFO] Configuring instance '{tart_vm_name}' from '{p.ci_job_image}'")
|
@@ -234,39 +248,57 @@ def prepare(
|
|
234
248
|
for v in volumes:
|
235
249
|
volume_mounts.append(TartVolume.from_string(v))
|
236
250
|
|
237
|
-
|
238
|
-
|
251
|
+
try:
|
252
|
+
tart.run(tart_vm_name, volume_mounts)
|
253
|
+
except:
|
254
|
+
click.secho(f"[ERROR] Failed to start VM '{tart_vm_name}'", fg="red")
|
255
|
+
sys.exit(1)
|
256
|
+
|
257
|
+
try:
|
258
|
+
ip = tart.ip(tart_vm_name, timeout=timeout)
|
259
|
+
except:
|
260
|
+
click.secho(f"[ERROR] Failed to get IP of VM '{tart_vm_name}'", fg="red")
|
261
|
+
sys.exit(1)
|
262
|
+
|
239
263
|
if not ip:
|
240
264
|
click.echo(f"[ERROR] Error, VM was not reacheable after '{timeout}' seconds")
|
241
265
|
sys.exit(1)
|
242
266
|
|
243
|
-
|
244
|
-
|
245
|
-
f"sudo mkdir -p {remote_script_dir} && sudo chown {p.tart_ssh_username}:{p.tart_ssh_username} {remote_script_dir}",
|
246
|
-
)
|
247
|
-
|
248
|
-
for volume in volume_mounts:
|
249
|
-
click.echo("[INFO] Setting up volume mount '{volume.name}'")
|
267
|
+
try:
|
268
|
+
ssh_session = tart.ssh_session(name=p.vm_name(), username=p.tart_ssh_username, password=p.tart_ssh_password)
|
250
269
|
ssh_session.exec_ssh_command(
|
251
|
-
f"sudo mkdir -p
|
270
|
+
f"sudo mkdir -p {remote_script_dir} && sudo chown {p.tart_ssh_username}:{p.tart_ssh_username} {remote_script_dir}",
|
252
271
|
)
|
253
272
|
|
254
|
-
|
255
|
-
|
256
|
-
|
257
|
-
|
258
|
-
|
273
|
+
for volume in volume_mounts:
|
274
|
+
click.echo(f"[INFO] Setting up volume mount '{volume.name}'")
|
275
|
+
ssh_session.exec_ssh_command(
|
276
|
+
f"sudo mkdir -p $(dirname {volume.dest}); sudo ln -sf '/Volumes/My Shared Files/{volume.name}' {volume.dest}",
|
277
|
+
)
|
259
278
|
|
260
|
-
|
261
|
-
|
262
|
-
|
263
|
-
|
279
|
+
# if cache and builds volumes are not mounted, make sure to create them locally inside the VM
|
280
|
+
if not cache_dir:
|
281
|
+
ssh_session.exec_ssh_command(
|
282
|
+
f"sudo mkdir -p {remote_cache_dir} && sudo chown {p.tart_ssh_username}:{p.tart_ssh_username} {remote_cache_dir}",
|
283
|
+
)
|
284
|
+
|
285
|
+
if not builds_dir:
|
286
|
+
ssh_session.exec_ssh_command(
|
287
|
+
f"sudo mkdir -p {remote_build_dir} && sudo chown {p.tart_ssh_username}:{p.tart_ssh_username} {remote_build_dir}",
|
288
|
+
)
|
289
|
+
except:
|
290
|
+
click.secho(f"[ERROR] Failed so prepare VM '{tart_vm_name}'", fg="red")
|
291
|
+
sys.exit(1)
|
264
292
|
|
265
293
|
if install_gitlab_runner:
|
266
294
|
click.echo(
|
267
295
|
f"[INFO] Installing GitLab Runner '{gitlab_runner_version}' [force: '{force_install_gitlab_runner}']"
|
268
296
|
)
|
269
|
-
|
297
|
+
try:
|
298
|
+
tart.install_gitlab_runner(name=tart_vm_name, username=p.tart_ssh_username, password=p.tart_ssh_password)
|
299
|
+
except:
|
300
|
+
click.secho(f"[ERROR] Failed to install GitLab Runner '{gitlab_runner_version}'", fg="red")
|
301
|
+
sys.exit(1)
|
270
302
|
|
271
303
|
tart.print_spec(tart_vm_name)
|
272
304
|
|
@@ -14,6 +14,9 @@ from gitlab_runner_tart_driver.modules.tart import Tart
|
|
14
14
|
@click.option(
|
15
15
|
"--default-ssh-password", default="admin", required=False, type=str, help="password to login to a tart vm"
|
16
16
|
)
|
17
|
+
@click.option(
|
18
|
+
"--timeout", "ssh_timeout", default=60, required=False, type=int, help="SSH connection timeout in seconds"
|
19
|
+
)
|
17
20
|
@click.option(
|
18
21
|
"-x",
|
19
22
|
"--tart-executable",
|
@@ -31,7 +34,7 @@ from gitlab_runner_tart_driver.modules.tart import Tart
|
|
31
34
|
)
|
32
35
|
@click.argument("script")
|
33
36
|
@click.argument("stage")
|
34
|
-
def run(default_ssh_username, default_ssh_password, tart_executable, shell, script, stage):
|
37
|
+
def run(default_ssh_username, default_ssh_password, ssh_timeout, tart_executable, shell, script, stage):
|
35
38
|
"""Run commands."""
|
36
39
|
p = GitLabCustomCommandConfig()
|
37
40
|
|
@@ -45,10 +48,21 @@ def run(default_ssh_username, default_ssh_password, tart_executable, shell, scri
|
|
45
48
|
######################################################################
|
46
49
|
tart = Tart(exec_path=tart_executable)
|
47
50
|
tart_vm_name = p.vm_name()
|
48
|
-
tart_ip = tart.ip(tart_vm_name, timeout=30)
|
49
|
-
click.echo(f"[INFO] Establishing SSH conntection to '{p.tart_ssh_username}@{tart_ip}'")
|
50
51
|
|
51
|
-
|
52
|
+
try:
|
53
|
+
tart_ip = tart.ip(tart_vm_name, timeout=ssh_timeout)
|
54
|
+
click.echo(f"[INFO] Establishing SSH conntection to '{p.tart_ssh_username}@{tart_ip}'")
|
55
|
+
except:
|
56
|
+
click.secho(
|
57
|
+
f"[ERROR] Could not establish SSH conntection to '{tart_vm_name}' after '{ssh_timeout}' seconds.", fg="red"
|
58
|
+
)
|
59
|
+
sys.exit(1)
|
60
|
+
|
61
|
+
try:
|
62
|
+
ssh_session = tart.ssh_session(name=p.vm_name(), username=p.tart_ssh_username, password=p.tart_ssh_password)
|
63
|
+
except:
|
64
|
+
click.secho(f"[ERROR] Could not establish SSH session with '{p.tart_ssh_username}@{tart_ip}'", fg="red")
|
65
|
+
sys.exit(1)
|
52
66
|
|
53
67
|
click.echo("[INFO] Preparing workspace")
|
54
68
|
remote_temp_dir = "/opt/temp"
|
@@ -1,6 +1,7 @@
|
|
1
1
|
from typing import Optional
|
2
2
|
|
3
3
|
from pydantic import BaseSettings
|
4
|
+
from pydantic import Field
|
4
5
|
|
5
6
|
|
6
7
|
class GitLabCustomCommandConfig(BaseSettings):
|
@@ -13,9 +14,9 @@ class GitLabCustomCommandConfig(BaseSettings):
|
|
13
14
|
ci_concurrent_project_id: str
|
14
15
|
ci_runner_short_token: str
|
15
16
|
ci_project_name: str
|
16
|
-
ci_registry: str
|
17
|
-
ci_registry_user: str
|
18
|
-
ci_registry_password: str
|
17
|
+
ci_registry: Optional[str]
|
18
|
+
ci_registry_user: Optional[str]
|
19
|
+
ci_registry_password: Optional[str]
|
19
20
|
|
20
21
|
tart_registry_username: Optional[str]
|
21
22
|
tart_registry_password: Optional[str]
|
@@ -24,6 +25,8 @@ class GitLabCustomCommandConfig(BaseSettings):
|
|
24
25
|
tart_ssh_username: Optional[str]
|
25
26
|
tart_ssh_password: Optional[str]
|
26
27
|
|
28
|
+
tart_max_vm_count: Optional[int] = Field(default=2)
|
29
|
+
|
27
30
|
class Config:
|
28
31
|
"""Define the prefix used by GitLab for all environment variables passed to a custom driver.
|
29
32
|
see https://docs.gitlab.com/runner/executors/custom.html#stages
|
@@ -33,4 +36,8 @@ class GitLabCustomCommandConfig(BaseSettings):
|
|
33
36
|
|
34
37
|
def vm_name(self):
|
35
38
|
"""Creates a unique name for a VM"""
|
36
|
-
return f"{self.ci_project_name}-{self.ci_pipeline_id}-{self.ci_job_id}-{self.ci_concurrent_id}"
|
39
|
+
return f"{self.vm_name_prefix}-{self.ci_project_name}-{self.ci_pipeline_id}-{self.ci_job_id}-{self.ci_concurrent_id}"
|
40
|
+
|
41
|
+
@property
|
42
|
+
def vm_name_prefix(self):
|
43
|
+
return "grtd"
|
{gitlab_runner_tart_driver-0.1.4.dist-info → gitlab_runner_tart_driver-0.1.6.dist-info}/METADATA
RENAMED
@@ -1,6 +1,6 @@
|
|
1
1
|
Metadata-Version: 2.1
|
2
2
|
Name: gitlab-runner-tart-driver
|
3
|
-
Version: 0.1.
|
3
|
+
Version: 0.1.6
|
4
4
|
Home-page: https://gitlab.com/schmieder.matthias/gitlab-runner-tart-driver
|
5
5
|
Author: Matthias Schmieder
|
6
6
|
Author-email: schmieder.matthias@gmail.com
|
@@ -442,6 +442,7 @@ Usage: gitlab-runner-tart-driver run [OPTIONS] SCRIPT STAGE
|
|
442
442
|
Options:
|
443
443
|
--default-ssh-username TEXT username to login to a tart vm
|
444
444
|
--default-ssh-password TEXT password to login to a tart vm
|
445
|
+
--timeout INTEGER SSH connection timeout in seconds
|
445
446
|
-x, --tart-executable TEXT Path to the tart executable.
|
446
447
|
--shell TEXT Path to the shell to be used for commands over
|
447
448
|
ssh.
|
{gitlab_runner_tart_driver-0.1.4.dist-info → gitlab_runner_tart_driver-0.1.6.dist-info}/RECORD
RENAMED
@@ -1,20 +1,20 @@
|
|
1
|
-
gitlab_runner_tart_driver/__init__.py,sha256=
|
1
|
+
gitlab_runner_tart_driver/__init__.py,sha256=n3oM6B_EMz93NsTI18NNZd-jKFcUPzUkbIKj5VFK5ok,22
|
2
2
|
gitlab_runner_tart_driver/__main__.py,sha256=FiyMv64vDC-R8i3CGEP9QP48djZFHm7utyChwZJWCeY,107
|
3
3
|
gitlab_runner_tart_driver/cli.py,sha256=1eFi9m8L4zcBO5eE4g4EP8phtE1znF54qt-xAigPsOE,596
|
4
4
|
gitlab_runner_tart_driver/commands/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
5
|
-
gitlab_runner_tart_driver/commands/cleanup.py,sha256=
|
5
|
+
gitlab_runner_tart_driver/commands/cleanup.py,sha256=3o2qijQ_okIHJKUWz_k40NhK2pIzkTLyFMKPJToBbVQ,1617
|
6
6
|
gitlab_runner_tart_driver/commands/config.py,sha256=cacJ9ms5r3nZGZ_sS2d21Uoz7S-bMjB__lORUmeXZ-4,760
|
7
|
-
gitlab_runner_tart_driver/commands/prepare.py,sha256=
|
8
|
-
gitlab_runner_tart_driver/commands/run.py,sha256=
|
7
|
+
gitlab_runner_tart_driver/commands/prepare.py,sha256=mx8n4vCfYXGW_ZwtY2PRdgcJPXBy2_BpoeZn9ct7Nqo,11270
|
8
|
+
gitlab_runner_tart_driver/commands/run.py,sha256=n8x4FXQ9iO3TfCybUZM_u6HMs9rEDG-5lqAb_76-LcI,2654
|
9
9
|
gitlab_runner_tart_driver/modules/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
10
|
-
gitlab_runner_tart_driver/modules/gitlab_custom_command_config.py,sha256=
|
10
|
+
gitlab_runner_tart_driver/modules/gitlab_custom_command_config.py,sha256=jD1kKXBFP-4MZQl1zu7jiNpGNVuDtdSPtqIiSQKKi6Q,1264
|
11
11
|
gitlab_runner_tart_driver/modules/gitlab_custom_driver_config.py,sha256=PD7I45PhX1WmZHWUL_Hjr4M0S3vXzqyiwv9UMTEnRy0,405
|
12
12
|
gitlab_runner_tart_driver/modules/tart.py,sha256=gSo1NDwaAnulov8qijhn2TdXsaWI5Vqsuzxy-oakvjQ,8703
|
13
13
|
gitlab_runner_tart_driver/modules/utils.py,sha256=7ipKjy_5tC5iW67Na_A9XhF4o2lKcAqO8LRTTSJKNd0,923
|
14
14
|
gitlab_runner_tart_driver/scripts/install-gitlab-runner.sh.j2,sha256=-rBzxZ92w7lMrTCVcjMHhlZgqPIK1RJKVoOc2wjZvck,2533
|
15
|
-
gitlab_runner_tart_driver-0.1.
|
16
|
-
gitlab_runner_tart_driver-0.1.
|
17
|
-
gitlab_runner_tart_driver-0.1.
|
18
|
-
gitlab_runner_tart_driver-0.1.
|
19
|
-
gitlab_runner_tart_driver-0.1.
|
20
|
-
gitlab_runner_tart_driver-0.1.
|
15
|
+
gitlab_runner_tart_driver-0.1.6.dist-info/LICENSE.txt,sha256=TiYXQpEfbzcPBNGb7k1NslUngq_un-5cxGyT4W1S_f4,3303
|
16
|
+
gitlab_runner_tart_driver-0.1.6.dist-info/METADATA,sha256=-UebsWklpOD3DHKEQ6P77nkCxC9VCzDke8YY6jpORX4,18585
|
17
|
+
gitlab_runner_tart_driver-0.1.6.dist-info/WHEEL,sha256=pkctZYzUS4AYVn6dJ-7367OJZivF2e8RA9b_ZBjif18,92
|
18
|
+
gitlab_runner_tart_driver-0.1.6.dist-info/entry_points.txt,sha256=xmvpGQf1wvFPy5wqDWXu8k5FD_k9KkCNCkpuworTsr0,82
|
19
|
+
gitlab_runner_tart_driver-0.1.6.dist-info/top_level.txt,sha256=JjRzCs2sr24xG4SV_5tIBPpNC1Tec7I4AbK4IKMDqOc,26
|
20
|
+
gitlab_runner_tart_driver-0.1.6.dist-info/RECORD,,
|
{gitlab_runner_tart_driver-0.1.4.dist-info → gitlab_runner_tart_driver-0.1.6.dist-info}/LICENSE.txt
RENAMED
File without changes
|
{gitlab_runner_tart_driver-0.1.4.dist-info → gitlab_runner_tart_driver-0.1.6.dist-info}/WHEEL
RENAMED
File without changes
|
File without changes
|
File without changes
|