Site without podman

This commit is contained in:
mewp 2025-02-10 00:34:21 +00:00
parent 79da8e0b1a
commit d545cae892

View file

@ -7,39 +7,51 @@ let
vendorHash = "sha256-H8Wa1GoXjU8mkaE0ofdA1mO+rNo3l4s0nxTVih9LuWs="; vendorHash = "sha256-H8Wa1GoXjU8mkaE0ofdA1mO+rNo3l4s0nxTVih9LuWs=";
}; };
buildScript = ''
rev=$(git ls-remote https://git.orga.cebula.camp/infra/site | grep refs/heads/nix | cut -f1)
pkg=$(nix-build -I nixpkgs=${pkgs.path} --no-out-link -E 'import (builtins.fetchGit { url = "https://git.orga.cebula.camp/infra/site"; rev="'$rev'"; })')
'';
in { in {
virtualisation.podman.enable = true;
virtualisation.oci-containers.backend = "podman";
virtualisation.oci-containers.containers = {
site = {
image = "git.orga.cebula.camp/infra/site:golden";
ports = [ "10.88.0.1:9001:3000" ];
};
};
services.nginx.virtualHosts."cebula.camp" = { services.nginx.virtualHosts."cebula.camp" = {
forceSSL = true; forceSSL = true;
enableACME = true; enableACME = true;
locations."/" = { locations."/" = {
proxyPass = "http://10.88.0.1:9001/"; proxyPass = "http://localhost:3000/";
proxyWebsockets = true; proxyWebsockets = true;
}; };
}; locations."/.not-well-known/update" = {
systemd.timers.site-autodeploy = { proxyPass = "http://unix:/run/site-autodeploy.sock";
wantedBy = [ "timers.target" ]; extraConfig = ''
timerConfig = { proxy_http_version 1.0;
OnBootSec = "5m"; '';
OnUnitActiveSec = "5m";
Unit = "site-autodeploy.service";
}; };
}; };
systemd.services.site-autodeploy = { systemd.sockets.site-autodeploy = {
path = [ pkgs.podman pkgs.bash ]; wantedBy = [ "sockets.target" ];
socketConfig = {
ListenStream = "/run/site-autodeploy.sock";
SocketMode = "0600";
SocketUser = config.services.nginx.user;
Accept = true;
MaxConnections=1;
};
};
systemd.services."site-autodeploy@" = {
path = [ pkgs.git pkgs.nix pkgs.bash pkgs.systemd ];
script = '' script = ''
set -eu set -eu
${autodeploy}/bin/autodeploy \ rev=$(git ls-remote https://git.orga.cebula.camp/infra/site | grep refs/heads/nix | cut -f1)
-local_checkout /root/site-ci \ if [ -n "$(nix-build --dry-run -I nixpkgs=${pkgs.path} -E 'import (builtins.fetchGit { url = "https://git.orga.cebula.camp/infra/site"; rev="'$rev'"; })' 2>&1)" ]; then
-trigger "systemctl restart podman-site" echo -e "HTTP/1.0 200 Ok\r\n\r\n\r\n"
${buildScript}
systemctl restart cebula-site
else
echo -e "HTTP/1.0 304 Not Modified\r\nContent-Length: 0\r\n\r\n"
fi
''; '';
unitConfig = {
CollectMode="inactive-or-failed";
};
serviceConfig = { serviceConfig = {
Type = "oneshot"; Type = "oneshot";
# TODO: run as an unprivileged user: # TODO: run as an unprivileged user:
@ -47,6 +59,15 @@ in {
# subuid/subgid maps with LDAP. # subuid/subgid maps with LDAP.
# 2. let the unprivileged user sudo into a systemctl unit restart # 2. let the unprivileged user sudo into a systemctl unit restart
User = "root"; User = "root";
StandardOutput = "socket";
}; };
}; };
systemd.services.cebula-site = {
wantedBy = [ "multi-user.target" ];
path = [ pkgs.git pkgs.nix pkgs.bash ];
script = ''
${buildScript}
exec $pkg/bin/cebula-site
'';
};
} }