diff --git a/.forgejo/workflows/build-static-server.yaml b/.forgejo/workflows/build-static-server.yaml index 30e9084..140dc49 100644 --- a/.forgejo/workflows/build-static-server.yaml +++ b/.forgejo/workflows/build-static-server.yaml @@ -21,6 +21,16 @@ jobs: - name: Build static-server image run: nix build ./deploy-static-site/images#staticServer --out-link result-static-server + - name: Push Nix closure to S3 cache + if: env.NIX_SIGNING_KEY != '' + uses: https://git.toph.so/toph/ci-actions/push-nix-cache@main + with: + store-path: ./result-static-server + env: + AWS_ACCESS_KEY_ID: ${{ secrets.S3_ACCESS_KEY }} + AWS_SECRET_ACCESS_KEY: ${{ secrets.S3_SECRET_KEY }} + NIX_SIGNING_KEY: ${{ secrets.NIX_SIGNING_KEY }} + - name: Push to registry run: | nix shell nixpkgs#skopeo -c skopeo copy \ diff --git a/deploy-static-site/action.yaml b/deploy-static-site/action.yaml index 05a781f..3459fc9 100644 --- a/deploy-static-site/action.yaml +++ b/deploy-static-site/action.yaml @@ -57,14 +57,11 @@ runs: - name: Sign and push Nix closure to S3 cache if: env.NIX_SIGNING_KEY != '' - shell: bash - run: | - echo "${NIX_SIGNING_KEY}" > /tmp/nix-key - nix store sign -k /tmp/nix-key --recursive ./result-site - nix copy \ - --to "s3://${{ inputs.s3-bucket }}?endpoint=${{ inputs.s3-endpoint }}&access-key-id=${AWS_ACCESS_KEY_ID}&secret-access-key=${AWS_SECRET_ACCESS_KEY}" \ - ./result-site - rm /tmp/nix-key + uses: https://git.toph.so/toph/ci-actions/push-nix-cache@main + with: + store-path: ./result-site + s3-endpoint: ${{ inputs.s3-endpoint }} + s3-bucket: ${{ inputs.s3-bucket }} - name: Upload site tarball to S3 shell: bash diff --git a/push-nix-cache/action.yaml b/push-nix-cache/action.yaml new file mode 100644 index 0000000..62601e3 --- /dev/null +++ b/push-nix-cache/action.yaml @@ -0,0 +1,32 @@ +name: Push Nix Cache +description: Sign a Nix store path and push it to the S3 binary cache + +# Required env vars: AWS_ACCESS_KEY_ID, AWS_SECRET_ACCESS_KEY, NIX_SIGNING_KEY + +inputs: + store-path: + description: 'Path to the Nix store symlink or derivation to push (e.g. ./result)' + required: true + + s3-endpoint: + description: 'S3 endpoint URL' + required: false + default: 'https://s3.toph.so' + + s3-bucket: + description: 'S3 bucket used as the Nix binary cache' + required: false + default: 'nix-cache' + +runs: + using: composite + steps: + - name: Sign and push Nix closure + shell: bash + run: | + echo "${NIX_SIGNING_KEY}" > /tmp/nix-key + nix store sign -k /tmp/nix-key --recursive "${{ inputs.store-path }}" + nix copy \ + --to "s3://${{ inputs.s3-bucket }}?endpoint=${{ inputs.s3-endpoint }}&access-key-id=${AWS_ACCESS_KEY_ID}&secret-access-key=${AWS_SECRET_ACCESS_KEY}" \ + "${{ inputs.store-path }}" + rm /tmp/nix-key