diff options
| author | toufic ar <contact@toufy.me> | 2026-07-14 17:24:08 +0300 |
|---|---|---|
| committer | toufic ar <contact@toufy.me> | 2026-07-14 17:24:08 +0300 |
| commit | 9e48032a7d7cea20d665bc6ab666a43e549af0f4 (patch) | |
| tree | 05293ae0c882c0dfd6ffb8880db82bcb06fee2ed | |
| parent | 95e86e7420dbe123a2d09039233af26a09f4c84a (diff) | |
| download | servers-9e48032a7d7cea20d665bc6ab666a43e549af0f4.tar.gz servers-9e48032a7d7cea20d665bc6ab666a43e549af0f4.zip | |
autopush docker :)
| -rw-r--r-- | adonis/autopush/default.nix | 206 | ||||
| -rw-r--r-- | aphrodite/devops/default.nix | 1 | ||||
| -rw-r--r-- | common/default.nix | 1 | ||||
| -rw-r--r-- | common/docker.nix (renamed from aphrodite/devops/docker.nix) | 2 |
4 files changed, 171 insertions, 39 deletions
diff --git a/adonis/autopush/default.nix b/adonis/autopush/default.nix index 7e5e45c..fd0d7e9 100644 --- a/adonis/autopush/default.nix +++ b/adonis/autopush/default.nix @@ -1,62 +1,194 @@ { config, pkgs, + lib, ... }: let domain = "push.${config.customOps.domain.fqdn}"; - port = 8082; - redisPort = 6369; - endpointPort = 443; - autopush = pkgs.autopush-rs; + connectPort = 8082; + endpointPort = 8080; in { sops.secrets = { "autopush/autoconnect" = {}; "autopush/autoendpoint" = {}; }; - environment.systemPackages = [autopush]; - services.redis.servers."autopush" = { - enable = true; - port = redisPort; + virtualisation.oci-containers.containers."autopush-autoconnect" = { + image = "compose2nix/autopush-autoconnect"; + environment = { + "AUTOCONNECT__DB_DSN" = "redis://redis"; + "AUTOCONNECT__ENDPOINT_HOSTNAME" = "updates.${domain}"; + "AUTOCONNECT__ENDPOINT_PORT" = "443"; + "AUTOCONNECT__ENDPOINT_SCHEME" = "https"; + "AUTOCONNECT__ROUTER_HOSTNAME" = "autoconnect"; + }; + environmentFiles = [ + config.sops.secrets."autopush/autoconnect".path + ]; + ports = [ + "8080:8080/tcp" + ]; + dependsOn = [ + "autopush-redis" + ]; + log-driver = "journald"; + extraOptions = [ + "--network-alias=autoconnect" + "--network=autopush_default" + ]; + }; + + systemd.services."docker-autopush-autoconnect" = { + serviceConfig = { + Restart = lib.mkOverride 90 "always"; + RestartMaxDelaySec = lib.mkOverride 90 "1m"; + RestartSec = lib.mkOverride 90 "100ms"; + RestartSteps = lib.mkOverride 90 9; + }; + after = [ + "docker-network-autopush_default.service" + ]; + requires = [ + "docker-network-autopush_default.service" + ]; + partOf = [ + "docker-compose-autopush-root.target" + ]; + wantedBy = [ + "docker-compose-autopush-root.target" + ]; + }; + + virtualisation.oci-containers.containers."autopush-autoend" = { + image = "compose2nix/autopush-autoend"; + environment = { + "AUTOEND__DB_DSN" = "redis://redis"; + "AUTOEND__ENDPOINT_URL" = "https://updates.${domain}"; + "AUTOEND__HOST" = "0.0.0.0"; + "AUTOEND__PORT" = "8082"; + }; + environmentFiles = [ + config.sops.secrets."autopush/autoendpoint".path + ]; + + ports = [ + "8082:8082/tcp" + ]; + dependsOn = [ + "autopush-autoconnect" + "autopush-redis" + ]; + log-driver = "journald"; + extraOptions = [ + "--network-alias=autoendpoint" + "--network=autopush_default" + ]; }; - systemd.services = { - autopush-autoconnect = { - environment = { - AUTOCONNECT__DB_DSN = "redis://127.0.0.1:${builtins.toString redisPort}"; - AUTOCONNECT__ENDPOINT_SCHEME = "https"; - AUTOCONNECT__ENDPOINT_HOSTNAME = "updates.${domain}"; - AUTOCONNECT__ENDPOINT_PORT = builtins.toString endpointPort; - AUTOCONNECT__ROUTER_HOSTNAME = "localhost"; - }; - wantedBy = ["multi-user.target"]; - serviceConfig = { - EnvironmentFile = config.sops.secrets."autopush/autoconnect".path; - ExecStart = "${autopush}/bin/autoconnect"; - }; + + systemd.services."docker-autopush-autoend" = { + serviceConfig = { + Restart = lib.mkOverride 90 "always"; + RestartMaxDelaySec = lib.mkOverride 90 "1m"; + RestartSec = lib.mkOverride 90 "100ms"; + RestartSteps = lib.mkOverride 90 9; }; - autopush-autoendpoint = { - environment = { - AUTOEND__DB_DSN = "redis://127.0.0.1:${builtins.toString redisPort}"; - AUTOEND__HOST = "127.0.0.1"; - AUTOEND__PORT = builtins.toString port; - AUTOEND__ENDPOINT_URL = "https://updates.${domain}"; - AUTOEND__HUMAN_LOGS = "true"; - }; - wantedBy = ["multi-user.target"]; - serviceConfig = { - EnvironmentFile = config.sops.secrets."autopush/autoendpoint".path; - ExecStart = "${autopush}/bin/autoendpoint"; - }; + after = [ + "docker-network-autopush_default.service" + ]; + requires = [ + "docker-network-autopush_default.service" + ]; + partOf = [ + "docker-compose-autopush-root.target" + ]; + wantedBy = [ + "docker-compose-autopush-root.target" + ]; + }; + + virtualisation.oci-containers.containers."autopush-redis" = { + image = "redis:latest"; + cmd = ["redis-server"]; + log-driver = "journald"; + extraOptions = [ + "--network-alias=redis" + "--network=autopush_default" + ]; + }; + + systemd.services."docker-autopush-redis" = { + serviceConfig = { + Restart = lib.mkOverride 90 "always"; + RestartMaxDelaySec = lib.mkOverride 90 "1m"; + RestartSec = lib.mkOverride 90 "100ms"; + RestartSteps = lib.mkOverride 90 9; }; + after = [ + "docker-network-autopush_default.service" + ]; + requires = [ + "docker-network-autopush_default.service" + ]; + partOf = [ + "docker-compose-autopush-root.target" + ]; + wantedBy = [ + "docker-compose-autopush-root.target" + ]; }; + + systemd.services."docker-network-autopush_default" = { + path = [pkgs.docker]; + serviceConfig = { + Type = "oneshot"; + RemainAfterExit = true; + ExecStop = "docker network rm -f autopush_default"; + }; + script = '' + docker network inspect autopush_default || docker network create autopush_default + ''; + partOf = ["docker-compose-autopush-root.target"]; + wantedBy = ["docker-compose-autopush-root.target"]; + }; + + systemd.services."docker-build-autopush-autoconnect" = { + path = [pkgs.docker pkgs.git]; + serviceConfig = { + Type = "oneshot"; + TimeoutSec = 300; + }; + script = '' + docker build -t compose2nix/autopush-autoconnect --build-arg BINARY=autoconnect --build-arg BUILD_ARGS=--no-default-features --features redis --build-arg CRATE=autoconnect https://github.com/mozilla-services/autopush-rs.git + ''; + }; + + systemd.services."docker-build-autopush-autoend" = { + path = [pkgs.docker pkgs.git]; + serviceConfig = { + Type = "oneshot"; + TimeoutSec = 300; + }; + script = '' + docker build -t compose2nix/autopush-autoend --build-arg BUILD_ARGS=--no-default-features --features redis --build-arg CRATE=autoendpoint --build-arg BINARY=autoendpoint https://github.com/mozilla-services/autopush-rs.git + ''; + }; + + systemd.targets."docker-compose-autopush-root" = { + unitConfig = { + Description = "Root target generated by compose2nix."; + }; + wantedBy = ["multi-user.target"]; + }; + services.nginx.virtualHosts.${domain} = { forceSSL = true; enableACME = true; - locations."/".proxyPass = "http://127.0.0.1:8080"; + locations."/".proxyPass = "http://127.0.0.1:${builtins.toString endpointPort}"; }; + services.nginx.virtualHosts."updates.${domain}" = { forceSSL = true; enableACME = true; - locations."/".proxyPass = "http://127.0.0.1:${builtins.toString port}"; + locations."/".proxyPass = "http://127.0.0.1:${builtins.toString connectPort}"; }; } diff --git a/aphrodite/devops/default.nix b/aphrodite/devops/default.nix index f4fae07..67d9059 100644 --- a/aphrodite/devops/default.nix +++ b/aphrodite/devops/default.nix @@ -1,6 +1,5 @@ { imports = [ - ./docker.nix ./git.nix ./msci.nix ]; diff --git a/common/default.nix b/common/default.nix index ed96c7a..0ba70a3 100644 --- a/common/default.nix +++ b/common/default.nix @@ -1,6 +1,7 @@ { imports = [ ./disks.nix + ./docker.nix ./fail2ban.nix ./git.nix ./hardware.nix diff --git a/aphrodite/devops/docker.nix b/common/docker.nix index cb53fcb..4dd9495 100644 --- a/aphrodite/devops/docker.nix +++ b/common/docker.nix @@ -5,8 +5,8 @@ virtualisation = { docker = { enable = true; - storageDriver = "btrfs"; autoPrune.enable = true; + storageDriver = "btrfs"; }; oci-containers.backend = "docker"; }; |
