diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml index 9cf9789..bdbee7c 100644 --- a/.github/workflows/deploy.yml +++ b/.github/workflows/deploy.yml @@ -107,13 +107,35 @@ jobs: ssh-keygen -y -f ~/.ssh/id_ed25519 >/dev/null 2>&1 || { echo "SSH key invalid"; exit 1; } ssh-keyscan -H "$VPS_HOST" >> ~/.ssh/known_hosts 2>/dev/null + # Push build result to Attic binary cache (attic.asepharyana.my.id) so + # the VPS can substitute it instead of a single-stream `nix copy ssh://`. + - name: Push to Attic cache + env: + ATTIC_TOKEN: ${{ secrets.ATTIC_TOKEN }} + run: | + if [ -z "$ATTIC_TOKEN" ]; then + echo "ATTIC_TOKEN not set; skipping attic push" + exit 0 + fi + STORE_PATH="${{ steps.build.outputs.store-path }}" + # Install attic client (deterministic Nix build from flake) + nix build github:DeterminateSystems/attic#attic --option sandbox false --no-link --print-out-paths > /tmp/attic-path + ATTIC_BIN=$(cat /tmp/attic-path)/bin/attic + "$ATTIC_BIN" login asepharyana https://attic.asepharyana.my.id "$ATTIC_TOKEN" >/dev/null 2>&1 || true + "$ATTIC_BIN" push asepharyana:gmw "$STORE_PATH" --jobs 4 + # NOTE: env files /etc/gmw/backend.env & /etc/gmw/discord-gateway.env are # managed MANUALLY on the VPS (source of truth). CI only builds & deploys. - name: Deploy ${{ matrix.service }} to VPS run: | STORE_PATH="${{ steps.build.outputs.store-path }}" echo "=== Copying ${{ matrix.service }}: $STORE_PATH ===" - nix copy --to "ssh://$VPS_USER@$VPS_HOST" "$STORE_PATH" + if [ -n "${{ secrets.ATTIC_TOKEN }}" ] && ssh "$VPS_USER@$VPS_HOST" "sudo /nix/var/nix/profiles/default/bin/nix-store --realise '$STORE_PATH'" 2>/dev/null; then + echo "Substituted ${{ matrix.service }} from Attic cache" + else + echo "Attic substitute failed; falling back to ssh copy" + nix copy --to "ssh://$VPS_USER@$VPS_HOST" "$STORE_PATH" + fi echo "=== Updating profile ===" ssh "$VPS_USER@$VPS_HOST" "sudo /nix/var/nix/profiles/default/bin/nix-env --profile /nix/var/nix/profiles/gmw-${{ matrix.service }} --set '$STORE_PATH'"