add forgejo-runner playbook + role

This commit is contained in:
Finn 2024-02-17 18:26:24 -08:00
parent f0aead75c2
commit 10503a44a0
10 changed files with 210 additions and 1 deletions

1
.gitignore vendored
View file

@ -1 +1,2 @@
/secrets /secrets
secrets.yaml

View file

@ -0,0 +1,7 @@
- hosts: forgejo_runners
vars:
ansible_user: root
roles:
- base
- monitoring
- forgejo-runner

View file

@ -36,3 +36,10 @@ home_k8s:
home_network: true home_network: true
k8s-node-3: k8s-node-3:
home_network: true home_network: true
forgejo_runners:
hosts:
forgejo-runner-0:
home_network: true
forgejo-runner-1:
home_network: true

View file

@ -0,0 +1,17 @@
- name: systemctl daemon-reload
command: systemctl daemon-reload
- name: restart podman.service
service:
name: podman.service
state: restarted
- name: restart podman.socket
service:
name: podman.socket
state: restarted
- name: restart forgejo-runner
service:
name: forgejo-runner
state: restarted

View file

@ -0,0 +1,56 @@
- name: Install podman
apt:
name: [podman]
- name: make some directories
file:
path: "{{ item }}"
state: directory
with_items:
- /etc/forgejo-runner
- /opt/shared-with-host
- /var/forgejo-runner
- /etc/systemd/system/podman.service.d
- /etc/systemd/system/podman.socket.d
- name: configure podman service
template:
src: podman.service-override.conf
dest: /etc/systemd/system/podman.service.d/override.conf
notify:
- systemctl daemon-reload
- restart podman.service
- name: configure podman socket
template:
src: podman.socket-override.conf
dest: /etc/systemd/system/podman.socket.d/override.conf
notify:
- systemctl daemon-reload
- restart podman.socket
- name: enable podman
service:
name: "{{ item }}"
enabled: true
with_items: [podman.socket, podman.service]
- name: configure forgejo-runner
template:
src: forgejo-runner.yaml
dest: /etc/forgejo-runner/config.yaml
notify:
- restart forgejo-runner
- name: install forgejo-runner.service
template:
src: forgejo-runner.service
dest: /etc/systemd/system/forgejo-runner.service
notify:
- systemctl daemon-reload
- restart forgejo-runner
- name: register the runner
command: podman run --rm --user root -tiv /etc/forgejo-runner:/etc/forgejo-runner:ro -v /var/forgejo-runner:/data code.forgejo.org/forgejo/runner:3.3.0 forgejo-runner register --instance https://git.janky.solutions --name "{{ inventory_hostname }}" --token "{{ lookup('ansible.builtin.ini', 'registration_token section=forgejo_runner file=secrets/git.janky.solutions.ini') }}" --no-interactive
args:
creates: /var/forgejo-runner/.runner

View file

@ -0,0 +1,34 @@
[Unit]
Description=Forgejo Runner
Wants=network.target
[Service]
Environment=PODMAN_SYSTEMD_UNIT=%n
Restart=on-failure
TimeoutStopSec=70
ExecStartPre=/bin/rm -f %t/forgejo-runner.service.pid %t/forgejo-runner.service.ctr-id
ExecStartPre=-/usr/bin/podman pull code.forgejo.org/forgejo/runner:3.3.0
ExecStart=/usr/bin/podman run \
--cidfile=%t/%n.ctr-id \
--cgroups=no-conmon \
--rm \
--sdnotify=conmon \
--user=0 \
-d \
--conmon-pidfile %t/forgejo-runner.service.pid \
--replace \
--env DOCKER_HOST=unix:///run/podman/podman.sock \
--name forgejo-runner \
-v /run/podman/podman.sock:/run/podman/podman.sock \
-v /etc/forgejo-runner:/etc/forgejo-runner:ro \
-v /opt/shared-with-host:/opt/shared-with-host \
-v /var/forgejo-runner:/data code.forgejo.org/forgejo/runner:3.3.0 forgejo-runner daemon \
-c /etc/forgejo-runner/config.yaml
ExecStop=/usr/bin/podman stop --ignore --cidfile %t/forgejo-runner.service.ctr-id -t 10
ExecStopPost=/usr/bin/podman rm --ignore -f --cidfile %t/forgejo-runner.service.ctr-id
PIDFile=%t/forgejo-runner.service.pid
Type=forking
RestartSec=60
[Install]
WantedBy=multi-user.target default.target

View file

@ -0,0 +1,83 @@
log:
# The level of logging, can be trace, debug, info, warn, error, fatal
level: debug
runner:
# Where to store the registration result.
file: .runner
# Execute how many tasks concurrently at the same time.
capacity: 1
# Extra environment variables to run jobs.
envs:
GO_PROXY: goproxy.home.finn.io
# Extra environment variables to run jobs from a file.
# It will be ignored if it's empty or the file doesn't exist.
env_file: .env
# The timeout for a job to be finished.
# Please note that the Forgejo instance also has a timeout (3h by default) for the job.
# So the job could be stopped by the Forgejo instance if it's timeout is shorter than this.
timeout: 3h
# Whether skip verifying the TLS certificate of the Forgejo instance.
insecure: false
# The timeout for fetching the job from the Forgejo instance.
fetch_timeout: 5s
# The interval for fetching the job from the Forgejo instance.
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"]
# If it's empty when registering, it will ask for inputting labels.
# If it's empty when execute `deamon`, will use labels in `.runner` file.
labels: []
cache:
# Enable cache server to use actions/cache.
enabled: true
# The directory to store the cache data.
# If it's empty, the cache data will be stored in $HOME/.cache/actcache.
dir: ""
# The host of the cache server.
# It's not for the address to listen, but the address to connect from job containers.
# So 0.0.0.0 is a bad choice, leave it empty to detect automatically.
host: ""
# The port of the cache server.
# 0 means to use a random available port.
port: 0
# The external cache server URL. Valid only when enable is true.
# If it's specified, act_runner will use this URL as the ACTIONS_CACHE_URL rather than start a server by itself.
# The URL should generally end with "/".
external_server: ""
container:
# Specifies the network to which the container will connect.
# Could be host, bridge or the name of a custom network.
# If it's empty, create a network automatically.
network: ""
# Whether to use privileged mode or not when launching task containers (privileged mode is required for Docker-in-Docker).
privileged: true
# And other options to be used when the container is started (eg, --add-host=my.forgejo.url:host-gateway).
options:
# The parent directory of a job's working directory.
# If it's empty, /workspace will be used.
workdir_parent:
# Volumes (including bind mounts) can be mounted to containers. Glob syntax is supported, see https://github.com/gobwas/glob
# You can specify multiple volumes. If the sequence is empty, no volumes can be mounted.
# For example, if you only allow containers to mount the `data` volume and all the json files in `/src`, you should change the config to:
# valid_volumes:
# - data
# - /src/*.json
# If you want to allow any volume, please use the following configuration:
# valid_volumes:
# - '**'
valid_volumes: []
# overrides the docker client host with the specified one.
# If it's empty, act_runner will find an available docker host automatically.
# 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: "unix:///run/podman/podman.sock"
# Pull docker image(s) even if already present
force_pull: false
host:
# The parent directory of a job's working directory.
# If it's empty, $HOME/.cache/act/ will be used.
workdir_parent:

View file

@ -0,0 +1,2 @@
[Service]
Environment=LOGGING="--log-level=warn"

View file

@ -0,0 +1,2 @@
[Socket]
SocketGroup=debian

View file

@ -1,6 +1,6 @@
server: server:
log_level: warn log_level: warn
http_listen_port: 0 http_listen_port: 9080
grpc_listen_port: 0 grpc_listen_port: 0
clients: clients: