Files
GMW/.gitea/workflows/deploy.yml
T
Developer 79b7694676
Build & Deploy (Nix) / build-and-deploy (backend) (push) Failing after 1m27s
Build & Deploy (Nix) / build-and-deploy (discord-gateway) (push) Failing after 2m29s
Build & Deploy (Nix) / build-and-deploy (proxy) (push) Failing after 2m24s
ci: set profile even without systemd unit
2026-07-30 17:05:44 +07:00

90 lines
2.9 KiB
YAML

name: Build & Deploy (Nix)
on:
push:
branches:
- main
jobs:
build-and-deploy:
runs-on: ubuntu-latest
strategy:
fail-fast: false
max-parallel: 1
matrix:
service: [backend, discord-gateway, proxy]
steps:
- name: Check out repository
run: |
git clone https://git.imrnes.team/MythEclipse/GMW.git .
git checkout ${{ github.sha }}
- name: Install Nix & Build ${{ matrix.service }}
run: |
set -eu
# Install Nix (container-safe: --init none, root-only mode)
curl -fsSL https://install.determinate.systems/nix \
| sh -s -- install linux --no-confirm --init none 2>&1
# Enable flakes
mkdir -p /etc/nix
echo "experimental-features = nix-command flakes" >> /etc/nix/nix.conf
. /nix/var/nix/profiles/default/etc/profile.d/nix-daemon.sh
# Build
nix build .#${{ matrix.service }} --impure --option sandbox false 2>&1
echo "$(readlink result)" > /tmp/gmw-store-path-${{ matrix.service }}
- name: Copy binary to target VPS & deploy ${{ matrix.service }}
env:
VPS_HOST: ${{ secrets.VPS_HOST }}
VPS_USER: ${{ secrets.VPS_USER }}
VPS_SSH_KEY_VALUE: ${{ secrets.VPS_SSH_KEY_VALUE }}
run: |
set -eu
. /nix/var/nix/profiles/default/etc/profile.d/nix-daemon.sh
SERVICE="${{ matrix.service }}"
STORE_PATH=$(cat "/tmp/gmw-store-path-$SERVICE")
echo "=== $SERVICE — Store path: $STORE_PATH"
key_file=$(mktemp /tmp/deploy-key.XXXXXX)
printf '%s\n' "$VPS_SSH_KEY_VALUE" > "$key_file"
chmod 600 "$key_file"
# Copy binary closure to target VPS via Nix SSH store
export NIX_SSHOPTS="-i $key_file -o StrictHostKeyChecking=no"
nix copy --to "ssh://${VPS_USER}@${VPS_HOST}" "$STORE_PATH" 2>&1
# Deploy: update profile + restart service
NIX_BIN="/nix/var/nix/profiles/default/bin"
PROFILE="/nix/var/nix/profiles/gmw-$SERVICE"
UNIT="gmw-$SERVICE"
ssh -i "$key_file" -o StrictHostKeyChecking=no \
"${VPS_USER}@${VPS_HOST}" "
# Remove stale profile dir if it exists as regular directory
if [ -d $PROFILE ] && [ ! -L $PROFILE ]; then
rm -rf $PROFILE
fi
export PATH=\$PATH:$NIX_BIN
nix-env --profile $PROFILE --set $STORE_PATH
if systemctl is-enabled --quiet $UNIT 2>/dev/null; then
systemctl daemon-reload
systemctl restart $UNIT
sleep 3
systemctl status $UNIT --no-pager 2>&1 | head -12
else
echo \"=== $UNIT: profile set, unit not yet created ==="
echo \"Run: nix-env --profile $PROFILE --set $STORE_PATH\"
echo \"Create: /etc/systemd/system/$UNIT.service\"
fi
" 2>&1