gitlab-runner-tart-driver 0.1.1__tar.gz → 0.1.3__tar.gz
Sign up to get free protection for your applications and to get access to all the features.
- {gitlab-runner-tart-driver-0.1.1 → gitlab-runner-tart-driver-0.1.3}/PKG-INFO +41 -4
- {gitlab-runner-tart-driver-0.1.1 → gitlab-runner-tart-driver-0.1.3}/README.md +40 -3
- gitlab-runner-tart-driver-0.1.3/gitlab_runner_tart_driver/__init__.py +1 -0
- {gitlab-runner-tart-driver-0.1.1 → gitlab-runner-tart-driver-0.1.3}/gitlab_runner_tart_driver/commands/config.py +2 -2
- {gitlab-runner-tart-driver-0.1.1 → gitlab-runner-tart-driver-0.1.3}/gitlab_runner_tart_driver/commands/prepare.py +102 -6
- {gitlab-runner-tart-driver-0.1.1 → gitlab-runner-tart-driver-0.1.3}/gitlab_runner_tart_driver/commands/run.py +8 -37
- {gitlab-runner-tart-driver-0.1.1 → gitlab-runner-tart-driver-0.1.3}/gitlab_runner_tart_driver/modules/gitlab_custom_command_config.py +2 -0
- {gitlab-runner-tart-driver-0.1.1 → gitlab-runner-tart-driver-0.1.3}/gitlab_runner_tart_driver/modules/tart.py +62 -1
- {gitlab-runner-tart-driver-0.1.1 → gitlab-runner-tart-driver-0.1.3}/gitlab_runner_tart_driver.egg-info/PKG-INFO +41 -4
- {gitlab-runner-tart-driver-0.1.1 → gitlab-runner-tart-driver-0.1.3}/setup.py +1 -1
- gitlab-runner-tart-driver-0.1.1/gitlab_runner_tart_driver/__init__.py +0 -1
- {gitlab-runner-tart-driver-0.1.1 → gitlab-runner-tart-driver-0.1.3}/LICENSE.txt +0 -0
- {gitlab-runner-tart-driver-0.1.1 → gitlab-runner-tart-driver-0.1.3}/gitlab_runner_tart_driver/__main__.py +0 -0
- {gitlab-runner-tart-driver-0.1.1 → gitlab-runner-tart-driver-0.1.3}/gitlab_runner_tart_driver/cli.py +0 -0
- {gitlab-runner-tart-driver-0.1.1 → gitlab-runner-tart-driver-0.1.3}/gitlab_runner_tart_driver/commands/__init__.py +0 -0
- {gitlab-runner-tart-driver-0.1.1 → gitlab-runner-tart-driver-0.1.3}/gitlab_runner_tart_driver/commands/cleanup.py +0 -0
- {gitlab-runner-tart-driver-0.1.1 → gitlab-runner-tart-driver-0.1.3}/gitlab_runner_tart_driver/modules/__init__.py +0 -0
- {gitlab-runner-tart-driver-0.1.1 → gitlab-runner-tart-driver-0.1.3}/gitlab_runner_tart_driver/modules/gitlab_custom_driver_config.py +0 -0
- {gitlab-runner-tart-driver-0.1.1 → gitlab-runner-tart-driver-0.1.3}/gitlab_runner_tart_driver/modules/utils.py +0 -0
- {gitlab-runner-tart-driver-0.1.1 → gitlab-runner-tart-driver-0.1.3}/gitlab_runner_tart_driver.egg-info/SOURCES.txt +0 -0
- {gitlab-runner-tart-driver-0.1.1 → gitlab-runner-tart-driver-0.1.3}/gitlab_runner_tart_driver.egg-info/dependency_links.txt +0 -0
- {gitlab-runner-tart-driver-0.1.1 → gitlab-runner-tart-driver-0.1.3}/gitlab_runner_tart_driver.egg-info/entry_points.txt +0 -0
- {gitlab-runner-tart-driver-0.1.1 → gitlab-runner-tart-driver-0.1.3}/gitlab_runner_tart_driver.egg-info/not-zip-safe +0 -0
- {gitlab-runner-tart-driver-0.1.1 → gitlab-runner-tart-driver-0.1.3}/gitlab_runner_tart_driver.egg-info/requires.txt +0 -0
- {gitlab-runner-tart-driver-0.1.1 → gitlab-runner-tart-driver-0.1.3}/gitlab_runner_tart_driver.egg-info/top_level.txt +0 -0
- {gitlab-runner-tart-driver-0.1.1 → gitlab-runner-tart-driver-0.1.3}/pyproject.toml +0 -0
- {gitlab-runner-tart-driver-0.1.1 → gitlab-runner-tart-driver-0.1.3}/setup.cfg +0 -0
@@ -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.3
|
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
|
@@ -114,15 +114,18 @@ The `config.toml` should be located at `~/.gitlab-runner/config.toml`. Open it a
|
|
114
114
|
[runners.custom]
|
115
115
|
config_exec = "/opt/homebrew/bin/gitlab-runner-tart-driver"
|
116
116
|
config_args = [ "config", '-x', '/opt/homebrew/bin/tart' ]
|
117
|
+
config_exec_timeout = 200
|
117
118
|
|
118
119
|
prepare_exec = "/opt/homebrew/bin/gitlab-runner-tart-driver"
|
119
120
|
prepare_args = [ "prepare", '-x', '/opt/homebrew/bin/tart' ]
|
121
|
+
prepare_exec_timeout = 200
|
120
122
|
|
121
123
|
run_exec = "/opt/homebrew/bin/gitlab-runner-tart-driver"
|
122
124
|
run_args = [ "run", '-x', '/opt/homebrew/bin/tart' ]
|
123
125
|
|
124
126
|
cleanup_exec = "/opt/homebrew/bin/gitlab-runner-tart-driver"
|
125
127
|
cleanup_args = [ "cleanup", '-x', '/opt/homebrew/bin/tart' ]
|
128
|
+
cleanup_exec_timeout = 200
|
126
129
|
```
|
127
130
|
|
128
131
|
Now restart the gitlab-runner with `gitlab-runner restart`
|
@@ -266,6 +269,32 @@ shutdown_timeout = 0
|
|
266
269
|
cleanup_args = [ "cleanup", '-x', '/opt/homebrew/bin/tart' ]
|
267
270
|
```
|
268
271
|
|
272
|
+
### Host Cache and Builds directories
|
273
|
+
|
274
|
+
With `tart` it is possible to mount local directories into the VM. Mounting local directories brings a number of benefits like up tp 30% higher IO performance as well as a correct caching mechanism.
|
275
|
+
To enable Host-local caching and builds, simply pass `--builds-dir` and `--cache-dir` to the `prepare` command
|
276
|
+
|
277
|
+
```ini
|
278
|
+
prepare_exec = "/opt/homebrew/bin/gitlab-runner-tart-driver"
|
279
|
+
prepare_args = [ "prepare", '-x', '/opt/homebrew/bin/tart', '--concurrency', '2', '--auto-resources', '--cache-dir', '/Users/gitlab/gitlab-runner/cache', '--builds-dir', '/Users/gitlab/gitlab-runner/builds']
|
280
|
+
```
|
281
|
+
|
282
|
+
### Volume Mounts
|
283
|
+
|
284
|
+
Just like with `docker` the `gitlab-runner-tart-driver` allows you to mount any arbitrary host path into your VM. This can be especially useful if you have to mount runner-local resources like shared test-data or additional caches into the executor. You can follow the standard docker syntax for *volume mounts* `--volume /my/local/dir:/opt/remote/dir`. Additionally you can also pass the `ro` flag to make the mount *read-only* i.e. `--volume /my/local/dir:/opt/remote/dir:ro`.
|
285
|
+
|
286
|
+
```ini
|
287
|
+
[runners.custom]
|
288
|
+
config_exec = "/opt/homebrew/bin/gitlab-runner-tart-driver"
|
289
|
+
config_args = [ "config" ]
|
290
|
+
|
291
|
+
prepare_exec = "/opt/homebrew/bin/gitlab-runner-tart-driver"
|
292
|
+
prepare_args = [ "prepare",
|
293
|
+
'-x', '/opt/homebrew/bin/tart',
|
294
|
+
'--concurrency', '2',
|
295
|
+
'--auto-resources',
|
296
|
+
'--volume /data/models/:/opt/data/models:ro']
|
297
|
+
```
|
269
298
|
### Auto Host Resource Distribution
|
270
299
|
|
271
300
|
`tart` images come with a pre-defined number of CPUs and Memory allocation. Typical numbers for default images are `cpu_count=4` and `memory=8192`. With the concurrency limitation of two VMs/images running at the same time this might not utilize your host system completely.
|
@@ -324,11 +353,13 @@ Usage: gitlab-runner-tart-driver prepare [OPTIONS]
|
|
324
353
|
Prepare the environment and start the tart VM.
|
325
354
|
|
326
355
|
Options:
|
356
|
+
--default-ssh-username TEXT username to login to a tart vm
|
357
|
+
--default-ssh-password TEXT password to login to a tart vm
|
327
358
|
--pull-policy [always|if-not-present|never]
|
328
359
|
define how runners pull tart images from
|
329
360
|
registries
|
330
361
|
--registry-username TEXT username to login to a oci registry
|
331
|
-
--registry-password TEXT
|
362
|
+
--registry-password TEXT password to login to a oci registry
|
332
363
|
--registry TEXT username to login to a oci registry
|
333
364
|
--cpu INTEGER Number of CPUs associated to VM
|
334
365
|
--memory INTEGER VM memory size in megabytes associated to VM
|
@@ -340,8 +371,14 @@ Options:
|
|
340
371
|
--concurrency INTEGER Number of concurrent processes that are
|
341
372
|
supported. ATTENTION tart currently only
|
342
373
|
support two concurrent VMs
|
374
|
+
--cache-dir TEXT Caching dir to be used.
|
375
|
+
--builds-dir TEXT Path to the builds directory.
|
376
|
+
--timeout INTEGER Timeout in seconds for the VM to be
|
377
|
+
reachable via SSH.
|
378
|
+
--volume TEXT Volume mount definition with docker syntax.
|
379
|
+
<host_dir>:<vm_dir>[:ro]
|
343
380
|
-x, --tart-executable TEXT Path to the tart executable.
|
344
|
-
--help Show this message and exit.
|
381
|
+
--help Show this message and exit. Show this message and exit.
|
345
382
|
```
|
346
383
|
|
347
384
|
### Command `run`
|
@@ -353,7 +390,7 @@ Usage: gitlab-runner-tart-driver run [OPTIONS] SCRIPT STAGE
|
|
353
390
|
|
354
391
|
Options:
|
355
392
|
--default-ssh-username TEXT username to login to a tart vm
|
356
|
-
--default-ssh-password TEXT
|
393
|
+
--default-ssh-password TEXT password to login to a tart vm
|
357
394
|
-x, --tart-executable TEXT Path to the tart executable.
|
358
395
|
--shell TEXT Path to the shell to be used for commands over
|
359
396
|
ssh.
|
@@ -99,15 +99,18 @@ The `config.toml` should be located at `~/.gitlab-runner/config.toml`. Open it a
|
|
99
99
|
[runners.custom]
|
100
100
|
config_exec = "/opt/homebrew/bin/gitlab-runner-tart-driver"
|
101
101
|
config_args = [ "config", '-x', '/opt/homebrew/bin/tart' ]
|
102
|
+
config_exec_timeout = 200
|
102
103
|
|
103
104
|
prepare_exec = "/opt/homebrew/bin/gitlab-runner-tart-driver"
|
104
105
|
prepare_args = [ "prepare", '-x', '/opt/homebrew/bin/tart' ]
|
106
|
+
prepare_exec_timeout = 200
|
105
107
|
|
106
108
|
run_exec = "/opt/homebrew/bin/gitlab-runner-tart-driver"
|
107
109
|
run_args = [ "run", '-x', '/opt/homebrew/bin/tart' ]
|
108
110
|
|
109
111
|
cleanup_exec = "/opt/homebrew/bin/gitlab-runner-tart-driver"
|
110
112
|
cleanup_args = [ "cleanup", '-x', '/opt/homebrew/bin/tart' ]
|
113
|
+
cleanup_exec_timeout = 200
|
111
114
|
```
|
112
115
|
|
113
116
|
Now restart the gitlab-runner with `gitlab-runner restart`
|
@@ -251,6 +254,32 @@ shutdown_timeout = 0
|
|
251
254
|
cleanup_args = [ "cleanup", '-x', '/opt/homebrew/bin/tart' ]
|
252
255
|
```
|
253
256
|
|
257
|
+
### Host Cache and Builds directories
|
258
|
+
|
259
|
+
With `tart` it is possible to mount local directories into the VM. Mounting local directories brings a number of benefits like up tp 30% higher IO performance as well as a correct caching mechanism.
|
260
|
+
To enable Host-local caching and builds, simply pass `--builds-dir` and `--cache-dir` to the `prepare` command
|
261
|
+
|
262
|
+
```ini
|
263
|
+
prepare_exec = "/opt/homebrew/bin/gitlab-runner-tart-driver"
|
264
|
+
prepare_args = [ "prepare", '-x', '/opt/homebrew/bin/tart', '--concurrency', '2', '--auto-resources', '--cache-dir', '/Users/gitlab/gitlab-runner/cache', '--builds-dir', '/Users/gitlab/gitlab-runner/builds']
|
265
|
+
```
|
266
|
+
|
267
|
+
### Volume Mounts
|
268
|
+
|
269
|
+
Just like with `docker` the `gitlab-runner-tart-driver` allows you to mount any arbitrary host path into your VM. This can be especially useful if you have to mount runner-local resources like shared test-data or additional caches into the executor. You can follow the standard docker syntax for *volume mounts* `--volume /my/local/dir:/opt/remote/dir`. Additionally you can also pass the `ro` flag to make the mount *read-only* i.e. `--volume /my/local/dir:/opt/remote/dir:ro`.
|
270
|
+
|
271
|
+
```ini
|
272
|
+
[runners.custom]
|
273
|
+
config_exec = "/opt/homebrew/bin/gitlab-runner-tart-driver"
|
274
|
+
config_args = [ "config" ]
|
275
|
+
|
276
|
+
prepare_exec = "/opt/homebrew/bin/gitlab-runner-tart-driver"
|
277
|
+
prepare_args = [ "prepare",
|
278
|
+
'-x', '/opt/homebrew/bin/tart',
|
279
|
+
'--concurrency', '2',
|
280
|
+
'--auto-resources',
|
281
|
+
'--volume /data/models/:/opt/data/models:ro']
|
282
|
+
```
|
254
283
|
### Auto Host Resource Distribution
|
255
284
|
|
256
285
|
`tart` images come with a pre-defined number of CPUs and Memory allocation. Typical numbers for default images are `cpu_count=4` and `memory=8192`. With the concurrency limitation of two VMs/images running at the same time this might not utilize your host system completely.
|
@@ -309,11 +338,13 @@ Usage: gitlab-runner-tart-driver prepare [OPTIONS]
|
|
309
338
|
Prepare the environment and start the tart VM.
|
310
339
|
|
311
340
|
Options:
|
341
|
+
--default-ssh-username TEXT username to login to a tart vm
|
342
|
+
--default-ssh-password TEXT password to login to a tart vm
|
312
343
|
--pull-policy [always|if-not-present|never]
|
313
344
|
define how runners pull tart images from
|
314
345
|
registries
|
315
346
|
--registry-username TEXT username to login to a oci registry
|
316
|
-
--registry-password TEXT
|
347
|
+
--registry-password TEXT password to login to a oci registry
|
317
348
|
--registry TEXT username to login to a oci registry
|
318
349
|
--cpu INTEGER Number of CPUs associated to VM
|
319
350
|
--memory INTEGER VM memory size in megabytes associated to VM
|
@@ -325,8 +356,14 @@ Options:
|
|
325
356
|
--concurrency INTEGER Number of concurrent processes that are
|
326
357
|
supported. ATTENTION tart currently only
|
327
358
|
support two concurrent VMs
|
359
|
+
--cache-dir TEXT Caching dir to be used.
|
360
|
+
--builds-dir TEXT Path to the builds directory.
|
361
|
+
--timeout INTEGER Timeout in seconds for the VM to be
|
362
|
+
reachable via SSH.
|
363
|
+
--volume TEXT Volume mount definition with docker syntax.
|
364
|
+
<host_dir>:<vm_dir>[:ro]
|
328
365
|
-x, --tart-executable TEXT Path to the tart executable.
|
329
|
-
--help Show this message and exit.
|
366
|
+
--help Show this message and exit. Show this message and exit.
|
330
367
|
```
|
331
368
|
|
332
369
|
### Command `run`
|
@@ -338,7 +375,7 @@ Usage: gitlab-runner-tart-driver run [OPTIONS] SCRIPT STAGE
|
|
338
375
|
|
339
376
|
Options:
|
340
377
|
--default-ssh-username TEXT username to login to a tart vm
|
341
|
-
--default-ssh-password TEXT
|
378
|
+
--default-ssh-password TEXT password to login to a tart vm
|
342
379
|
-x, --tart-executable TEXT Path to the tart executable.
|
343
380
|
--shell TEXT Path to the shell to be used for commands over
|
344
381
|
ssh.
|
@@ -0,0 +1 @@
|
|
1
|
+
__version__ = "0.1.3"
|
@@ -14,8 +14,8 @@ def config():
|
|
14
14
|
https://docs.gitlab.com/runner/executors/custom.html#config."""
|
15
15
|
|
16
16
|
c = GitLabCustomDriverConfig(
|
17
|
-
builds_dir="/
|
18
|
-
cache_dir="/
|
17
|
+
builds_dir="/opt/builds",
|
18
|
+
cache_dir="/opt/cache",
|
19
19
|
hostname=socket.gethostname(),
|
20
20
|
driver=GitLabCustomDriver(name="tart", version=__version__),
|
21
21
|
)
|
@@ -1,14 +1,22 @@
|
|
1
|
+
import os
|
1
2
|
import sys
|
2
3
|
|
3
4
|
import click
|
4
5
|
|
5
6
|
from gitlab_runner_tart_driver.modules.gitlab_custom_command_config import GitLabCustomCommandConfig
|
6
7
|
from gitlab_runner_tart_driver.modules.tart import Tart
|
8
|
+
from gitlab_runner_tart_driver.modules.tart import TartVolume
|
7
9
|
from gitlab_runner_tart_driver.modules.utils import get_host_spec
|
8
10
|
from gitlab_runner_tart_driver.modules.utils import print_host_spec
|
9
11
|
|
10
12
|
|
11
13
|
@click.command()
|
14
|
+
@click.option(
|
15
|
+
"--default-ssh-username", default="admin", required=False, type=str, help="username to login to a tart vm"
|
16
|
+
)
|
17
|
+
@click.option(
|
18
|
+
"--default-ssh-password", default="admin", required=False, type=str, help="password to login to a tart vm"
|
19
|
+
)
|
12
20
|
@click.option(
|
13
21
|
"--pull-policy",
|
14
22
|
default="if-not-present",
|
@@ -16,7 +24,7 @@ from gitlab_runner_tart_driver.modules.utils import print_host_spec
|
|
16
24
|
help="define how runners pull tart images from registries",
|
17
25
|
)
|
18
26
|
@click.option("--registry-username", required=False, default=None, type=str, help="username to login to a oci registry")
|
19
|
-
@click.option("--registry-password", required=False, default=None, type=str, help="
|
27
|
+
@click.option("--registry-password", required=False, default=None, type=str, help="password to login to a oci registry")
|
20
28
|
@click.option("--registry", required=False, default=None, type=str, help="username to login to a oci registry")
|
21
29
|
@click.option("--cpu", required=False, default=None, type=int, help="Number of CPUs associated to VM")
|
22
30
|
@click.option("--memory", required=False, default=None, type=int, help="VM memory size in megabytes associated to VM")
|
@@ -42,8 +50,40 @@ from gitlab_runner_tart_driver.modules.utils import print_host_spec
|
|
42
50
|
type=int,
|
43
51
|
help="Number of concurrent processes that are supported. ATTENTION tart currently only support two concurrent VMs",
|
44
52
|
)
|
53
|
+
@click.option(
|
54
|
+
"--cache-dir",
|
55
|
+
required=False,
|
56
|
+
default=None,
|
57
|
+
type=str,
|
58
|
+
help="Caching dir to be used.",
|
59
|
+
)
|
60
|
+
@click.option(
|
61
|
+
"--builds-dir",
|
62
|
+
required=False,
|
63
|
+
default=None,
|
64
|
+
type=str,
|
65
|
+
help="Path to the builds directory.",
|
66
|
+
)
|
67
|
+
@click.option(
|
68
|
+
"--timeout",
|
69
|
+
required=False,
|
70
|
+
default=60,
|
71
|
+
type=int,
|
72
|
+
help="Timeout in seconds for the VM to be reachable via SSH.",
|
73
|
+
)
|
74
|
+
@click.option(
|
75
|
+
"--volume",
|
76
|
+
"volumes",
|
77
|
+
required=False,
|
78
|
+
default=[],
|
79
|
+
type=str,
|
80
|
+
multiple=True,
|
81
|
+
help="Volume mount definition with docker syntax. <host_dir>:<vm_dir>[:ro]",
|
82
|
+
)
|
45
83
|
@click.option("-x", "--tart-executable", required=False, default="tart", type=str, help="Path to the tart executable.")
|
46
84
|
def prepare(
|
85
|
+
default_ssh_username,
|
86
|
+
default_ssh_password,
|
47
87
|
registry_username,
|
48
88
|
registry_password,
|
49
89
|
registry,
|
@@ -53,6 +93,10 @@ def prepare(
|
|
53
93
|
pull_policy,
|
54
94
|
auto_resources,
|
55
95
|
concurrency,
|
96
|
+
cache_dir,
|
97
|
+
builds_dir,
|
98
|
+
timeout,
|
99
|
+
volumes,
|
56
100
|
tart_executable,
|
57
101
|
):
|
58
102
|
"""Prepare the environment and start the tart VM."""
|
@@ -61,6 +105,11 @@ def prepare(
|
|
61
105
|
|
62
106
|
p = GitLabCustomCommandConfig()
|
63
107
|
|
108
|
+
if not p.tart_ssh_username:
|
109
|
+
p.tart_ssh_username = default_ssh_username
|
110
|
+
if not p.tart_ssh_password:
|
111
|
+
p.tart_ssh_password = default_ssh_password
|
112
|
+
|
64
113
|
tart = Tart(exec_path=tart_executable)
|
65
114
|
tart_images = tart.list()
|
66
115
|
tart_vm_map = {}
|
@@ -78,7 +127,6 @@ def prepare(
|
|
78
127
|
tart.login(username=p.ci_registry_user, password=p.ci_registry_password, host=p.ci_registry)
|
79
128
|
except:
|
80
129
|
click.secho(f"[ERROR] Failed to login to '{p.ci_registry}'", fg="red")
|
81
|
-
sys.exit(1)
|
82
130
|
|
83
131
|
if registry_username and registry_password and registry:
|
84
132
|
click.echo(f"[INFO] Logging into OCI Registry '{registry}'")
|
@@ -86,7 +134,6 @@ def prepare(
|
|
86
134
|
tart.login(username=registry_username, password=registry_password, host=registry)
|
87
135
|
except:
|
88
136
|
click.secho(f"[ERROR] Failed to login to '{registry}'", fg="red")
|
89
|
-
sys.exit(1)
|
90
137
|
|
91
138
|
if p.tart_registry_username and p.tart_registry_password and p.tart_registry:
|
92
139
|
click.echo(f"[INFO] Logging into custom OCI Registry '{p.tart_registry}'")
|
@@ -94,7 +141,6 @@ def prepare(
|
|
94
141
|
tart.login(username=p.tart_registry_username, password=p.tart_registry_password, host=p.tart_registry)
|
95
142
|
except:
|
96
143
|
click.secho(f"[ERROR] Failed to login to '{p.tart_registry}'", fg="red")
|
97
|
-
sys.exit(1)
|
98
144
|
|
99
145
|
######################################################################
|
100
146
|
# PULL
|
@@ -140,8 +186,58 @@ def prepare(
|
|
140
186
|
|
141
187
|
click.echo(f"[INFO] Starting VM instance '{tart_vm_name}'")
|
142
188
|
|
143
|
-
|
144
|
-
|
189
|
+
remote_build_dir = "/opt/builds"
|
190
|
+
remote_script_dir = "/opt/temp"
|
191
|
+
remote_cache_dir = "/opt/cache"
|
192
|
+
|
193
|
+
volume_mounts = []
|
194
|
+
if cache_dir:
|
195
|
+
cache_dir = os.path.abspath(os.path.expanduser(cache_dir))
|
196
|
+
os.makedirs(cache_dir, exist_ok=True)
|
197
|
+
click.echo(f"[INFO] Cache directory set to '{cache_dir}'")
|
198
|
+
volume_mounts.append(TartVolume(source=cache_dir, dest=remote_cache_dir, name="cache", ro=False))
|
199
|
+
if builds_dir:
|
200
|
+
# Concurrency compatible builds directory
|
201
|
+
# see https://docs.gitlab.com/runner/executors/shell.html#run-scripts-as-a-privileged-user
|
202
|
+
# <builds_dir>/<short-token>/<concurrent-id>/<namespace>/<project-name>.
|
203
|
+
builds_dir = os.path.join(
|
204
|
+
os.path.abspath(os.path.expanduser(builds_dir)), p.ci_runner_short_token, p.ci_concurrent_project_id
|
205
|
+
)
|
206
|
+
os.makedirs(builds_dir, exist_ok=True)
|
207
|
+
click.echo(f"[INFO] Builds directory set to '{builds_dir}'")
|
208
|
+
volume_mounts.append(TartVolume(source=builds_dir, dest=remote_build_dir, name="builds", ro=False))
|
209
|
+
|
210
|
+
for v in volumes:
|
211
|
+
volume_mounts.append(TartVolume.from_string(v))
|
212
|
+
|
213
|
+
tart.run(tart_vm_name, volume_mounts)
|
214
|
+
ip = tart.ip(tart_vm_name, timeout=timeout)
|
215
|
+
if not ip:
|
216
|
+
click.echo(f"[ERROR] Error, VM was not reacheable after '{timeout}' seconds")
|
217
|
+
sys.exit(1)
|
218
|
+
|
219
|
+
ssh_session = tart.ssh_session(name=p.vm_name(), username=p.tart_ssh_username, password=p.tart_ssh_password)
|
220
|
+
ssh_session.exec_ssh_command(
|
221
|
+
f"sudo mkdir -p {remote_script_dir} && sudo chown {p.tart_ssh_username}:{p.tart_ssh_username} {remote_script_dir}",
|
222
|
+
)
|
223
|
+
|
224
|
+
for volume in volume_mounts:
|
225
|
+
click.echo("[INFO] Setting up volume mount '{volume.name}'")
|
226
|
+
ssh_session.exec_ssh_command(
|
227
|
+
f"sudo mkdir -p $(dirname {volume.dest}); sudo ln -sf '/Volumes/My Shared Files/{volume.name}' {volume.dest}",
|
228
|
+
)
|
229
|
+
|
230
|
+
# if cache and builds volumes are not mounted, make sure to create them locally inside the VM
|
231
|
+
if not cache_dir:
|
232
|
+
ssh_session.exec_ssh_command(
|
233
|
+
f"sudo mkdir -p {remote_cache_dir} && sudo chown {p.tart_ssh_username}:{p.tart_ssh_username} {remote_cache_dir}",
|
234
|
+
)
|
235
|
+
|
236
|
+
if not builds_dir:
|
237
|
+
ssh_session.exec_ssh_command(
|
238
|
+
f"sudo mkdir -p {remote_build_dir} && sudo chown {p.tart_ssh_username}:{p.tart_ssh_username} {remote_build_dir}",
|
239
|
+
)
|
240
|
+
|
145
241
|
tart.print_spec(tart_vm_name)
|
146
242
|
|
147
243
|
sys.exit(0)
|
@@ -2,8 +2,6 @@ import os
|
|
2
2
|
import sys
|
3
3
|
|
4
4
|
import click
|
5
|
-
from paramiko import MissingHostKeyPolicy
|
6
|
-
from paramiko import SSHClient
|
7
5
|
|
8
6
|
from gitlab_runner_tart_driver.modules.gitlab_custom_command_config import GitLabCustomCommandConfig
|
9
7
|
from gitlab_runner_tart_driver.modules.tart import Tart
|
@@ -14,7 +12,7 @@ from gitlab_runner_tart_driver.modules.tart import Tart
|
|
14
12
|
"--default-ssh-username", default="admin", required=False, type=str, help="username to login to a tart vm"
|
15
13
|
)
|
16
14
|
@click.option(
|
17
|
-
"--default-ssh-password", default="admin", required=False, type=str, help="
|
15
|
+
"--default-ssh-password", default="admin", required=False, type=str, help="password to login to a tart vm"
|
18
16
|
)
|
19
17
|
@click.option(
|
20
18
|
"-x",
|
@@ -50,46 +48,19 @@ def run(default_ssh_username, default_ssh_password, tart_executable, shell, scri
|
|
50
48
|
tart_ip = tart.ip(tart_vm_name, timeout=30)
|
51
49
|
click.echo(f"[INFO] Establishing SSH conntection to '{p.tart_ssh_username}@{tart_ip}'")
|
52
50
|
|
53
|
-
|
54
|
-
ssh_client.set_missing_host_key_policy(MissingHostKeyPolicy())
|
55
|
-
ssh_client.connect(tart_ip, username=p.tart_ssh_username, password=p.tart_ssh_password)
|
51
|
+
ssh_session = tart.ssh_session(name=p.vm_name(), username=p.tart_ssh_username, password=p.tart_ssh_password)
|
56
52
|
|
57
|
-
click.echo("[INFO] Preparing workspace
|
58
|
-
|
59
|
-
remote_script_dir = "/opt/temp"
|
60
|
-
remote_cache_dir = "/opt/cache"
|
61
|
-
exec_ssh_command(
|
62
|
-
ssh_client,
|
63
|
-
f"sudo mkdir -p {remote_build_dir} && sudo chown {p.tart_ssh_username}:{p.tart_ssh_username} {remote_build_dir}",
|
64
|
-
)
|
65
|
-
exec_ssh_command(
|
66
|
-
ssh_client,
|
67
|
-
f"sudo mkdir -p {remote_script_dir} && sudo chown {p.tart_ssh_username}:{p.tart_ssh_username} {remote_script_dir}",
|
68
|
-
)
|
69
|
-
exec_ssh_command(
|
70
|
-
ssh_client,
|
71
|
-
f"sudo mkdir -p {remote_cache_dir} && sudo chown {p.tart_ssh_username}:{p.tart_ssh_username} {remote_cache_dir}",
|
72
|
-
)
|
53
|
+
click.echo("[INFO] Preparing workspace")
|
54
|
+
remote_temp_dir = "/opt/temp"
|
73
55
|
|
74
56
|
script_name = os.path.basename(script)
|
75
|
-
remote_script_path = os.path.join(
|
57
|
+
remote_script_path = os.path.join(remote_temp_dir, stage + "-" + script_name)
|
76
58
|
|
77
|
-
sftp = ssh_client.open_sftp()
|
59
|
+
sftp = ssh_session.ssh_client.open_sftp()
|
78
60
|
sftp.put(script, remote_script_path)
|
79
61
|
sftp.close()
|
80
62
|
|
81
|
-
exec_ssh_command(
|
82
|
-
script_exit_code = exec_ssh_command(
|
63
|
+
# ssh_session.exec_ssh_command(f"cd {remote_build_dir}")
|
64
|
+
script_exit_code = ssh_session.exec_ssh_command(f"{shell} -l {remote_script_path}", get_pty=True)
|
83
65
|
|
84
66
|
sys.exit(script_exit_code)
|
85
|
-
|
86
|
-
|
87
|
-
def exec_ssh_command(ssh_client, command, get_pty=True):
|
88
|
-
"""Executes an ssh command and prints it's output continously to stdout/stderr"""
|
89
|
-
_, stdout, stderr = ssh_client.exec_command(command, get_pty=get_pty)
|
90
|
-
for line in iter(stdout.readline, ""):
|
91
|
-
click.echo(line, nl=False)
|
92
|
-
for line in iter(stderr.readline, ""):
|
93
|
-
click.echo(line, nl=False, err=True)
|
94
|
-
|
95
|
-
return stdout.channel.recv_exit_status()
|
@@ -1,6 +1,10 @@
|
|
1
|
+
import os
|
1
2
|
import re
|
2
3
|
import subprocess
|
3
4
|
|
5
|
+
import click
|
6
|
+
from paramiko import MissingHostKeyPolicy
|
7
|
+
from paramiko import SSHClient
|
4
8
|
from pydantic import BaseModel
|
5
9
|
from pydantic import Field
|
6
10
|
from tabulate import tabulate
|
@@ -22,6 +26,50 @@ class TartVmSpec(BaseModel):
|
|
22
26
|
ip_address: str
|
23
27
|
|
24
28
|
|
29
|
+
class TartVolume(BaseModel):
|
30
|
+
name: str
|
31
|
+
source: str
|
32
|
+
dest: str
|
33
|
+
ro: bool = Field(default=False)
|
34
|
+
|
35
|
+
@classmethod
|
36
|
+
def from_string(cls, value):
|
37
|
+
components = value.split(":")
|
38
|
+
if len(components) < 2:
|
39
|
+
raise ValueError(f"'{value}' is not a valid volume mount definition")
|
40
|
+
|
41
|
+
source = os.path.abspath(os.path.expanduser(components[0])).rstrip("/")
|
42
|
+
dest = components[1].rstrip("/")
|
43
|
+
name = dest.strip("/").replace("/", "__")
|
44
|
+
ro = False
|
45
|
+
if len(components) > 2:
|
46
|
+
if "ro" == components[2]:
|
47
|
+
ro = True
|
48
|
+
else:
|
49
|
+
raise ValueError(f"'{components[2]}' flag unknown")
|
50
|
+
|
51
|
+
return cls(name=name, source=source, dest=dest, ro=ro)
|
52
|
+
|
53
|
+
|
54
|
+
class TartSshSession:
|
55
|
+
def __init__(self, username, password, ip):
|
56
|
+
self.user = username
|
57
|
+
self.ip = ip
|
58
|
+
self.password = password
|
59
|
+
self.ssh_client = SSHClient()
|
60
|
+
self.ssh_client.set_missing_host_key_policy(MissingHostKeyPolicy())
|
61
|
+
self.ssh_client.connect(ip, username=username, password=password)
|
62
|
+
|
63
|
+
def exec_ssh_command(self, command, get_pty=True):
|
64
|
+
"""Executes an ssh command and prints it's output continously to stdout/stderr"""
|
65
|
+
_, stdout, stderr = self.ssh_client.exec_command(command, get_pty=get_pty)
|
66
|
+
for line in iter(stdout.readline, ""):
|
67
|
+
click.echo(line, nl=False)
|
68
|
+
for line in iter(stderr.readline, ""):
|
69
|
+
click.echo(line, nl=False, err=True)
|
70
|
+
return stdout.channel.recv_exit_status()
|
71
|
+
|
72
|
+
|
25
73
|
class Tart(object):
|
26
74
|
def __init__(self, exec_path="tart"):
|
27
75
|
self.tart_executable = exec_path
|
@@ -102,12 +150,18 @@ class Tart(object):
|
|
102
150
|
"""stops a given tart VM"""
|
103
151
|
self.exec(["stop", name])
|
104
152
|
|
105
|
-
def run(self, name, no_graphics=True) -> None:
|
153
|
+
def run(self, name: str, volumes: list[TartVolume] = [], no_graphics=True) -> None:
|
106
154
|
"""starts a given tart VM"""
|
107
155
|
args = ["run", name]
|
108
156
|
if no_graphics:
|
109
157
|
args.append("--no-graphics")
|
110
158
|
|
159
|
+
if volumes:
|
160
|
+
for d in volumes:
|
161
|
+
source_path = os.path.abspath(os.path.expanduser(d.source))
|
162
|
+
if d.ro:
|
163
|
+
source_path = f"{source_path}:ro"
|
164
|
+
args.extend(["--dir", f"{d.name}:{source_path}"])
|
111
165
|
try:
|
112
166
|
self.spawn_exec(args)
|
113
167
|
except Exception as e:
|
@@ -157,3 +211,10 @@ class Tart(object):
|
|
157
211
|
if cmd:
|
158
212
|
exec_cmd.extend(cmd)
|
159
213
|
subprocess.Popen(exec_cmd, stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL)
|
214
|
+
|
215
|
+
def ssh_session(self, name, username, password) -> TartSshSession:
|
216
|
+
ip = self.ip(name=name)
|
217
|
+
if not ip:
|
218
|
+
raise ValueError("Could not retrievew IP")
|
219
|
+
|
220
|
+
return TartSshSession(ip=ip, username=username, password=password)
|
@@ -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.3
|
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
|
@@ -114,15 +114,18 @@ The `config.toml` should be located at `~/.gitlab-runner/config.toml`. Open it a
|
|
114
114
|
[runners.custom]
|
115
115
|
config_exec = "/opt/homebrew/bin/gitlab-runner-tart-driver"
|
116
116
|
config_args = [ "config", '-x', '/opt/homebrew/bin/tart' ]
|
117
|
+
config_exec_timeout = 200
|
117
118
|
|
118
119
|
prepare_exec = "/opt/homebrew/bin/gitlab-runner-tart-driver"
|
119
120
|
prepare_args = [ "prepare", '-x', '/opt/homebrew/bin/tart' ]
|
121
|
+
prepare_exec_timeout = 200
|
120
122
|
|
121
123
|
run_exec = "/opt/homebrew/bin/gitlab-runner-tart-driver"
|
122
124
|
run_args = [ "run", '-x', '/opt/homebrew/bin/tart' ]
|
123
125
|
|
124
126
|
cleanup_exec = "/opt/homebrew/bin/gitlab-runner-tart-driver"
|
125
127
|
cleanup_args = [ "cleanup", '-x', '/opt/homebrew/bin/tart' ]
|
128
|
+
cleanup_exec_timeout = 200
|
126
129
|
```
|
127
130
|
|
128
131
|
Now restart the gitlab-runner with `gitlab-runner restart`
|
@@ -266,6 +269,32 @@ shutdown_timeout = 0
|
|
266
269
|
cleanup_args = [ "cleanup", '-x', '/opt/homebrew/bin/tart' ]
|
267
270
|
```
|
268
271
|
|
272
|
+
### Host Cache and Builds directories
|
273
|
+
|
274
|
+
With `tart` it is possible to mount local directories into the VM. Mounting local directories brings a number of benefits like up tp 30% higher IO performance as well as a correct caching mechanism.
|
275
|
+
To enable Host-local caching and builds, simply pass `--builds-dir` and `--cache-dir` to the `prepare` command
|
276
|
+
|
277
|
+
```ini
|
278
|
+
prepare_exec = "/opt/homebrew/bin/gitlab-runner-tart-driver"
|
279
|
+
prepare_args = [ "prepare", '-x', '/opt/homebrew/bin/tart', '--concurrency', '2', '--auto-resources', '--cache-dir', '/Users/gitlab/gitlab-runner/cache', '--builds-dir', '/Users/gitlab/gitlab-runner/builds']
|
280
|
+
```
|
281
|
+
|
282
|
+
### Volume Mounts
|
283
|
+
|
284
|
+
Just like with `docker` the `gitlab-runner-tart-driver` allows you to mount any arbitrary host path into your VM. This can be especially useful if you have to mount runner-local resources like shared test-data or additional caches into the executor. You can follow the standard docker syntax for *volume mounts* `--volume /my/local/dir:/opt/remote/dir`. Additionally you can also pass the `ro` flag to make the mount *read-only* i.e. `--volume /my/local/dir:/opt/remote/dir:ro`.
|
285
|
+
|
286
|
+
```ini
|
287
|
+
[runners.custom]
|
288
|
+
config_exec = "/opt/homebrew/bin/gitlab-runner-tart-driver"
|
289
|
+
config_args = [ "config" ]
|
290
|
+
|
291
|
+
prepare_exec = "/opt/homebrew/bin/gitlab-runner-tart-driver"
|
292
|
+
prepare_args = [ "prepare",
|
293
|
+
'-x', '/opt/homebrew/bin/tart',
|
294
|
+
'--concurrency', '2',
|
295
|
+
'--auto-resources',
|
296
|
+
'--volume /data/models/:/opt/data/models:ro']
|
297
|
+
```
|
269
298
|
### Auto Host Resource Distribution
|
270
299
|
|
271
300
|
`tart` images come with a pre-defined number of CPUs and Memory allocation. Typical numbers for default images are `cpu_count=4` and `memory=8192`. With the concurrency limitation of two VMs/images running at the same time this might not utilize your host system completely.
|
@@ -324,11 +353,13 @@ Usage: gitlab-runner-tart-driver prepare [OPTIONS]
|
|
324
353
|
Prepare the environment and start the tart VM.
|
325
354
|
|
326
355
|
Options:
|
356
|
+
--default-ssh-username TEXT username to login to a tart vm
|
357
|
+
--default-ssh-password TEXT password to login to a tart vm
|
327
358
|
--pull-policy [always|if-not-present|never]
|
328
359
|
define how runners pull tart images from
|
329
360
|
registries
|
330
361
|
--registry-username TEXT username to login to a oci registry
|
331
|
-
--registry-password TEXT
|
362
|
+
--registry-password TEXT password to login to a oci registry
|
332
363
|
--registry TEXT username to login to a oci registry
|
333
364
|
--cpu INTEGER Number of CPUs associated to VM
|
334
365
|
--memory INTEGER VM memory size in megabytes associated to VM
|
@@ -340,8 +371,14 @@ Options:
|
|
340
371
|
--concurrency INTEGER Number of concurrent processes that are
|
341
372
|
supported. ATTENTION tart currently only
|
342
373
|
support two concurrent VMs
|
374
|
+
--cache-dir TEXT Caching dir to be used.
|
375
|
+
--builds-dir TEXT Path to the builds directory.
|
376
|
+
--timeout INTEGER Timeout in seconds for the VM to be
|
377
|
+
reachable via SSH.
|
378
|
+
--volume TEXT Volume mount definition with docker syntax.
|
379
|
+
<host_dir>:<vm_dir>[:ro]
|
343
380
|
-x, --tart-executable TEXT Path to the tart executable.
|
344
|
-
--help Show this message and exit.
|
381
|
+
--help Show this message and exit. Show this message and exit.
|
345
382
|
```
|
346
383
|
|
347
384
|
### Command `run`
|
@@ -353,7 +390,7 @@ Usage: gitlab-runner-tart-driver run [OPTIONS] SCRIPT STAGE
|
|
353
390
|
|
354
391
|
Options:
|
355
392
|
--default-ssh-username TEXT username to login to a tart vm
|
356
|
-
--default-ssh-password TEXT
|
393
|
+
--default-ssh-password TEXT password to login to a tart vm
|
357
394
|
-x, --tart-executable TEXT Path to the tart executable.
|
358
395
|
--shell TEXT Path to the shell to be used for commands over
|
359
396
|
ssh.
|
@@ -10,7 +10,7 @@ this_directory = os.path.abspath(os.path.dirname(__file__))
|
|
10
10
|
with open(os.path.join(this_directory, "README.md"), encoding="utf-8") as f:
|
11
11
|
long_description = f.read()
|
12
12
|
|
13
|
-
version = "0.1.
|
13
|
+
version = "0.1.3"
|
14
14
|
|
15
15
|
version = f"{version}{os.environ.get('PIP_VERSION_POSTFIX','')}"
|
16
16
|
|
@@ -1 +0,0 @@
|
|
1
|
-
__version__ = "0.1.1"
|
File without changes
|
File without changes
|
{gitlab-runner-tart-driver-0.1.1 → gitlab-runner-tart-driver-0.1.3}/gitlab_runner_tart_driver/cli.py
RENAMED
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|