From 9f2165abc88e8a82125fb57c9ebd17c63f9bfd0f Mon Sep 17 00:00:00 2001 From: sinavir Date: Fri, 12 Apr 2024 19:53:02 +0200 Subject: [PATCH] feat(ci): Cache CI results --- .forgejo/workflows/eval.yaml | 18 ++++++++++++++++++ default.nix | 1 + machines/storage01/atticd.nix | 2 +- scripts/cache.sh | 12 ++++++++++++ scripts/default.nix | 3 +++ scripts/push-to-cache.sh | 13 +++++++++++++ 6 files changed, 48 insertions(+), 1 deletion(-) create mode 100755 scripts/cache.sh create mode 100755 scripts/push-to-cache.sh diff --git a/.forgejo/workflows/eval.yaml b/.forgejo/workflows/eval.yaml index b5cbf0a..d1628b4 100644 --- a/.forgejo/workflows/eval.yaml +++ b/.forgejo/workflows/eval.yaml @@ -68,3 +68,21 @@ jobs: run: | # Enter the shell nix-shell --run 'colmena build --on rescue01' + + push_to_cache: + runs-on: nix + needs: + - build_compute01 + - build_storage01 + - build_vault01 + - build_web01 + - build_web02 + - build_rescue01 + steps: + - uses: actions/checkout@v3 + + - name: Push to cache + run: nix-shell --run push-to-cache + env: + ATTIC_ENDPOINT: "https://cachix.dgnum.eu" + ATTIC_TOKEN: ${{ secrets.ATTIC_TOKEN }} diff --git a/default.nix b/default.nix index 44d2c02..d04dfad 100644 --- a/default.nix +++ b/default.nix @@ -76,6 +76,7 @@ in [ npins nixos-generators + attic-client ] ++ (builtins.map (p: callPackage p { }) [ (sources.disko + "/package.nix") diff --git a/machines/storage01/atticd.nix b/machines/storage01/atticd.nix index 61a5b94..0bc6897 100644 --- a/machines/storage01/atticd.nix +++ b/machines/storage01/atticd.nix @@ -58,7 +58,7 @@ in proxyPass = "http://127.0.0.1:9090"; extraConfig = '' - client_max_body_size 700M; + client_max_body_size 10G; ''; }; }; diff --git a/scripts/cache.sh b/scripts/cache.sh new file mode 100755 index 0000000..503a7e9 --- /dev/null +++ b/scripts/cache.sh @@ -0,0 +1,12 @@ +ENDPOINT=${ATTIC_ENDPOINT:-https://cachix.dgnum.eu} + +if [ "$1" == "off" ]; then + echo "Please edit $XDG_CONFIG_DIRS/nix/nix.conf to remove the cache" +elif [ "$1" == "on" ]; then + @attic@/bin/attic login dgnum "$ENDPOINT" + @attic@/bin/attic use dgnum:infra +else + echo "Help:" + echo " cache {on|off}" +fi + diff --git a/scripts/default.nix b/scripts/default.nix index c349792..84945a0 100644 --- a/scripts/default.nix +++ b/scripts/default.nix @@ -10,6 +10,7 @@ let git jq ; + attic = pkgs.attic-client; }; mkShellScript = @@ -32,6 +33,8 @@ let "check-deployment" "launch-vm" "list-nodes" + "push-to-cache" + "cache" ]; in diff --git a/scripts/push-to-cache.sh b/scripts/push-to-cache.sh new file mode 100755 index 0000000..b6d1ae3 --- /dev/null +++ b/scripts/push-to-cache.sh @@ -0,0 +1,13 @@ +set -e +set -u +set -o pipefail + +ENDPOINT=${ATTIC_ENDPOINT:-https://cachix.dgnum.eu} + +@attic@/bin/attic login dgnum "$ENDPOINT" "$ATTIC_TOKEN" + +@colmena@/bin/colmena eval -E '{ nodes, lib, ... }: lib.mapAttrsToList (_: v: v.config.system.build.toplevel.drvPath) nodes' |\ +@jq@/bin/jq -r '.[]' |\ +xargs nix-store -q -R --include-outputs |\ +sed '/\.drv$/d' |\ +xargs @attic@/bin/attic push dgnum:infra