From 9e48032a7d7cea20d665bc6ab666a43e549af0f4 Mon Sep 17 00:00:00 2001 From: toufic ar Date: Tue, 14 Jul 2026 17:24:08 +0300 Subject: autopush docker :) --- adonis/autopush/default.nix | 210 +++++++++++++++++++++++++++++++++++-------- aphrodite/devops/default.nix | 1 - aphrodite/devops/docker.nix | 13 --- common/default.nix | 1 + common/docker.nix | 13 +++ 5 files changed, 185 insertions(+), 53 deletions(-) delete mode 100644 aphrodite/devops/docker.nix create mode 100644 common/docker.nix 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; - }; - 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"; - }; - }; - 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"; - }; + 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."docker-autopush-autoend" = { + 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-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/aphrodite/devops/docker.nix b/aphrodite/devops/docker.nix deleted file mode 100644 index cb53fcb..0000000 --- a/aphrodite/devops/docker.nix +++ /dev/null @@ -1,13 +0,0 @@ -{pkgs, ...}: { - environment.systemPackages = with pkgs; [ - docker-compose - ]; - virtualisation = { - docker = { - enable = true; - storageDriver = "btrfs"; - autoPrune.enable = true; - }; - oci-containers.backend = "docker"; - }; -} 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/common/docker.nix b/common/docker.nix new file mode 100644 index 0000000..4dd9495 --- /dev/null +++ b/common/docker.nix @@ -0,0 +1,13 @@ +{pkgs, ...}: { + environment.systemPackages = with pkgs; [ + docker-compose + ]; + virtualisation = { + docker = { + enable = true; + autoPrune.enable = true; + storageDriver = "btrfs"; + }; + oci-containers.backend = "docker"; + }; +} -- cgit v1.3.1