try to move ci agent to a nixos container

This commit is contained in:
Cyryl Płotnicki 2022-12-21 12:54:55 +00:00
parent 0486fdbabb
commit e42f3c95c6

View file

@ -10,22 +10,38 @@
domain = "ci.cyplo.dev"; domain = "ci.cyplo.dev";
path = "/var/lib/woodpecker"; path = "/var/lib/woodpecker";
serverContainerName = "woodpecker-server"; serverContainerName = "woodpecker-server";
agent = { uid = 2061;
dependsOn = ["${serverContainerName}"]; gid = 3061;
volumes = ["/var/run/podman/podman.sock:/var/run/docker.sock"]; systemUserName = "woodpecker";
image = "woodpeckerci/woodpecker-agent@sha256:9a98e25ca6fcf7c437ad355cfce53a696c55b9864399a4d456429a20bfb44545"; systemGroupName = "woodpecker";
environmentFiles = ["${config.sops.secrets.gitea-env.path}"]; podmanGid = 994;
environment = { secretSettings = {
WOODPECKER_SERVER = "${serverContainerName}:${toString agentPort}"; owner = systemUserName;
WOODPECKER_MAX_PROCS = "1"; group = systemGroupName;
WOODPECKER_DEBUG_PRETTY = "true";
WOODPECKER_LOG_LEVEL = "info";
};
extraOptions = ["--network=woodpecker"];
}; };
woodpeckerEnvSecretName = "woodpecker-env";
woodpeckerEnvSecretPath = "/run/secrets/${woodpeckerEnvSecretName}";
in { in {
imports = [../nginx.nix]; imports = [../nginx.nix];
users = {
users."${systemUserName}" = {
inherit uid;
isSystemUser = true;
isNormalUser = false;
group = systemGroupName;
extraGroups = ["podman"];
};
groups."${systemGroupName}" = {
inherit gid;
members = ["${systemUserName}"];
};
groups."podman" = {
gid = podmanGid;
members = ["${systemUserName}"];
};
};
services.nginx = { services.nginx = {
virtualHosts = { virtualHosts = {
"${domain}" = { "${domain}" = {
@ -43,7 +59,19 @@ in {
format = "binary"; format = "binary";
}; };
virtualisation.podman.defaultNetwork.dnsname.enable = true; sops.secrets."woodpecker-env" =
{
sopsFile = ./gitea.sops;
format = "binary";
path = woodpeckerEnvSecretPath;
}
// secretSettings;
virtualisation.podman = {
enable = true;
defaultNetwork.dnsname.enable = true;
};
networking.firewall.allowedTCPPorts = [agentPort];
virtualisation.oci-containers.containers = { virtualisation.oci-containers.containers = {
"${serverContainerName}" = { "${serverContainerName}" = {
image = "woodpeckerci/woodpecker-server@sha256:e6027e46a782d50790183b7274a2a2ad3a6c6fb9a645e6af81a16419613c28ea"; image = "woodpeckerci/woodpecker-server@sha256:e6027e46a782d50790183b7274a2a2ad3a6c6fb9a645e6af81a16419613c28ea";
@ -56,12 +84,69 @@ in {
WOODPECKER_GITEA = "true"; WOODPECKER_GITEA = "true";
WOODPECKER_GITEA_URL = "https://git.cyplo.dev"; WOODPECKER_GITEA_URL = "https://git.cyplo.dev";
}; };
ports = ["${toString httpPort}:${toString httpPort}"]; ports = [
extraOptions = ["--network=woodpecker"]; "${toString httpPort}:${toString httpPort}"
"${toString agentPort}:${toString agentPort}"
];
};
};
containers.woodpecker-agent1 = {
autoStart = true;
forwardPorts = [
];
bindMounts = {
"${woodpeckerEnvSecretPath}" = {
hostPath = "${woodpeckerEnvSecretPath}";
isReadOnly = true;
};
"/var/run/docker.sock" = {
hostPath = "/var/run/podman/podman.sock";
isReadOnly = false;
};
};
config = {
config,
pkgs,
lib,
...
}: {
system.stateVersion = "22.11";
users = {
mutableUsers = false;
allowNoPasswordLogin = true;
users."${systemUserName}" = {
inherit uid;
isSystemUser = true;
isNormalUser = false;
group = systemGroupName;
};
groups."${systemGroupName}" = {
inherit gid;
members = ["${systemUserName}"];
};
groups."podman" = {
gid = podmanGid;
members = ["${systemUserName}"];
};
};
systemd.services.woodpecker-agent = {
wantedBy = ["multi-user.target"];
environment = {
WOODPECKER_SERVER = "${domain}:${toString agentPort}";
WOODPECKER_MAX_PROCS = "1";
WOODPECKER_DEBUG_PRETTY = "true";
WOODPECKER_LOG_LEVEL = "info";
};
serviceConfig = {
EnvironmentFile = [
woodpeckerEnvSecretPath
];
ExecStart = "${pkgs.woodpecker-agent}/bin/woodpecker-agent";
User = systemUserName;
Group = systemGroupName;
};
};
}; };
woodpecker-agent1 = agent;
woodpecker-agent2 = agent;
woodpecker-agent3 = agent;
woodpecker-agent4 = agent;
}; };
} }