Add VBox executor
This commit is contained in:
parent
0586cb26d2
commit
8302304078
2 changed files with 81 additions and 35 deletions
|
@ -141,10 +141,14 @@ data:
|
|||
doRegion: nyc1
|
||||
domain: "{{ $domain }}"
|
||||
gitlabRunners:
|
||||
glurl: "https://gitlab.com/"
|
||||
runnerDescription: "Docker executor"
|
||||
runnerImage: "alpine:latest"
|
||||
runnerTags: ""
|
||||
- glurl: "https://gitlab.com/"
|
||||
runnerDescription: "Docker executor"
|
||||
runnerImage: "alpine:latest"
|
||||
runnerTags: ""
|
||||
- glurl: "https://gitlab.com/"
|
||||
baseVM: "debian"
|
||||
runnerDescription: "VirtualBox executor - Debian, OpenJDK 20"
|
||||
runnerTags: "bash,openjdk20,linux"
|
||||
headless: {{ $headless }}
|
||||
home: "{{ .chezmoi.homeDir }}"
|
||||
homeParentFolder: "{{ if eq .chezmoi.os "linux" }}/home{{ else if eq .chezmoi.os "darwin" }}/Users{{ else }}C:\Users{{ end }}"
|
||||
|
|
|
@ -1,11 +1,12 @@
|
|||
{{- if eq .host.distro.family "linux" -}}
|
||||
#!/usr/bin/env bash
|
||||
# @file GitLab Runner Configuration
|
||||
# @brief Registers GitLab Runner with the given GitLab instance
|
||||
# @brief Registers GitLab Runner(s) with the given GitLab instance
|
||||
# @description
|
||||
# This script registers the runners with the given GitLab instance. SaaS GitLab can also be provided as the GitLab instance to register
|
||||
# the runners with. The script configures the runners to use Docker Executor. Refer to
|
||||
# [this page](https://docs.gitlab.com/runner/executors/docker.html) for details about the available configuration settings.
|
||||
# This script registers the runner(s) with the given GitLab instance. SaaS GitLab can also be provided as the GitLab instance to register
|
||||
# the runners with. The script configures the runners to use either Docker or VirtualBox Executor. Refer to
|
||||
# [this page](https://docs.gitlab.com/runner/executors/docker.html) and [this page](https://docs.gitlab.com/runner/executors/virtualbox.html)
|
||||
# for details about the available configuration settings.
|
||||
#
|
||||
# Configuring other executors is not supported by this script.
|
||||
#
|
||||
|
@ -23,12 +24,13 @@
|
|||
#
|
||||
# The following chart details the input variable(s) that are used to determine the configuration of the runner:
|
||||
#
|
||||
# | Variable | Description |
|
||||
# |---------------------|-------------------------------------------------------------|
|
||||
# | `glurl` | The URL of the Gitlab instance to associate the Runner with |
|
||||
# | `runnerImage` | Docker image to use to configure the runner |
|
||||
# | `runnerDescription` | Description of this runner |
|
||||
# | `runnerTags` | Comma separated list of tags for this runner |
|
||||
# | Variable | Description |
|
||||
# |---------------------|----------------------------------------------------------------------------------------------------------|
|
||||
# | `glurl` | The URL of the Gitlab instance to associate the Runner with |
|
||||
# | `runnerImage` | Docker image to use to configure the runner. Needed only when configuring `Docker` executor |
|
||||
# | `runnerDescription` | Description of this runner |
|
||||
# | `runnerTags` | Comma separated list of tags for this runner |
|
||||
# | `baseVM` | Name of the VirtualBox VM to use for creating runner. Needed only when configuring `VirtualBox` executor |
|
||||
#
|
||||
# ## Links
|
||||
#
|
||||
|
@ -37,28 +39,68 @@
|
|||
{{ includeTemplate "universal/profile" }}
|
||||
{{ includeTemplate "universal/logg" }}
|
||||
|
||||
### Run logic if gitlab-runner is installed
|
||||
if command -v gitlab-runner > /dev/null; then
|
||||
### Check if Runner Token value is present
|
||||
if [ -v $GITLAB_RUNNER_TOKEN ]; then
|
||||
### Registering runner
|
||||
logg info 'Registering GitLab Runner with the provided tags'
|
||||
{{range .host.gitlabRunners -}}
|
||||
gitlab-runner register \
|
||||
--non-interactive \
|
||||
--url {{ .glurl }} \
|
||||
--token $GITLAB_RUNNER_TOKEN \
|
||||
--executor "docker" \
|
||||
--docker-image {{ .runnerImage }} \
|
||||
--description "{{ .runnerDescription }} - on {{ .chezmoi.hostname }}" \
|
||||
{{if and .runnerTags (gt (len .runnerTags) 0) }}--tag-list "{{ .runnerTags }}"
|
||||
{{ else }}--run-untagged{{ end }}
|
||||
{{ end }}
|
||||
else
|
||||
logg warn 'GITLAB_RUNNER_TOKEN is not set. Not registering the runner'
|
||||
fi
|
||||
### Check if Docker is installed and operational so Docker executor(s) can be registered
|
||||
if command -v docker > /dev/null && docker run --rm hello-world > /dev/null; then
|
||||
HAS_DOCKER=1
|
||||
else
|
||||
logg warn 'gitlab-runner is not installed or is not available in PATH'
|
||||
logg warn 'Docker is not installed or it is not operational'
|
||||
fi
|
||||
|
||||
### Check if VirtualBox is installed and operational so VirtualBox executor(s) can be registered
|
||||
if command -v VirtualBox > /dev/null; then
|
||||
HAS_VIRTUALBOX=1
|
||||
else
|
||||
logg warn 'VirtualBox is not installed'
|
||||
fi
|
||||
|
||||
### Configure runners if Docker or VirtualBox is installed
|
||||
if [ $HAS_DOCKER -eq 0 ] && [ $HAS_VIRTUALBOX -eq 0 ]; then
|
||||
logg warn 'Docker and VirtualBox are not installed. Not registering runner(s).'
|
||||
else
|
||||
### Run logic if gitlab-runner is installed
|
||||
if command -v gitlab-runner > /dev/null; then
|
||||
### Check if Runner Token value is present before attempting to register runner(s)
|
||||
if [ -v $GITLAB_RUNNER_TOKEN ]; then
|
||||
### Registering runners
|
||||
{{ $cmd := `gitlab-runner register \
|
||||
--non-interactive \
|
||||
--token $GITLAB_RUNNER_TOKEN \` }}
|
||||
### Register Docker based runners if Docker is installed and operational
|
||||
if [ $HAS_DOCKER -eq 1 ]; then
|
||||
logg info 'Registering GitLab Runner(s) that use Docker executor'
|
||||
{{- range .host.gitlabRunners }}
|
||||
{{- if .runnerImage }}
|
||||
{{- $cmd }}
|
||||
--url {{ .glurl }} \
|
||||
--executor "docker" \
|
||||
--description "{{ .runnerDescription }} - on {{ .chezmoi.hostname }}" \
|
||||
--docker-image {{ .runnerImage }} \
|
||||
{{ if and .runnerTags (gt (len .runnerTags) 0) }}--tag-list "{{ .runnerTags }}"
|
||||
{{ else }}--run-untagged{{ end }} || echo 'Runner registration failed"
|
||||
{{ end -}}
|
||||
{{ end }}
|
||||
fi
|
||||
### Register VirtualBox based runners if VirtualBox is installed
|
||||
if [ $HAS_VIRTUALBOX -eq 1 ]; then
|
||||
logg info 'Registering GitLab Runner(s) that use VirtualBox executor'
|
||||
{{- range .host.gitlabRunners }}
|
||||
{{- if .baseVM }}
|
||||
{{- $cmd }}
|
||||
--url {{ .glurl }} \
|
||||
--executor "virtualbox" \
|
||||
--description "{{ .runnerDescription }} - on {{ .chezmoi.hostname }}" \
|
||||
--virtualbox-base-name "{{ .baseVM }}" \
|
||||
{{ if and .runnerTags (gt (len .runnerTags) 0) }}--tag-list "{{ .runnerTags }}"
|
||||
{{ else }}--run-untagged{{ end }} || echo 'Runner registration failed"
|
||||
{{ end -}}
|
||||
{{ end }}
|
||||
fi
|
||||
else
|
||||
logg warn 'GITLAB_RUNNER_TOKEN is not set. Not registering runner(s)'
|
||||
fi
|
||||
else
|
||||
logg warn 'gitlab-runner is not installed or is not available in PATH'
|
||||
fi
|
||||
fi
|
||||
|
||||
{{ end -}}
|
||||
|
|
Loading…
Reference in a new issue