extend runner configuration

This commit is contained in:
sebthom 2024-10-24 18:37:38 +02:00
parent 7c9b6cd583
commit 72b54f14de
4 changed files with 25 additions and 12 deletions

View File

@ -119,7 +119,7 @@ Name|Default Value|Description
----|-------------|-----------
GITEA_INSTANCE_INSECURE|`false`|It `true` don't verify the TLS certificate of the Gitea instance
GITEA_RUNNER_NAME|`<empty>`|If not specified the container's hostname is used
GITEA_RUNNER_LABELS|`<empty>`|Comma-separated list of labels in the format of `label[:schema[:args]]`. If not specified the following labels are used `ubuntu-latest:docker://catthehacker/ubuntu:act-22.04,ubuntu-22.04:docker://catthehacker/ubuntu:act-22.04,ubuntu-20.04:docker://catthehacker/ubuntu:act-20.04`
GITEA_RUNNER_LABELS|`<empty>`|Comma-separated list of labels in the format of `label[:schema[:args]]`.<br>If not specified the following labels are used<ol><li>`ubuntu-latest:docker://catthehacker/ubuntu:act-latest`<li>`ubuntu-22.04:docker://catthehacker/ubuntu:act-22.04`<li>`ubuntu-20.04:docker://catthehacker/ubuntu:act-20.04`</ol>
GITEA_RUNNER_REGISTRATION_FILE|`/data/.runner`|The JSON file that holds the result from the runner registration with the Gitea instance
GITEA_RUNNER_REGISTRATION_TIMEOUT|`30`|In case of failure, registration is retried until this timeout in seconds is reached
GITEA_RUNNER_REGISTRATION_RETRY_INTERVAL|`5`|Wait period in seconds between registration retries
@ -148,9 +148,11 @@ GITEA_RUNNER_JOB_CONTAINER_DOCKER_HOST|`<empty>`|If empty, the available docker
GITEA_RUNNER_JOB_CONTAINER_NETWORK|`bridge`|Docker network to use with job containers. Can be `bridge`, `host`, `none`, or the name of a custom network
GITEA_RUNNER_JOB_CONTAINER_PRIVILEGED|`false`|Whether to run jobs in containers with privileged mode which is required for **Docker-in-Docker** aka **dind**
GITEA_RUNNER_JOB_CONTAINER_OPTIONS|`<empty>`|Additional container launch options (eg, --add-host=my.gitea.url:host-gateway)
GITEA_RUNNER_JOB_CONTAINER_WORKDIR_PARENT|`/workspace`|The parent directory of a job's working directory.
GITEA_RUNNER_JOB_CONTAINER_FORCE_PULL|`false`|Pull docker images even if already present
GITEA_RUNNER_JOB_CONTAINER_WORKDIR_PARENT|`/workspace`|The parent directory of a job's working directory
GITEA_RUNNER_JOB_CONTAINER_FORCE_PULL|`true`|Pull docker image(s) even if already present
GITEA_RUNNER_JOB_CONTAINER_FORCE_REBUILD|`false`|Rebuild docker image(s) even if already present
GITEA_RUNNER_JOB_TIMEOUT|`3h`|The maximum time a job can run before it is cancelled
GITEA_RUNNER_SHUTDOWN_TIMEOUT|`0s`|The timeout for the runner to wait for running jobs to finish when shutting down
GITEA_RUNNER_ENV_VAR_**N**_NAME|`<empty>`|Name of the **N**-th extra environment variable to be passed to Job containers, e.g. `GITEA_RUNNER_ENV_VAR_1_NAME=MY_AUTH_TOKEN`
GITEA_RUNNER_ENV_VAR_**N**_VALUE|`<empty>`|Value of the **N**-th extra environment variable to be passed to Job containers, e.g. `GITEA_RUNNER_ENV_VAR_1_VALUE=SGVsbG8gbXkgZnJpZW5kIQ==`
GITEA_RUNNER_VALID_VOLUME_**N**|`<empty>`|Volumes (including bind mounts) that are allowed to be mounted into job containers. [Glob syntax](https://github.com/gobwas/glob) is supported, e.g. `GITEA_RUNNER_VALID_VOLUME_1=/src/*.json`

View File

@ -192,7 +192,7 @@ ENV \
GITEA_RUNNER_NAME='' \
GITEA_RUNNER_LABELS='' \
GITEA_RUNNER_LABELS_DEFAULT='\
ubuntu-latest:docker://catthehacker/ubuntu:act-22.04,\
ubuntu-latest:docker://catthehacker/ubuntu:act-latest,\
ubuntu-22.04:docker://catthehacker/ubuntu:act-22.04,\
ubuntu-20.04:docker://catthehacker/ubuntu:act-20.04' \
GITEA_RUNNER_UID=1000 \

View File

@ -1,4 +1,4 @@
# based on https://gitea.com/gitea/act_runner/src/tag/v0.2.6/internal/pkg/config/config.example.yaml
# based on https://gitea.com/gitea/act_runner/src/tag/v0.2.11/internal/pkg/config/config.example.yaml
log:
# The level of logging, can be trace, debug, info, warn, error, fatal
@ -27,6 +27,9 @@ runner:
# Please note that the Gitea instance also has a timeout (3h by default) for the job.
# So the job could be stopped by the Gitea instance if it's timeout is shorter than this.
timeout: '${GITEA_RUNNER_JOB_TIMEOUT:-3h}'
# The timeout for the runner to wait for running jobs to finish when shutting down.
# Any running jobs that haven't finished after this timeout will be cancelled.
shutdown_timeout: ${GITEA_RUNNER_SHUTDOWN_TIMEOUT:-0s}
# Whether skip verifying the TLS certificate of the Gitea instance.
insecure: ${GITEA_INSTANCE_INSECURE:-false}
# The timeout for fetching the job from the Gitea instance.
@ -34,10 +37,11 @@ runner:
# The interval for fetching the job from the Gitea instance.
fetch_interval: '${GITEA_RUNNER_FETCH_INTERVAL:-2s}'
# The labels of a runner are used to determine which jobs the runner can run, and how to run them.
# Like: ["macos-arm64:host", "ubuntu-latest:docker://node:16-bullseye", "ubuntu-22.04:docker://node:16-bullseye"]
# Like: "macos-arm64:host" or "ubuntu-latest:docker://gitea/runner-images:ubuntu-latest"
# Find more images provided by Gitea at https://gitea.com/gitea/runner-images .
# If it's empty when registering, it will ask for inputting labels.
# If it's empty when execute `daemon`, will use labels in `.runner` file.
#labels: []
labels: [ "${GITEA_RUNNER_LABELS//,/","}" ]
cache:
# Enable cache server to use actions/cache.
@ -67,6 +71,9 @@ container:
# And other options to be used when the container is started (eg, --add-host=my.gitea.url:host-gateway).
options: '${GITEA_RUNNER_JOB_CONTAINER_OPTIONS:-}'
# The parent directory of a job's working directory.
# NOTE: There is no need to add the first '/' of the path as act_runner will add it automatically.
# If the path starts with '/', the '/' will be trimmed.
# For example, if the parent directory is /path/to/my/dir, workdir_parent should be path/to/my/dir
# If it's empty, /workspace will be used.
workdir_parent: ${GITEA_RUNNER_JOB_CONTAINER_WORKDIR_PARENT:-/workspace}
# Volumes (including bind mounts) can be mounted to containers. Glob syntax is supported, see https://github.com/gobwas/glob
@ -93,7 +100,10 @@ container:
# If it's "-", act_runner will find an available docker host automatically, but the docker host won't be mounted to the job containers and service containers.
# If it's not empty or "-", the specified docker host will be used. An error will be returned if it doesn't work.
docker_host: '${GITEA_RUNNER_JOB_CONTAINER_DOCKER_HOST:-}'
force_pull: ${GITEA_RUNNER_JOB_CONTAINER_FORCE_PULL:-false}
# Pull docker image(s) even if already present
force_pull: ${GITEA_RUNNER_JOB_CONTAINER_FORCE_PULL:-true}
# Rebuild docker image(s) even if already present
force_rebuild: ${GITEA_RUNNER_JOB_CONTAINER_FORCE_REBUILD:-false}
host:
# The parent directory of a job's working directory.

View File

@ -24,6 +24,10 @@ fi
#################################################
# render config file
#################################################
if [[ -z ${GITEA_RUNNER_LABELS:-} ]]; then
GITEA_RUNNER_LABELS=$GITEA_RUNNER_LABELS_DEFAULT
fi
effective_config_file=/tmp/gitea_act_runner_config.yml
rm -f "$effective_config_file"
if [[ ${GITEA_RUNNER_LOG_EFFECTIVE_CONFIG:-false} == "true" ]]; then
@ -52,13 +56,10 @@ if [[ ! -s ${GITEA_RUNNER_REGISTRATION_FILE:-.runner} ]]; then
read -r GITEA_RUNNER_REGISTRATION_TOKEN < "$GITEA_RUNNER_REGISTRATION_TOKEN_FILE"
fi
if [[ -z ${GITEA_RUNNER_LABELS:-} ]]; then
GITEA_RUNNER_LABELS=$GITEA_RUNNER_LABELS_DEFAULT
fi
log INFO "Trying to register runner with Gitea..."
log INFO " GITEA_INSTANCE_URL=$GITEA_INSTANCE_URL"
log INFO " GITEA_RUNNER_NAME=$GITEA_RUNNER_NAME"
log INFO " GITEA_RUNNER_REGISTRATION_TOKEN=${GITEA_RUNNER_REGISTRATION_TOKEN//?/*}"
log INFO " GITEA_RUNNER_LABELS=$GITEA_RUNNER_LABELS"
wait_until=$(( $(date +%s) + $GITEA_RUNNER_REGISTRATION_TIMEOUT ))
while true; do