From 4a51f3055c0bbf15d916af76f8aebe83bbf7b990 Mon Sep 17 00:00:00 2001 From: asepharyana Date: Mon, 10 Aug 2026 15:06:08 +0700 Subject: [PATCH] ci(deploy): push builds to attic binary cache (attic.asepharyana.my.id) --- .github/workflows/deploy.yml | 28 +++++++++++++++++++++++++++- 1 file changed, 27 insertions(+), 1 deletion(-) diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml index 9cf9789..784d117 100644 --- a/.github/workflows/deploy.yml +++ b/.github/workflows/deploy.yml @@ -107,13 +107,39 @@ 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://`. + # The attic client runs on the VPS (pre-built at + # /nix/store/fygyy3yk4rqdknxkiwkqambpnhyax0k4-attic-0.1.0, config in + # /root/.config/attic with server "imrnes-ts" → Tailscale 100.121.180.82). + - 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 }}" + # Copy closure to VPS (fast if attic already has it via substitute) + ssh "$VPS_USER@$VPS_HOST" "sudo /nix/var/nix/profiles/default/bin/nix-store --realise '$STORE_PATH'" 2>/dev/null \ + || nix copy --to "ssh://$VPS_USER@$VPS_HOST" "$STORE_PATH" + # Push from VPS → Attic over Tailscale (reliable for large payloads) + ssh "$VPS_USER@$VPS_HOST" "/nix/store/fygyy3yk4rqdknxkiwkqambpnhyax0k4-attic-0.1.0/bin/attic push imrnes-ts:gmw '$STORE_PATH' --jobs 4" \ + || echo "attic push failed (non-fatal; ssh copy fallback below)" + # 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'"