diff --git a/.gitlab-ci-build.yml.in b/.gitlab-ci-build.yml.in index 60ffece..aa785a8 100644 --- a/.gitlab-ci-build.yml.in +++ b/.gitlab-ci-build.yml.in @@ -40,13 +40,7 @@ stages: ${EXCEPT} sources before_script: - - packer init sources - - echo $COMMAND - - mc alias set storage "http://localhost:9000" root "$MINIO_SECRET" - - mc ls storage/isos/cache - - file=$(echo var.iso.url | packer console -var-file="${distro}" -config-type=hcl2 sources/) - - mkdir cache - - mc get "storage/isos/$file" "$file" + - nix run ".#cache-restore" script: - ls -l cache/ - echo $COMMAND > build.sh diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 3ac06e3..5b989d1 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -72,6 +72,7 @@ downloads: paths: - ./packer_config/ script: + - nix run ".#cache-restore" - nix run ".#cache" trigger: diff --git a/cache-restore.sh b/cache-restore.sh new file mode 100644 index 0000000..0d25425 --- /dev/null +++ b/cache-restore.sh @@ -0,0 +1,5 @@ +mc alias set storage "$STORAGE_URL" root "$MINIO_SECRET" + +for f in $(mc ls --json storage/isos/cache | jq '.key' | tr -d '"'); do + mc get -q "storage/isos/cache/$f" "./cache/$f" +done diff --git a/flake.nix b/flake.nix index 463cf16..e31c605 100644 --- a/flake.nix +++ b/flake.nix @@ -53,6 +53,15 @@ ]; text = builtins.readFile ./cache.sh; }; + cache-restore = pkgs.writeShellApplication { + name = "cache-restore"; + runtimeInputs = with pkgs; [ + jq + minio-client + packer + ]; + text = builtins.readFile ./cache-restore.sh; + }; }; # https://numtide.github.io/treefmt/