64 lines
2.9 KiB
Cheetah
64 lines
2.9 KiB
Cheetah
{{- if eq .host.distro.family "linux" -}}
|
|
#!/usr/bin/env bash
|
|
# @file GitLab Runner Configuration
|
|
# @brief Registers GitLab Runner 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.
|
|
#
|
|
# Configuring other executors is not supported by this script.
|
|
#
|
|
# ## Secrets
|
|
#
|
|
# The following chart details the secret(s) that are needed to configure the runner:
|
|
#
|
|
# | Secret | Description |
|
|
# |------------------------|------------------------------------------------------------|
|
|
# | `GITLAB_RUNNER_TOKEN` | The token generated when the runner was created in GitLab |
|
|
#
|
|
# For more information about storing secrets like SSH keys and API keys, refer to our Secrets documentation provided below
|
|
#
|
|
# ## Configuration Variables
|
|
#
|
|
# 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 |
|
|
#
|
|
# ## Links
|
|
#
|
|
# * [Secrets / Environment variables documentation](https://install.doctor/docs/customization/secrets)
|
|
|
|
{{ 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
|
|
else
|
|
logg warn 'gitlab-runner is not installed or is not available in PATH'
|
|
fi
|
|
|
|
{{ end -}}
|