gitlab-runner-tart-driver 0.1.7__tar.gz → 0.2.0__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.7/gitlab_runner_tart_driver.egg-info → gitlab-runner-tart-driver-0.2.0}/PKG-INFO +21 -14
- {gitlab-runner-tart-driver-0.1.7 → gitlab-runner-tart-driver-0.2.0}/README.md +20 -13
- gitlab-runner-tart-driver-0.2.0/gitlab_runner_tart_driver/__init__.py +1 -0
- {gitlab-runner-tart-driver-0.1.7 → gitlab-runner-tart-driver-0.2.0}/gitlab_runner_tart_driver/commands/prepare.py +26 -48
- {gitlab-runner-tart-driver-0.1.7 → gitlab-runner-tart-driver-0.2.0}/gitlab_runner_tart_driver/commands/run.py +9 -19
- gitlab-runner-tart-driver-0.2.0/gitlab_runner_tart_driver/modules/gitlab_custom_command_config.py +102 -0
- {gitlab-runner-tart-driver-0.1.7 → gitlab-runner-tart-driver-0.2.0}/gitlab_runner_tart_driver/modules/tart.py +7 -1
- {gitlab-runner-tart-driver-0.1.7 → gitlab-runner-tart-driver-0.2.0/gitlab_runner_tart_driver.egg-info}/PKG-INFO +21 -14
- {gitlab-runner-tart-driver-0.1.7 → gitlab-runner-tart-driver-0.2.0}/setup.py +1 -1
- gitlab-runner-tart-driver-0.1.7/gitlab_runner_tart_driver/__init__.py +0 -1
- gitlab-runner-tart-driver-0.1.7/gitlab_runner_tart_driver/modules/gitlab_custom_command_config.py +0 -43
- {gitlab-runner-tart-driver-0.1.7 → gitlab-runner-tart-driver-0.2.0}/LICENSE.txt +0 -0
- {gitlab-runner-tart-driver-0.1.7 → gitlab-runner-tart-driver-0.2.0}/MANIFEST.in +0 -0
- {gitlab-runner-tart-driver-0.1.7 → gitlab-runner-tart-driver-0.2.0}/gitlab_runner_tart_driver/__main__.py +0 -0
- {gitlab-runner-tart-driver-0.1.7 → gitlab-runner-tart-driver-0.2.0}/gitlab_runner_tart_driver/cli.py +0 -0
- {gitlab-runner-tart-driver-0.1.7 → gitlab-runner-tart-driver-0.2.0}/gitlab_runner_tart_driver/commands/__init__.py +0 -0
- {gitlab-runner-tart-driver-0.1.7 → gitlab-runner-tart-driver-0.2.0}/gitlab_runner_tart_driver/commands/cleanup.py +0 -0
- {gitlab-runner-tart-driver-0.1.7 → gitlab-runner-tart-driver-0.2.0}/gitlab_runner_tart_driver/commands/config.py +0 -0
- {gitlab-runner-tart-driver-0.1.7 → gitlab-runner-tart-driver-0.2.0}/gitlab_runner_tart_driver/modules/__init__.py +0 -0
- {gitlab-runner-tart-driver-0.1.7 → gitlab-runner-tart-driver-0.2.0}/gitlab_runner_tart_driver/modules/gitlab_custom_driver_config.py +0 -0
- {gitlab-runner-tart-driver-0.1.7 → gitlab-runner-tart-driver-0.2.0}/gitlab_runner_tart_driver/modules/utils.py +0 -0
- {gitlab-runner-tart-driver-0.1.7 → gitlab-runner-tart-driver-0.2.0}/gitlab_runner_tart_driver/scripts/install-gitlab-runner.sh.j2 +0 -0
- {gitlab-runner-tart-driver-0.1.7 → gitlab-runner-tart-driver-0.2.0}/gitlab_runner_tart_driver.egg-info/SOURCES.txt +0 -0
- {gitlab-runner-tart-driver-0.1.7 → gitlab-runner-tart-driver-0.2.0}/gitlab_runner_tart_driver.egg-info/dependency_links.txt +0 -0
- {gitlab-runner-tart-driver-0.1.7 → gitlab-runner-tart-driver-0.2.0}/gitlab_runner_tart_driver.egg-info/entry_points.txt +0 -0
- {gitlab-runner-tart-driver-0.1.7 → gitlab-runner-tart-driver-0.2.0}/gitlab_runner_tart_driver.egg-info/not-zip-safe +0 -0
- {gitlab-runner-tart-driver-0.1.7 → gitlab-runner-tart-driver-0.2.0}/gitlab_runner_tart_driver.egg-info/requires.txt +0 -0
- {gitlab-runner-tart-driver-0.1.7 → gitlab-runner-tart-driver-0.2.0}/gitlab_runner_tart_driver.egg-info/top_level.txt +0 -0
- {gitlab-runner-tart-driver-0.1.7 → gitlab-runner-tart-driver-0.2.0}/pyproject.toml +0 -0
- {gitlab-runner-tart-driver-0.1.7 → gitlab-runner-tart-driver-0.2.0}/setup.cfg +0 -0
@@ -1,6 +1,6 @@
|
|
1
1
|
Metadata-Version: 2.1
|
2
2
|
Name: gitlab-runner-tart-driver
|
3
|
-
Version: 0.
|
3
|
+
Version: 0.2.0
|
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
|
@@ -20,6 +20,7 @@ License-File: LICENSE.txt
|
|
20
20
|
- [Setup](#setup)
|
21
21
|
- [GitLab Runner Configuration](#gitlab-runner-configuration)
|
22
22
|
- [GitLab CI](#gitlab-ci)
|
23
|
+
- [Supported Environment Variables](#supported-environment-variables)
|
23
24
|
- [Private OCI Registries](#private-oci-registries)
|
24
25
|
- [Configuring the SSH Credentials](#configuring-the-ssh-credentials)
|
25
26
|
- [Advanced Configuration](#advanced-configuration)
|
@@ -177,6 +178,24 @@ run-on-tart:
|
|
177
178
|
- artifact.txt
|
178
179
|
```
|
179
180
|
|
181
|
+
### Supported Environment Variables
|
182
|
+
|
183
|
+
| **Name** | **Default** | **Description** |
|
184
|
+
| ------------------------------------- | -------------- | ------------------------------------------------------------------------------------------------------------- |
|
185
|
+
| `TART_REGISTRY_USERNAME` | | Username to login to private OCI registry |
|
186
|
+
| `TART_REGISTRY_PASSWORD` | | Password to login to private OCI registry |
|
187
|
+
| `TART_REGISTRY` | | Private OCI registry |
|
188
|
+
| `TART_PULL_POLICY` | if-not-present | define how runners pull tart images from registries. Options are `always`,`if-not-present`,`never` |
|
189
|
+
| `TART_SSH_USERNAME` | admin | Username to use to login to VM |
|
190
|
+
| `TART_SSH_PASSWORD` | admin | Password to use to login to VM |
|
191
|
+
| `TART_EXECUTOR_HEADLESS` | true | Don't open a UI window. |
|
192
|
+
| `TART_EXECUTOR_SOFTNET_ENABLED` | false | Use software networking instead of the default shared (NAT) networking |
|
193
|
+
| `TART_EXECUTOR_VNC_ENABLED` | false | Use screen sharing instead of the built-in UI. Note that Remote Login option should be enabled inside the VM. |
|
194
|
+
| `TART_EXECUTOR_INSTALL_GITLAB_RUNNER` | false | Install a GitLabRunner into the VM to ensure full CI/CD functionality |
|
195
|
+
| `TART_EXECUTOR_SHELL` | /bin/zsh | The shell that should be used when running commands |
|
196
|
+
| `TART_EXECUTOR_TIMEOUT` | 60 | Timeout for `tart ip` to respond with a valid IP |
|
197
|
+
| `TART_EXECUTOR_DISPLAY` | 1920x1200 | Display resolution in format `WxH` |
|
198
|
+
|
180
199
|
### Private OCI Registries
|
181
200
|
|
182
201
|
Oftentimes you might want to provide your own OCI-compliant images created with [Packer](https://www.packer.io) and the official [Tart Builder](https://developer.hashicorp.com/packer/plugins/builders/tart). If you push your images to a private registry you will need to provide the credentials for the `gitlab-runner-tart-driver` to login there first.
|
@@ -346,9 +365,7 @@ see **Command `run`**
|
|
346
365
|
|
347
366
|
### Custom `pull_policy`
|
348
367
|
|
349
|
-
You can use a custom `pull_policy`. The default policy is `if-not-present`
|
350
|
-
|
351
|
-
see **Command `prepare`**
|
368
|
+
You can use a custom `pull_policy`. The default policy is `if-not-present`. Use `TART_PULL_POLICY` to override the default pull policy
|
352
369
|
|
353
370
|
## CLI
|
354
371
|
|
@@ -391,14 +408,6 @@ Usage: gitlab-runner-tart-driver prepare [OPTIONS]
|
|
391
408
|
Prepare the environment and start the tart VM.
|
392
409
|
|
393
410
|
Options:
|
394
|
-
--default-ssh-username TEXT username to login to a tart vm
|
395
|
-
--default-ssh-password TEXT password to login to a tart vm
|
396
|
-
--pull-policy [always|if-not-present|never]
|
397
|
-
define how runners pull tart images from
|
398
|
-
registries
|
399
|
-
--registry-username TEXT username to login to a oci registry
|
400
|
-
--registry-password TEXT password to login to a oci registry
|
401
|
-
--registry TEXT username to login to a oci registry
|
402
411
|
--cpu INTEGER Number of CPUs associated to VM
|
403
412
|
--memory INTEGER VM memory size in megabytes associated to VM
|
404
413
|
--display TEXT VM display resolution in a format of
|
@@ -434,8 +443,6 @@ Usage: gitlab-runner-tart-driver run [OPTIONS] SCRIPT STAGE
|
|
434
443
|
Run commands.
|
435
444
|
|
436
445
|
Options:
|
437
|
-
--default-ssh-username TEXT username to login to a tart vm
|
438
|
-
--default-ssh-password TEXT password to login to a tart vm
|
439
446
|
--timeout INTEGER SSH connection timeout in seconds
|
440
447
|
-x, --tart-executable TEXT Path to the tart executable.
|
441
448
|
--shell TEXT Path to the shell to be used for commands over
|
@@ -5,6 +5,7 @@
|
|
5
5
|
- [Setup](#setup)
|
6
6
|
- [GitLab Runner Configuration](#gitlab-runner-configuration)
|
7
7
|
- [GitLab CI](#gitlab-ci)
|
8
|
+
- [Supported Environment Variables](#supported-environment-variables)
|
8
9
|
- [Private OCI Registries](#private-oci-registries)
|
9
10
|
- [Configuring the SSH Credentials](#configuring-the-ssh-credentials)
|
10
11
|
- [Advanced Configuration](#advanced-configuration)
|
@@ -162,6 +163,24 @@ run-on-tart:
|
|
162
163
|
- artifact.txt
|
163
164
|
```
|
164
165
|
|
166
|
+
### Supported Environment Variables
|
167
|
+
|
168
|
+
| **Name** | **Default** | **Description** |
|
169
|
+
| ------------------------------------- | -------------- | ------------------------------------------------------------------------------------------------------------- |
|
170
|
+
| `TART_REGISTRY_USERNAME` | | Username to login to private OCI registry |
|
171
|
+
| `TART_REGISTRY_PASSWORD` | | Password to login to private OCI registry |
|
172
|
+
| `TART_REGISTRY` | | Private OCI registry |
|
173
|
+
| `TART_PULL_POLICY` | if-not-present | define how runners pull tart images from registries. Options are `always`,`if-not-present`,`never` |
|
174
|
+
| `TART_SSH_USERNAME` | admin | Username to use to login to VM |
|
175
|
+
| `TART_SSH_PASSWORD` | admin | Password to use to login to VM |
|
176
|
+
| `TART_EXECUTOR_HEADLESS` | true | Don't open a UI window. |
|
177
|
+
| `TART_EXECUTOR_SOFTNET_ENABLED` | false | Use software networking instead of the default shared (NAT) networking |
|
178
|
+
| `TART_EXECUTOR_VNC_ENABLED` | false | Use screen sharing instead of the built-in UI. Note that Remote Login option should be enabled inside the VM. |
|
179
|
+
| `TART_EXECUTOR_INSTALL_GITLAB_RUNNER` | false | Install a GitLabRunner into the VM to ensure full CI/CD functionality |
|
180
|
+
| `TART_EXECUTOR_SHELL` | /bin/zsh | The shell that should be used when running commands |
|
181
|
+
| `TART_EXECUTOR_TIMEOUT` | 60 | Timeout for `tart ip` to respond with a valid IP |
|
182
|
+
| `TART_EXECUTOR_DISPLAY` | 1920x1200 | Display resolution in format `WxH` |
|
183
|
+
|
165
184
|
### Private OCI Registries
|
166
185
|
|
167
186
|
Oftentimes you might want to provide your own OCI-compliant images created with [Packer](https://www.packer.io) and the official [Tart Builder](https://developer.hashicorp.com/packer/plugins/builders/tart). If you push your images to a private registry you will need to provide the credentials for the `gitlab-runner-tart-driver` to login there first.
|
@@ -331,9 +350,7 @@ see **Command `run`**
|
|
331
350
|
|
332
351
|
### Custom `pull_policy`
|
333
352
|
|
334
|
-
You can use a custom `pull_policy`. The default policy is `if-not-present`
|
335
|
-
|
336
|
-
see **Command `prepare`**
|
353
|
+
You can use a custom `pull_policy`. The default policy is `if-not-present`. Use `TART_PULL_POLICY` to override the default pull policy
|
337
354
|
|
338
355
|
## CLI
|
339
356
|
|
@@ -376,14 +393,6 @@ Usage: gitlab-runner-tart-driver prepare [OPTIONS]
|
|
376
393
|
Prepare the environment and start the tart VM.
|
377
394
|
|
378
395
|
Options:
|
379
|
-
--default-ssh-username TEXT username to login to a tart vm
|
380
|
-
--default-ssh-password TEXT password to login to a tart vm
|
381
|
-
--pull-policy [always|if-not-present|never]
|
382
|
-
define how runners pull tart images from
|
383
|
-
registries
|
384
|
-
--registry-username TEXT username to login to a oci registry
|
385
|
-
--registry-password TEXT password to login to a oci registry
|
386
|
-
--registry TEXT username to login to a oci registry
|
387
396
|
--cpu INTEGER Number of CPUs associated to VM
|
388
397
|
--memory INTEGER VM memory size in megabytes associated to VM
|
389
398
|
--display TEXT VM display resolution in a format of
|
@@ -419,8 +428,6 @@ Usage: gitlab-runner-tart-driver run [OPTIONS] SCRIPT STAGE
|
|
419
428
|
Run commands.
|
420
429
|
|
421
430
|
Options:
|
422
|
-
--default-ssh-username TEXT username to login to a tart vm
|
423
|
-
--default-ssh-password TEXT password to login to a tart vm
|
424
431
|
--timeout INTEGER SSH connection timeout in seconds
|
425
432
|
-x, --tart-executable TEXT Path to the tart executable.
|
426
433
|
--shell TEXT Path to the shell to be used for commands over
|
@@ -0,0 +1 @@
|
|
1
|
+
__version__ = "0.2.0"
|
@@ -11,21 +11,6 @@ from gitlab_runner_tart_driver.modules.utils import print_host_spec
|
|
11
11
|
|
12
12
|
|
13
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
|
-
)
|
20
|
-
@click.option(
|
21
|
-
"--pull-policy",
|
22
|
-
default="if-not-present",
|
23
|
-
type=click.Choice(["always", "if-not-present", "never"]),
|
24
|
-
help="define how runners pull tart images from registries",
|
25
|
-
)
|
26
|
-
@click.option("--registry-username", required=False, default=None, type=str, help="username to login to a oci registry")
|
27
|
-
@click.option("--registry-password", required=False, default=None, type=str, help="password to login to a oci registry")
|
28
|
-
@click.option("--registry", required=False, default=None, type=str, help="username to login to a oci registry")
|
29
14
|
@click.option("--cpu", required=False, default=None, type=int, help="Number of CPUs associated to VM")
|
30
15
|
@click.option("--memory", required=False, default=None, type=int, help="VM memory size in megabytes associated to VM")
|
31
16
|
@click.option(
|
@@ -103,15 +88,9 @@ from gitlab_runner_tart_driver.modules.utils import print_host_spec
|
|
103
88
|
)
|
104
89
|
@click.option("-x", "--tart-executable", required=False, default="tart", type=str, help="Path to the tart executable.")
|
105
90
|
def prepare(
|
106
|
-
default_ssh_username,
|
107
|
-
default_ssh_password,
|
108
|
-
registry_username,
|
109
|
-
registry_password,
|
110
|
-
registry,
|
111
91
|
cpu,
|
112
92
|
memory,
|
113
93
|
display,
|
114
|
-
pull_policy,
|
115
94
|
auto_resources,
|
116
95
|
concurrency,
|
117
96
|
cache_dir,
|
@@ -129,10 +108,12 @@ def prepare(
|
|
129
108
|
|
130
109
|
p = GitLabCustomCommandConfig()
|
131
110
|
|
132
|
-
if not p.
|
133
|
-
p.
|
134
|
-
if not p.
|
135
|
-
p.
|
111
|
+
if not p.tart_executor_display:
|
112
|
+
p.tart_executor_display = display
|
113
|
+
if not p.tart_executor_install_gitlab_runner:
|
114
|
+
p.tart_executor_install_gitlab_runner = install_gitlab_runner
|
115
|
+
if not p.tart_executor_timeout:
|
116
|
+
p.tart_executor_timeout = timeout
|
136
117
|
|
137
118
|
tart = Tart(exec_path=tart_executable)
|
138
119
|
tart_images = tart.list()
|
@@ -140,9 +121,6 @@ def prepare(
|
|
140
121
|
for i in tart_images:
|
141
122
|
tart_vm_map[i.name] = i
|
142
123
|
|
143
|
-
# for k,v in os.environ.items():
|
144
|
-
# click.echo(f'{k}={v}')
|
145
|
-
|
146
124
|
######################################################################
|
147
125
|
# OCI LOGIN
|
148
126
|
######################################################################
|
@@ -152,12 +130,12 @@ def prepare(
|
|
152
130
|
except:
|
153
131
|
click.secho(f"[ERROR] Failed to login to '{p.ci_registry}'", fg="red")
|
154
132
|
|
155
|
-
if registry_username and registry_password and registry:
|
156
|
-
click.echo(f"[INFO] Logging into OCI Registry '{registry}'")
|
133
|
+
if p.registry_username and p.registry_password and p.registry:
|
134
|
+
click.echo(f"[INFO] Logging into OCI Registry '{p.registry}'")
|
157
135
|
try:
|
158
|
-
tart.login(username=registry_username, password=registry_password, host=registry)
|
136
|
+
tart.login(username=p.registry_username, password=p.registry_password, host=p.registry)
|
159
137
|
except:
|
160
|
-
click.secho(f"[ERROR] Failed to login to '{registry}'", fg="red")
|
138
|
+
click.secho(f"[ERROR] Failed to login to '{p.registry}'", fg="red")
|
161
139
|
|
162
140
|
if p.tart_registry_username and p.tart_registry_password and p.tart_registry:
|
163
141
|
click.echo(f"[INFO] Logging into custom OCI Registry '{p.tart_registry}'")
|
@@ -170,18 +148,18 @@ def prepare(
|
|
170
148
|
# PULL
|
171
149
|
######################################################################
|
172
150
|
if (
|
173
|
-
(pull_policy == "always")
|
174
|
-
or (p.ci_job_image not in tart_vm_map and pull_policy != "never")
|
175
|
-
or (p.ci_job_image not in tart_vm_map and pull_policy == "if-not-present")
|
151
|
+
(p.pull_policy == "always")
|
152
|
+
or (p.ci_job_image not in tart_vm_map and p.pull_policy != "never")
|
153
|
+
or (p.ci_job_image not in tart_vm_map and p.pull_policy == "if-not-present")
|
176
154
|
):
|
177
|
-
click.echo(f"[INFO] Pulling '{p.ci_job_image}' [pull_policy={pull_policy}]")
|
155
|
+
click.echo(f"[INFO] Pulling '{p.ci_job_image}' [pull_policy={p.pull_policy}]")
|
178
156
|
try:
|
179
157
|
tart.pull(p.ci_job_image)
|
180
158
|
except:
|
181
159
|
click.secho(f"[ERROR] Failed to pull image '{p.ci_job_image}'", fg="red")
|
182
160
|
sys.exit(1)
|
183
161
|
else:
|
184
|
-
click.echo(f"[INFO] Skipping '{p.ci_job_image}' [pull_policy={pull_policy}]")
|
162
|
+
click.echo(f"[INFO] Skipping '{p.ci_job_image}' [pull_policy={p.pull_policy}]")
|
185
163
|
|
186
164
|
######################################################################
|
187
165
|
# Create VM
|
@@ -211,10 +189,10 @@ def prepare(
|
|
211
189
|
click.secho(f"[ERROR] failed to clone image f'{p.ci_job_image}'", fg="red")
|
212
190
|
sys.exit(1)
|
213
191
|
|
214
|
-
if cpu or memory or display:
|
192
|
+
if cpu or memory or p.display:
|
215
193
|
click.echo(f"[INFO] Configuring instance '{tart_vm_name}' from '{p.ci_job_image}'")
|
216
194
|
click.echo(
|
217
|
-
f"[INFO] {tart_vm_name} [cpu={cpu if cpu else 'default'}, memory={memory if memory else 'default'}, display={display if display else 'default'}]"
|
195
|
+
f"[INFO] {tart_vm_name} [cpu={cpu if cpu else 'default'}, memory={memory if memory else 'default'}, display={p.display if p.display else 'default'}]"
|
218
196
|
)
|
219
197
|
tart.set(tart_vm_name, cpu=cpu, memory=memory, display=display)
|
220
198
|
elif auto_resources:
|
@@ -249,25 +227,25 @@ def prepare(
|
|
249
227
|
volume_mounts.append(TartVolume.from_string(v))
|
250
228
|
|
251
229
|
try:
|
252
|
-
tart.run(tart_vm_name, volume_mounts)
|
230
|
+
tart.run(tart_vm_name, volume_mounts, no_graphics=p.headless, softnet=p.softnet_enabled)
|
253
231
|
except:
|
254
232
|
click.secho(f"[ERROR] Failed to start VM '{tart_vm_name}'", fg="red")
|
255
233
|
sys.exit(1)
|
256
234
|
|
257
235
|
try:
|
258
|
-
ip = tart.ip(tart_vm_name, timeout=timeout)
|
236
|
+
ip = tart.ip(tart_vm_name, timeout=p.timeout)
|
259
237
|
except:
|
260
238
|
click.secho(f"[ERROR] Failed to get IP of VM '{tart_vm_name}'", fg="red")
|
261
239
|
sys.exit(1)
|
262
240
|
|
263
241
|
if not ip:
|
264
|
-
click.echo(f"[ERROR] Error, VM was not reacheable after '{timeout}' seconds")
|
242
|
+
click.echo(f"[ERROR] Error, VM was not reacheable after '{p.timeout}' seconds")
|
265
243
|
sys.exit(1)
|
266
244
|
|
267
245
|
try:
|
268
|
-
ssh_session = tart.ssh_session(name=p.vm_name(), username=p.
|
246
|
+
ssh_session = tart.ssh_session(name=p.vm_name(), username=p.ssh_username, password=p.ssh_password)
|
269
247
|
ssh_session.exec_ssh_command(
|
270
|
-
f"sudo mkdir -p {remote_script_dir} && sudo chown {p.
|
248
|
+
f"sudo mkdir -p {remote_script_dir} && sudo chown {p.ssh_username}:{p.ssh_username} {remote_script_dir}",
|
271
249
|
)
|
272
250
|
|
273
251
|
for volume in volume_mounts:
|
@@ -279,23 +257,23 @@ def prepare(
|
|
279
257
|
# if cache and builds volumes are not mounted, make sure to create them locally inside the VM
|
280
258
|
if not cache_dir:
|
281
259
|
ssh_session.exec_ssh_command(
|
282
|
-
f"sudo mkdir -p {remote_cache_dir} && sudo chown {p.
|
260
|
+
f"sudo mkdir -p {remote_cache_dir} && sudo chown {p.ssh_username}:{p.ssh_username} {remote_cache_dir}",
|
283
261
|
)
|
284
262
|
|
285
263
|
if not builds_dir:
|
286
264
|
ssh_session.exec_ssh_command(
|
287
|
-
f"sudo mkdir -p {remote_build_dir} && sudo chown {p.
|
265
|
+
f"sudo mkdir -p {remote_build_dir} && sudo chown {p.ssh_username}:{p.ssh_username} {remote_build_dir}",
|
288
266
|
)
|
289
267
|
except:
|
290
268
|
click.secho(f"[ERROR] Failed so prepare VM '{tart_vm_name}'", fg="red")
|
291
269
|
sys.exit(1)
|
292
270
|
|
293
|
-
if install_gitlab_runner:
|
271
|
+
if p.install_gitlab_runner:
|
294
272
|
click.echo(
|
295
273
|
f"[INFO] Installing GitLab Runner '{gitlab_runner_version}' [force: '{force_install_gitlab_runner}']"
|
296
274
|
)
|
297
275
|
try:
|
298
|
-
tart.install_gitlab_runner(name=tart_vm_name, username=p.
|
276
|
+
tart.install_gitlab_runner(name=tart_vm_name, username=p.ssh_username, password=p.ssh_password)
|
299
277
|
except:
|
300
278
|
click.secho(f"[ERROR] Failed to install GitLab Runner '{gitlab_runner_version}'", fg="red")
|
301
279
|
sys.exit(1)
|
@@ -8,12 +8,6 @@ from gitlab_runner_tart_driver.modules.tart import Tart
|
|
8
8
|
|
9
9
|
|
10
10
|
@click.command()
|
11
|
-
@click.option(
|
12
|
-
"--default-ssh-username", default="admin", required=False, type=str, help="username to login to a tart vm"
|
13
|
-
)
|
14
|
-
@click.option(
|
15
|
-
"--default-ssh-password", default="admin", required=False, type=str, help="password to login to a tart vm"
|
16
|
-
)
|
17
11
|
@click.option(
|
18
12
|
"--timeout", "ssh_timeout", default=60, required=False, type=int, help="SSH connection timeout in seconds"
|
19
13
|
)
|
@@ -34,15 +28,12 @@ from gitlab_runner_tart_driver.modules.tart import Tart
|
|
34
28
|
)
|
35
29
|
@click.argument("script")
|
36
30
|
@click.argument("stage")
|
37
|
-
def run(
|
31
|
+
def run(ssh_timeout, tart_executable, shell, script, stage):
|
38
32
|
"""Run commands."""
|
39
33
|
p = GitLabCustomCommandConfig()
|
40
34
|
|
41
|
-
if not p.
|
42
|
-
p.
|
43
|
-
if not p.tart_ssh_password:
|
44
|
-
p.tart_ssh_password = default_ssh_password
|
45
|
-
|
35
|
+
if not p.tart_executor_shell:
|
36
|
+
p.tart_executor_shell = shell
|
46
37
|
######################################################################
|
47
38
|
# Connect to VM
|
48
39
|
######################################################################
|
@@ -51,22 +42,21 @@ def run(default_ssh_username, default_ssh_password, ssh_timeout, tart_executable
|
|
51
42
|
|
52
43
|
try:
|
53
44
|
tart_ip = tart.ip(tart_vm_name, timeout=ssh_timeout)
|
54
|
-
click.echo(f"[INFO] Establishing SSH conntection to '{p.
|
45
|
+
click.echo(f"[{stage}][INFO] Establishing SSH conntection to '{p.ssh_username}@{tart_ip}'")
|
55
46
|
except:
|
56
47
|
click.secho(
|
57
|
-
f"[ERROR] Could not establish SSH conntection to '{tart_vm_name}' after '{ssh_timeout}' seconds.",
|
48
|
+
f"[{stage}][ERROR] Could not establish SSH conntection to '{tart_vm_name}' after '{ssh_timeout}' seconds.",
|
49
|
+
fg="red",
|
58
50
|
)
|
59
51
|
sys.exit(1)
|
60
52
|
|
61
53
|
try:
|
62
|
-
ssh_session = tart.ssh_session(name=p.vm_name(), username=p.
|
54
|
+
ssh_session = tart.ssh_session(name=p.vm_name(), username=p.ssh_username, password=p.ssh_password)
|
63
55
|
except:
|
64
|
-
click.secho(f"[ERROR] Could not establish SSH session with '{p.
|
56
|
+
click.secho(f"[{stage}][ERROR] Could not establish SSH session with '{p.ssh_username}@{tart_ip}'", fg="red")
|
65
57
|
sys.exit(1)
|
66
58
|
|
67
|
-
click.echo("[INFO] Preparing workspace")
|
68
59
|
remote_temp_dir = "/opt/temp"
|
69
|
-
|
70
60
|
script_name = os.path.basename(script)
|
71
61
|
remote_script_path = os.path.join(remote_temp_dir, stage + "-" + script_name)
|
72
62
|
|
@@ -75,6 +65,6 @@ def run(default_ssh_username, default_ssh_password, ssh_timeout, tart_executable
|
|
75
65
|
sftp.close()
|
76
66
|
|
77
67
|
# ssh_session.exec_ssh_command(f"cd {remote_build_dir}")
|
78
|
-
script_exit_code = ssh_session.exec_ssh_command(f"{shell} -l {remote_script_path}", get_pty=True)
|
68
|
+
script_exit_code = ssh_session.exec_ssh_command(f"{p.shell} -l {remote_script_path}", get_pty=True)
|
79
69
|
|
80
70
|
sys.exit(script_exit_code)
|
gitlab-runner-tart-driver-0.2.0/gitlab_runner_tart_driver/modules/gitlab_custom_command_config.py
ADDED
@@ -0,0 +1,102 @@
|
|
1
|
+
from typing import Optional
|
2
|
+
|
3
|
+
from pydantic import BaseSettings
|
4
|
+
from pydantic import Field
|
5
|
+
|
6
|
+
|
7
|
+
class GitLabCustomCommandConfig(BaseSettings):
|
8
|
+
"""Config parameters needed throughout the process read from the environment"""
|
9
|
+
|
10
|
+
ci_job_image: str
|
11
|
+
ci_pipeline_id: str
|
12
|
+
ci_job_id: str
|
13
|
+
ci_concurrent_id: str
|
14
|
+
ci_concurrent_project_id: str
|
15
|
+
ci_runner_short_token: str
|
16
|
+
ci_project_name: str
|
17
|
+
ci_registry: Optional[str]
|
18
|
+
ci_registry_user: Optional[str]
|
19
|
+
ci_registry_password: Optional[str]
|
20
|
+
|
21
|
+
tart_registry_username: Optional[str]
|
22
|
+
tart_registry_password: Optional[str]
|
23
|
+
tart_registry: Optional[str]
|
24
|
+
|
25
|
+
tart_ssh_username: Optional[str] = Field(default="admin")
|
26
|
+
tart_ssh_password: Optional[str] = Field(default="admin")
|
27
|
+
tart_max_vm_count: Optional[int] = Field(default=2)
|
28
|
+
tart_pull_policy: Optional[str] = Field(default="if-not-present")
|
29
|
+
tart_executor_softnet_enabled: Optional[str] = Field(default="false")
|
30
|
+
tart_executor_headless: Optional[str] = Field(default="true")
|
31
|
+
tart_executor_vnc_enabled: Optional[str] = Field(default="false")
|
32
|
+
tart_executor_install_gitlab_runner: Optional[str] = Field(default="false")
|
33
|
+
tart_executor_shell: Optional[str] = Field(default="/bin/zsh")
|
34
|
+
tart_executor_timeout: Optional[int] = Field(default=60)
|
35
|
+
tart_executor_display: Optional[str] = Field(default="1920x1200")
|
36
|
+
|
37
|
+
class Config:
|
38
|
+
"""Define the prefix used by GitLab for all environment variables passed to a custom driver.
|
39
|
+
see https://docs.gitlab.com/runner/executors/custom.html#stages
|
40
|
+
"""
|
41
|
+
|
42
|
+
env_prefix = "CUSTOM_ENV_"
|
43
|
+
|
44
|
+
def vm_name(self):
|
45
|
+
"""Creates a unique name for a VM"""
|
46
|
+
return f"{self.vm_name_prefix}-{self.ci_project_name}-{self.ci_pipeline_id}-{self.ci_job_id}-{self.ci_concurrent_id}"
|
47
|
+
|
48
|
+
@property
|
49
|
+
def vm_name_prefix(self):
|
50
|
+
return "grtd"
|
51
|
+
|
52
|
+
@property
|
53
|
+
def softnet_enabled(self) -> bool:
|
54
|
+
return self.tart_executor_softnet_enabled.lower() == "true"
|
55
|
+
|
56
|
+
@property
|
57
|
+
def vnc_enabled(self) -> bool:
|
58
|
+
return self.tart_executor_vnc_enabled.lower() == "true"
|
59
|
+
|
60
|
+
@property
|
61
|
+
def headless(self) -> bool:
|
62
|
+
return self.tart_executor_headless.lower() == "true"
|
63
|
+
|
64
|
+
@property
|
65
|
+
def shell(self) -> Optional[str]:
|
66
|
+
return self.tart_executor_shell
|
67
|
+
|
68
|
+
@property
|
69
|
+
def display(self) -> Optional[str]:
|
70
|
+
return self.tart_executor_display
|
71
|
+
|
72
|
+
@property
|
73
|
+
def install_gitlab_runner(self) -> bool:
|
74
|
+
return self.tart_executor_install_gitlab_runner.lower() == "true"
|
75
|
+
|
76
|
+
@property
|
77
|
+
def timeout(self) -> Optional[int]:
|
78
|
+
return self.tart_executor_timeout
|
79
|
+
|
80
|
+
@property
|
81
|
+
def ssh_username(self) -> Optional[str]:
|
82
|
+
return self.tart_ssh_username
|
83
|
+
|
84
|
+
@property
|
85
|
+
def ssh_password(self) -> Optional[str]:
|
86
|
+
return self.tart_ssh_password
|
87
|
+
|
88
|
+
@property
|
89
|
+
def pull_policy(self) -> Optional[str]:
|
90
|
+
return self.tart_pull_policy
|
91
|
+
|
92
|
+
@property
|
93
|
+
def registry_username(self) -> Optional[str]:
|
94
|
+
return self.tart_registry_username
|
95
|
+
|
96
|
+
@property
|
97
|
+
def registry_password(self) -> Optional[str]:
|
98
|
+
return self.tart_registry_password
|
99
|
+
|
100
|
+
@property
|
101
|
+
def registry(self) -> Optional[str]:
|
102
|
+
return self.tart_registry
|
@@ -153,11 +153,15 @@ class Tart(object):
|
|
153
153
|
"""stops a given tart VM"""
|
154
154
|
self.exec(["stop", name])
|
155
155
|
|
156
|
-
def run(self, name: str, volumes: list[TartVolume] = [], no_graphics=True) -> None:
|
156
|
+
def run(self, name: str, volumes: list[TartVolume] = [], no_graphics=True, softnet=False, vnc=False) -> None:
|
157
157
|
"""starts a given tart VM"""
|
158
158
|
args = ["run", name]
|
159
159
|
if no_graphics:
|
160
160
|
args.append("--no-graphics")
|
161
|
+
if softnet:
|
162
|
+
args.append("--net-softnet")
|
163
|
+
if vnc:
|
164
|
+
args.append("--vnc")
|
161
165
|
|
162
166
|
if volumes:
|
163
167
|
for d in volumes:
|
@@ -166,6 +170,8 @@ class Tart(object):
|
|
166
170
|
source_path = f"{source_path}:ro"
|
167
171
|
args.extend(["--dir", f"{d.name}:{source_path}"])
|
168
172
|
try:
|
173
|
+
print(f"Starting VM '{name}'")
|
174
|
+
print(f"Command: 'tart {' '.join(args)}'")
|
169
175
|
self.spawn_exec(args)
|
170
176
|
except Exception as e:
|
171
177
|
print(f"Error when running VM {name}")
|
@@ -1,6 +1,6 @@
|
|
1
1
|
Metadata-Version: 2.1
|
2
2
|
Name: gitlab-runner-tart-driver
|
3
|
-
Version: 0.
|
3
|
+
Version: 0.2.0
|
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
|
@@ -20,6 +20,7 @@ License-File: LICENSE.txt
|
|
20
20
|
- [Setup](#setup)
|
21
21
|
- [GitLab Runner Configuration](#gitlab-runner-configuration)
|
22
22
|
- [GitLab CI](#gitlab-ci)
|
23
|
+
- [Supported Environment Variables](#supported-environment-variables)
|
23
24
|
- [Private OCI Registries](#private-oci-registries)
|
24
25
|
- [Configuring the SSH Credentials](#configuring-the-ssh-credentials)
|
25
26
|
- [Advanced Configuration](#advanced-configuration)
|
@@ -177,6 +178,24 @@ run-on-tart:
|
|
177
178
|
- artifact.txt
|
178
179
|
```
|
179
180
|
|
181
|
+
### Supported Environment Variables
|
182
|
+
|
183
|
+
| **Name** | **Default** | **Description** |
|
184
|
+
| ------------------------------------- | -------------- | ------------------------------------------------------------------------------------------------------------- |
|
185
|
+
| `TART_REGISTRY_USERNAME` | | Username to login to private OCI registry |
|
186
|
+
| `TART_REGISTRY_PASSWORD` | | Password to login to private OCI registry |
|
187
|
+
| `TART_REGISTRY` | | Private OCI registry |
|
188
|
+
| `TART_PULL_POLICY` | if-not-present | define how runners pull tart images from registries. Options are `always`,`if-not-present`,`never` |
|
189
|
+
| `TART_SSH_USERNAME` | admin | Username to use to login to VM |
|
190
|
+
| `TART_SSH_PASSWORD` | admin | Password to use to login to VM |
|
191
|
+
| `TART_EXECUTOR_HEADLESS` | true | Don't open a UI window. |
|
192
|
+
| `TART_EXECUTOR_SOFTNET_ENABLED` | false | Use software networking instead of the default shared (NAT) networking |
|
193
|
+
| `TART_EXECUTOR_VNC_ENABLED` | false | Use screen sharing instead of the built-in UI. Note that Remote Login option should be enabled inside the VM. |
|
194
|
+
| `TART_EXECUTOR_INSTALL_GITLAB_RUNNER` | false | Install a GitLabRunner into the VM to ensure full CI/CD functionality |
|
195
|
+
| `TART_EXECUTOR_SHELL` | /bin/zsh | The shell that should be used when running commands |
|
196
|
+
| `TART_EXECUTOR_TIMEOUT` | 60 | Timeout for `tart ip` to respond with a valid IP |
|
197
|
+
| `TART_EXECUTOR_DISPLAY` | 1920x1200 | Display resolution in format `WxH` |
|
198
|
+
|
180
199
|
### Private OCI Registries
|
181
200
|
|
182
201
|
Oftentimes you might want to provide your own OCI-compliant images created with [Packer](https://www.packer.io) and the official [Tart Builder](https://developer.hashicorp.com/packer/plugins/builders/tart). If you push your images to a private registry you will need to provide the credentials for the `gitlab-runner-tart-driver` to login there first.
|
@@ -346,9 +365,7 @@ see **Command `run`**
|
|
346
365
|
|
347
366
|
### Custom `pull_policy`
|
348
367
|
|
349
|
-
You can use a custom `pull_policy`. The default policy is `if-not-present`
|
350
|
-
|
351
|
-
see **Command `prepare`**
|
368
|
+
You can use a custom `pull_policy`. The default policy is `if-not-present`. Use `TART_PULL_POLICY` to override the default pull policy
|
352
369
|
|
353
370
|
## CLI
|
354
371
|
|
@@ -391,14 +408,6 @@ Usage: gitlab-runner-tart-driver prepare [OPTIONS]
|
|
391
408
|
Prepare the environment and start the tart VM.
|
392
409
|
|
393
410
|
Options:
|
394
|
-
--default-ssh-username TEXT username to login to a tart vm
|
395
|
-
--default-ssh-password TEXT password to login to a tart vm
|
396
|
-
--pull-policy [always|if-not-present|never]
|
397
|
-
define how runners pull tart images from
|
398
|
-
registries
|
399
|
-
--registry-username TEXT username to login to a oci registry
|
400
|
-
--registry-password TEXT password to login to a oci registry
|
401
|
-
--registry TEXT username to login to a oci registry
|
402
411
|
--cpu INTEGER Number of CPUs associated to VM
|
403
412
|
--memory INTEGER VM memory size in megabytes associated to VM
|
404
413
|
--display TEXT VM display resolution in a format of
|
@@ -434,8 +443,6 @@ Usage: gitlab-runner-tart-driver run [OPTIONS] SCRIPT STAGE
|
|
434
443
|
Run commands.
|
435
444
|
|
436
445
|
Options:
|
437
|
-
--default-ssh-username TEXT username to login to a tart vm
|
438
|
-
--default-ssh-password TEXT password to login to a tart vm
|
439
446
|
--timeout INTEGER SSH connection timeout in seconds
|
440
447
|
-x, --tart-executable TEXT Path to the tart executable.
|
441
448
|
--shell TEXT Path to the shell to be used for commands over
|
@@ -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.
|
13
|
+
version = "0.2.0"
|
14
14
|
|
15
15
|
version = f"{version}{os.environ.get('PIP_VERSION_POSTFIX','')}"
|
16
16
|
|
@@ -1 +0,0 @@
|
|
1
|
-
__version__ = "0.1.7"
|
gitlab-runner-tart-driver-0.1.7/gitlab_runner_tart_driver/modules/gitlab_custom_command_config.py
DELETED
@@ -1,43 +0,0 @@
|
|
1
|
-
from typing import Optional
|
2
|
-
|
3
|
-
from pydantic import BaseSettings
|
4
|
-
from pydantic import Field
|
5
|
-
|
6
|
-
|
7
|
-
class GitLabCustomCommandConfig(BaseSettings):
|
8
|
-
"""Config parameters needed throughout the process read from the environment"""
|
9
|
-
|
10
|
-
ci_job_image: str
|
11
|
-
ci_pipeline_id: str
|
12
|
-
ci_job_id: str
|
13
|
-
ci_concurrent_id: str
|
14
|
-
ci_concurrent_project_id: str
|
15
|
-
ci_runner_short_token: str
|
16
|
-
ci_project_name: str
|
17
|
-
ci_registry: Optional[str]
|
18
|
-
ci_registry_user: Optional[str]
|
19
|
-
ci_registry_password: Optional[str]
|
20
|
-
|
21
|
-
tart_registry_username: Optional[str]
|
22
|
-
tart_registry_password: Optional[str]
|
23
|
-
tart_registry: Optional[str]
|
24
|
-
|
25
|
-
tart_ssh_username: Optional[str]
|
26
|
-
tart_ssh_password: Optional[str]
|
27
|
-
|
28
|
-
tart_max_vm_count: Optional[int] = Field(default=2)
|
29
|
-
|
30
|
-
class Config:
|
31
|
-
"""Define the prefix used by GitLab for all environment variables passed to a custom driver.
|
32
|
-
see https://docs.gitlab.com/runner/executors/custom.html#stages
|
33
|
-
"""
|
34
|
-
|
35
|
-
env_prefix = "CUSTOM_ENV_"
|
36
|
-
|
37
|
-
def vm_name(self):
|
38
|
-
"""Creates a unique name for a VM"""
|
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"
|
File without changes
|
File without changes
|
File without changes
|
{gitlab-runner-tart-driver-0.1.7 → gitlab-runner-tart-driver-0.2.0}/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
|
File without changes
|
File without changes
|