ci: migrate CI to GitHub Actions (deploy nix + mirror ke Gitea backup)
Mirror to Gitea / mirror (push) Successful in 26s
Build & Deploy (Nix) / build-and-deploy (backend) (push) Failing after 32m40s
Build & Deploy (Nix) / build-and-deploy (proxy) (push) Failing after 18m0s
Build & Deploy (Nix) / build-and-deploy (discord-gateway) (push) Failing after 18m0s
Mirror to Gitea / mirror (push) Successful in 26s
Build & Deploy (Nix) / build-and-deploy (backend) (push) Failing after 32m40s
Build & Deploy (Nix) / build-and-deploy (proxy) (push) Failing after 18m0s
Build & Deploy (Nix) / build-and-deploy (discord-gateway) (push) Failing after 18m0s
This commit is contained in:
@@ -1,98 +0,0 @@
|
||||
name: Build & Deploy (Nix)
|
||||
|
||||
on:
|
||||
push:
|
||||
branches:
|
||||
- main
|
||||
|
||||
jobs:
|
||||
build-and-deploy:
|
||||
runs-on: ubuntu-latest
|
||||
|
||||
strategy:
|
||||
fail-fast: false
|
||||
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: Build & Deploy ${{ matrix.service }}
|
||||
env:
|
||||
VPS_HOST: ${{ secrets.VPS_HOST }}
|
||||
VPS_USER: ${{ secrets.VPS_USER }}
|
||||
VPS_SSH_KEY: ${{ secrets.VPS_SSH_KEY }}
|
||||
# Declarative env: source of truth = Gitea secrets, CI writes the
|
||||
# service env files on the VPS. Update env by editing the secret,
|
||||
# never by SSH-ing into the VPS by hand.
|
||||
BACKEND_ENV: ${{ secrets.BACKEND_ENV }}
|
||||
GATEWAY_ENV: ${{ secrets.GATEWAY_ENV }}
|
||||
run: |
|
||||
set -eu
|
||||
|
||||
# --- Install Nix & Build ---
|
||||
curl -fsSL https://install.determinate.systems/nix \
|
||||
| sh -s -- install linux --no-confirm --init none 2>&1
|
||||
|
||||
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
|
||||
|
||||
SERVICE="${{ matrix.service }}"
|
||||
echo "=== Building: $SERVICE ==="
|
||||
nix build ".#$SERVICE" --impure --option sandbox false 2>&1
|
||||
|
||||
STORE_PATH=$(readlink result)
|
||||
echo "=== Store path: $STORE_PATH"
|
||||
|
||||
# --- Deploy ---
|
||||
NIX_BIN="/nix/var/nix/profiles/default/bin"
|
||||
PROFILE="/nix/var/nix/profiles/gmw-$SERVICE"
|
||||
|
||||
key_file=$(mktemp /tmp/deploy-key.XXXXXX)
|
||||
printf '%s\n' "$VPS_SSH_KEY" > "$key_file"
|
||||
chmod 600 "$key_file"
|
||||
|
||||
export NIX_SSHOPTS="-i $key_file -o StrictHostKeyChecking=no"
|
||||
nix copy --to "ssh://${VPS_USER}@${VPS_HOST}" "$STORE_PATH" 2>&1
|
||||
|
||||
# --- Deploy env (declarative, from Gitea secrets) ---
|
||||
ENV_TARGET=""
|
||||
ENV_VALUE=""
|
||||
case "$SERVICE" in
|
||||
backend) ENV_TARGET="/etc/gmw/backend.env"; ENV_VALUE="$BACKEND_ENV" ;;
|
||||
discord-gateway) ENV_TARGET="/etc/gmw/discord-gateway.env"; ENV_VALUE="$GATEWAY_ENV" ;;
|
||||
proxy) ;; # nginx proxy has no env file
|
||||
esac
|
||||
|
||||
if [ -n "$ENV_VALUE" ] && [ -n "$ENV_TARGET" ]; then
|
||||
echo "=== Deploying env: $ENV_TARGET ==="
|
||||
printf '%s\n' "$ENV_VALUE" | ssh -i "$key_file" -o StrictHostKeyChecking=no \
|
||||
"${VPS_USER}@${VPS_HOST}" "
|
||||
set -eu
|
||||
mkdir -p /etc/gmw
|
||||
cat > $ENV_TARGET
|
||||
chown gmw:gmw $ENV_TARGET
|
||||
chmod 600 $ENV_TARGET
|
||||
echo \"env file lines: \$(grep -c '=' $ENV_TARGET)\"
|
||||
"
|
||||
else
|
||||
echo "=== No env secret for $SERVICE — skipping env deploy ==="
|
||||
fi
|
||||
|
||||
ssh -i "$key_file" -o StrictHostKeyChecking=no \
|
||||
"${VPS_USER}@${VPS_HOST}" "
|
||||
if [ -d $PROFILE ] && [ ! -L $PROFILE ]; then
|
||||
rm -rf $PROFILE
|
||||
fi
|
||||
export PATH=\$PATH:$NIX_BIN
|
||||
nix-env --profile $PROFILE --set $STORE_PATH
|
||||
systemctl daemon-reload
|
||||
systemctl restart gmw-$SERVICE
|
||||
sleep 3
|
||||
systemctl status gmw-$SERVICE --no-pager 2>&1 | head -12
|
||||
" 2>&1
|
||||
@@ -0,0 +1,76 @@
|
||||
name: Build & Deploy (Nix)
|
||||
|
||||
on:
|
||||
push:
|
||||
branches: [main]
|
||||
workflow_dispatch:
|
||||
|
||||
concurrency:
|
||||
group: gmw-deploy
|
||||
cancel-in-progress: false
|
||||
|
||||
permissions:
|
||||
contents: read
|
||||
|
||||
env:
|
||||
VPS_HOST: ${{ secrets.VPS_HOST }}
|
||||
VPS_USER: ${{ secrets.VPS_USER }}
|
||||
|
||||
jobs:
|
||||
build-and-deploy:
|
||||
runs-on: ubuntu-latest
|
||||
strategy:
|
||||
fail-fast: false
|
||||
matrix:
|
||||
service: [backend, discord-gateway, proxy]
|
||||
steps:
|
||||
- name: Checkout
|
||||
uses: actions/checkout@v7
|
||||
with:
|
||||
fetch-depth: 0
|
||||
submodules: false
|
||||
|
||||
- name: Install Nix
|
||||
uses: DeterminateSystems/nix-installer-action@v22
|
||||
with:
|
||||
determinate: false
|
||||
extra-conf: |
|
||||
sandbox = false
|
||||
accept-flake-config = true
|
||||
|
||||
- name: Cache Nix
|
||||
uses: DeterminateSystems/magic-nix-cache-action@v14
|
||||
|
||||
- name: Build ${{ matrix.service }}
|
||||
id: build
|
||||
run: |
|
||||
nix build .#${{ matrix.service }} --impure --option sandbox false --print-build-logs
|
||||
STORE_PATH=$(readlink result)
|
||||
echo "store-path=$STORE_PATH" >> "$GITHUB_OUTPUT"
|
||||
echo "Build OK ${{ matrix.service }}: $STORE_PATH"
|
||||
|
||||
- name: Setup SSH key
|
||||
env:
|
||||
SSH_KEY: ${{ secrets.SSH_PRIVATE_KEY }}
|
||||
run: |
|
||||
mkdir -p ~/.ssh
|
||||
echo "$SSH_KEY" > ~/.ssh/id_ed25519
|
||||
chmod 600 ~/.ssh/id_ed25519
|
||||
sed -i 's/\r$//' ~/.ssh/id_ed25519
|
||||
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
|
||||
|
||||
# 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"
|
||||
|
||||
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'"
|
||||
|
||||
echo "=== Restarting service ==="
|
||||
ssh "$VPS_USER@$VPS_HOST" "sudo systemctl daemon-reload && sudo systemctl restart gmw-${{ matrix.service }} && sleep 3 && sudo systemctl is-active gmw-${{ matrix.service }}"
|
||||
echo "✅ gmw-${{ matrix.service }} deployed"
|
||||
@@ -0,0 +1,26 @@
|
||||
name: Mirror to Gitea
|
||||
|
||||
on:
|
||||
push:
|
||||
branches: [main, master]
|
||||
workflow_dispatch:
|
||||
|
||||
permissions:
|
||||
contents: write
|
||||
|
||||
jobs:
|
||||
mirror:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- name: Checkout
|
||||
uses: actions/checkout@v7
|
||||
with:
|
||||
fetch-depth: 0
|
||||
|
||||
- name: Mirror to Gitea
|
||||
env:
|
||||
GITEA_TOKEN: ${{ secrets.GITEA_TOKEN }}
|
||||
run: |
|
||||
git remote add gitea "https://oauth2:${GITEA_TOKEN}@git.imrnes.team/MythEclipse/GMW.git"
|
||||
git push --mirror gitea
|
||||
echo "✅ Mirrored to Gitea (MythEclipse/GMW)"
|
||||
Reference in New Issue
Block a user