runner: connect with UUID and token instead of registering
All checks were successful
nixos / nixos (push) Successful in 1m8s
All checks were successful
nixos / nixos (push) Successful in 1m8s
The runner's token was regenerated in Forgejo (runner asxpio-services,
same UUID), which also retires the registration-token route the NixOS
module used. Both runners now work the same way: settings from Nix, the
connection (URL, UUID, token from sops) merged in at start, no
registration step. A new token is a sops change and a deploy.
Corrects 0a54caa: `forgejo actions generate-runner-token` returned the
existing registration token, so that commit rotated nothing.
Assisted-by: Claude:opus-5-5
This commit is contained in:
parent
0a54caa7d4
commit
b7414c2ad1
1 changed files with 163 additions and 138 deletions
|
|
@ -3,6 +3,11 @@
|
|||
#
|
||||
# asxpio for git.asxp.io, reached over the private network
|
||||
# interop for another-im/interop on dev.another.im
|
||||
#
|
||||
# Both connect with a UUID and token from Forgejo's "Create new runner"
|
||||
# (or a token reset there); no registration step. The UUID is in the
|
||||
# config, the token in sops; the connection is merged into the config at
|
||||
# start. A new token means: put it in sops, deploy.
|
||||
{
|
||||
config,
|
||||
lib,
|
||||
|
|
@ -19,71 +24,84 @@ let
|
|||
nixVersion = "2.35.6";
|
||||
|
||||
yaml = pkgs.formats.yaml { };
|
||||
interopConfig = yaml.generate "runner-interop.yaml" {
|
||||
log = {
|
||||
level = "info";
|
||||
job_level = "info";
|
||||
};
|
||||
runner = {
|
||||
capacity = 3;
|
||||
timeout = "5h";
|
||||
shutdown_timeout = "5h";
|
||||
fetch_interval = "5s";
|
||||
envs.NIX_CONFIG = ''
|
||||
experimental-features = nix-command flakes
|
||||
build-users-group =
|
||||
sandbox = false
|
||||
|
||||
# runner <name> <settings without server.connections> <sops secret> <url> <uuid>
|
||||
runner =
|
||||
{
|
||||
name,
|
||||
description,
|
||||
settings,
|
||||
tokenSecret,
|
||||
url,
|
||||
uuid,
|
||||
}:
|
||||
let
|
||||
configFile = yaml.generate "runner-${name}.yaml" settings;
|
||||
in
|
||||
{
|
||||
sops.secrets.${tokenSecret}.restartUnits = [ "forgejo-runner-${name}.service" ];
|
||||
sops.templates."runner-${name}-server.yaml".content = ''
|
||||
server:
|
||||
connections:
|
||||
${name}:
|
||||
url: ${url}
|
||||
uuid: ${uuid}
|
||||
token: ${config.sops.placeholder.${tokenSecret}}
|
||||
'';
|
||||
labels = [
|
||||
"nix:docker://nixos/nix:${nixVersion}"
|
||||
"docker:docker://node:22.23.5-bookworm"
|
||||
"nix-host:docker://nixos/nix:${nixVersion}"
|
||||
];
|
||||
|
||||
systemd.services."forgejo-runner-${name}" = {
|
||||
inherit description;
|
||||
wantedBy = [ "multi-user.target" ];
|
||||
after = [
|
||||
"network-online.target"
|
||||
"podman.socket"
|
||||
];
|
||||
wants = [
|
||||
"network-online.target"
|
||||
"podman.socket"
|
||||
];
|
||||
environment.DOCKER_HOST = "unix:///run/podman/podman.sock";
|
||||
path = [
|
||||
pkgs.forgejo-runner
|
||||
pkgs.yq-go
|
||||
];
|
||||
serviceConfig = {
|
||||
DynamicUser = true;
|
||||
SupplementaryGroups = [ "podman" ];
|
||||
StateDirectory = "forgejo-runner-${name}";
|
||||
WorkingDirectory = "/var/lib/forgejo-runner-${name}";
|
||||
RuntimeDirectory = "forgejo-runner-${name}";
|
||||
LoadCredential = "server.yaml:${config.sops.templates."runner-${name}-server.yaml".path}";
|
||||
Restart = "always";
|
||||
RestartSec = 5;
|
||||
};
|
||||
script = ''
|
||||
umask 077
|
||||
yq eval-all '. as $i ireduce ({}; . * $i)' ${configFile} "$CREDENTIALS_DIRECTORY/server.yaml" \
|
||||
> "$RUNTIME_DIRECTORY/config.yaml"
|
||||
exec forgejo-runner daemon --config "$RUNTIME_DIRECTORY/config.yaml"
|
||||
'';
|
||||
};
|
||||
};
|
||||
container = {
|
||||
network = "bridge";
|
||||
privileged = false;
|
||||
docker_host = "-"; # its jobs get no container socket
|
||||
valid_volumes = [ ];
|
||||
force_pull = false;
|
||||
};
|
||||
};
|
||||
in
|
||||
{
|
||||
options.asxpio.runner.forgejoUrl = lib.mkOption {
|
||||
type = lib.types.str;
|
||||
default = "http://10.10.0.10:3000"; # over the private network, not through Traefik
|
||||
};
|
||||
|
||||
config = {
|
||||
# A new token re-registers the runner (the module compares its hash)
|
||||
sops.secrets."runner/token".restartUnits = [ "gitea-runner-asxpio.service" ];
|
||||
sops.secrets."runner/interop_token" = { };
|
||||
sops.templates."runner.env".content = ''
|
||||
TOKEN=${config.sops.placeholder."runner/token"}
|
||||
'';
|
||||
# The connection (URL, UUID, token) is merged into the config at
|
||||
# start; the UUID is not secret (interop's infra/runner.json)
|
||||
sops.templates."runner-interop-server.yaml".content = ''
|
||||
server:
|
||||
connections:
|
||||
interop:
|
||||
url: https://dev.another.im/
|
||||
uuid: dc326085-8420-4c33-8b88-a9ef46b3359b
|
||||
token: ${config.sops.placeholder."runner/interop_token"}
|
||||
'';
|
||||
|
||||
# The job cache server listens on a random port
|
||||
asxpio.security.ports = [ "tcp/*/.forgejo-runner" ];
|
||||
asxpio.security.containers."FORGEJO-ACTIONS-TASK-.*" = [ "docker-sock" ]; # docker_host: automount
|
||||
|
||||
services.gitea-actions-runner = {
|
||||
package = pkgs.forgejo-runner;
|
||||
instances.asxpio = {
|
||||
enable = true;
|
||||
name = config.networking.hostName;
|
||||
url = config.asxpio.runner.forgejoUrl;
|
||||
tokenFile = config.sops.templates."runner.env".path;
|
||||
asxpio = runner {
|
||||
name = "asxpio";
|
||||
description = "Forgejo Actions runner for git.asxp.io";
|
||||
tokenSecret = "runner/token";
|
||||
url = config.asxpio.runner.forgejoUrl;
|
||||
uuid = "a41810d7-48a3-4004-aeba-2148704e4e99"; # runner "asxpio-services"
|
||||
settings = {
|
||||
log = {
|
||||
level = "info";
|
||||
job_level = "info";
|
||||
};
|
||||
runner = {
|
||||
capacity = 4;
|
||||
timeout = "3h";
|
||||
shutdown_timeout = "3h";
|
||||
fetch_timeout = "5s";
|
||||
fetch_interval = "2s";
|
||||
report_interval = "1s";
|
||||
labels = [
|
||||
"ubuntu-latest:docker://node:20.20.2-bookworm"
|
||||
"ubuntu-22.04:docker://node:20.20.2-bookworm"
|
||||
|
|
@ -101,63 +119,68 @@ in
|
|||
"alpine-latest:docker://alpine:3.24.4"
|
||||
"nix-latest:docker://nixos/nix:${nixVersion}"
|
||||
];
|
||||
settings = {
|
||||
log = {
|
||||
level = "info";
|
||||
job_level = "info";
|
||||
};
|
||||
runner = {
|
||||
capacity = 4;
|
||||
timeout = "3h";
|
||||
shutdown_timeout = "3h";
|
||||
fetch_timeout = "5s";
|
||||
fetch_interval = "2s";
|
||||
report_interval = "1s";
|
||||
};
|
||||
cache.enabled = true;
|
||||
container = {
|
||||
privileged = false;
|
||||
options = "-v nix-store-${nixVersion}:/nix";
|
||||
valid_volumes = [ "**" ];
|
||||
docker_host = "automount"; # deploy jobs build and push images
|
||||
force_pull = false;
|
||||
};
|
||||
};
|
||||
};
|
||||
};
|
||||
|
||||
systemd.services.forgejo-runner-interop = {
|
||||
description = "Forgejo Actions runner for another-im/interop";
|
||||
wantedBy = [ "multi-user.target" ];
|
||||
after = [
|
||||
"network-online.target"
|
||||
"podman.socket"
|
||||
];
|
||||
wants = [
|
||||
"network-online.target"
|
||||
"podman.socket"
|
||||
];
|
||||
environment.DOCKER_HOST = "unix:///run/podman/podman.sock";
|
||||
path = [
|
||||
pkgs.forgejo-runner
|
||||
pkgs.yq-go
|
||||
];
|
||||
serviceConfig = {
|
||||
DynamicUser = true;
|
||||
SupplementaryGroups = [ "podman" ];
|
||||
StateDirectory = "forgejo-runner-interop";
|
||||
WorkingDirectory = "/var/lib/forgejo-runner-interop";
|
||||
RuntimeDirectory = "forgejo-runner-interop";
|
||||
LoadCredential = "server.yaml:${config.sops.templates."runner-interop-server.yaml".path}";
|
||||
Restart = "always";
|
||||
RestartSec = 5;
|
||||
cache.enabled = true;
|
||||
container = {
|
||||
privileged = false;
|
||||
options = "-v nix-store-${nixVersion}:/nix";
|
||||
valid_volumes = [ "**" ];
|
||||
docker_host = "automount"; # deploy jobs build and push images
|
||||
force_pull = false;
|
||||
};
|
||||
script = ''
|
||||
umask 077
|
||||
yq eval-all '. as $i ireduce ({}; . * $i)' ${interopConfig} "$CREDENTIALS_DIRECTORY/server.yaml" \
|
||||
> "$RUNTIME_DIRECTORY/config.yaml"
|
||||
exec forgejo-runner daemon --config "$RUNTIME_DIRECTORY/config.yaml"
|
||||
'';
|
||||
};
|
||||
};
|
||||
|
||||
interop = runner {
|
||||
name = "interop";
|
||||
description = "Forgejo Actions runner for another-im/interop";
|
||||
tokenSecret = "runner/interop_token";
|
||||
url = "https://dev.another.im/";
|
||||
uuid = "dc326085-8420-4c33-8b88-a9ef46b3359b"; # interop's infra/runner.json
|
||||
settings = {
|
||||
log = {
|
||||
level = "info";
|
||||
job_level = "info";
|
||||
};
|
||||
runner = {
|
||||
capacity = 3;
|
||||
timeout = "5h";
|
||||
shutdown_timeout = "5h";
|
||||
fetch_interval = "5s";
|
||||
envs.NIX_CONFIG = ''
|
||||
experimental-features = nix-command flakes
|
||||
build-users-group =
|
||||
sandbox = false
|
||||
'';
|
||||
labels = [
|
||||
"nix:docker://nixos/nix:${nixVersion}"
|
||||
"docker:docker://node:22.23.5-bookworm"
|
||||
"nix-host:docker://nixos/nix:${nixVersion}"
|
||||
];
|
||||
};
|
||||
container = {
|
||||
network = "bridge";
|
||||
privileged = false;
|
||||
docker_host = "-"; # its jobs get no container socket
|
||||
valid_volumes = [ ];
|
||||
force_pull = false;
|
||||
};
|
||||
};
|
||||
};
|
||||
in
|
||||
{
|
||||
options.asxpio.runner.forgejoUrl = lib.mkOption {
|
||||
type = lib.types.str;
|
||||
default = "http://10.10.0.10:3000"; # over the private network, not through Traefik
|
||||
};
|
||||
|
||||
config = lib.mkMerge [
|
||||
asxpio
|
||||
interop
|
||||
{
|
||||
# The job cache server listens on a random port
|
||||
asxpio.security.ports = [ "tcp/*/.forgejo-runner" ];
|
||||
asxpio.security.containers."FORGEJO-ACTIONS-TASK-.*" = [ "docker-sock" ]; # docker_host: automount
|
||||
}
|
||||
];
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue