ci(deploy): push builds to attic binary cache (attic.asepharyana.my.id)
This commit is contained in:
@@ -107,13 +107,39 @@ jobs:
|
|||||||
ssh-keygen -y -f ~/.ssh/id_ed25519 >/dev/null 2>&1 || { echo "SSH key invalid"; exit 1; }
|
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
|
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
|
# 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.
|
# managed MANUALLY on the VPS (source of truth). CI only builds & deploys.
|
||||||
- name: Deploy ${{ matrix.service }} to VPS
|
- name: Deploy ${{ matrix.service }} to VPS
|
||||||
run: |
|
run: |
|
||||||
STORE_PATH="${{ steps.build.outputs.store-path }}"
|
STORE_PATH="${{ steps.build.outputs.store-path }}"
|
||||||
echo "=== Copying ${{ matrix.service }}: $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 ==="
|
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'"
|
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'"
|
||||||
|
|||||||
Reference in New Issue
Block a user