All checks were successful
Deploy to Server / deploy (push) Successful in 18s
67 lines
2.3 KiB
YAML
67 lines
2.3 KiB
YAML
name: Deploy to Server
|
|
|
|
on:
|
|
push:
|
|
branches:
|
|
- main
|
|
|
|
jobs:
|
|
deploy:
|
|
runs-on: ubuntu-latest # Gitea runner label
|
|
container:
|
|
image: alpine:latest # Alpine to keep CPU/memory low
|
|
steps:
|
|
- name: Install SSH and Networking Tools
|
|
# 'apk add' is the Alpine equivalent of 'apt-get install'
|
|
run: apk add --no-cache openssh-client iproute2 git
|
|
|
|
- name: Configure SSH Key
|
|
run: |
|
|
mkdir -p ~/.ssh
|
|
# Gitea uses ${{ secrets.SECRET_NAME }} syntax
|
|
echo "${{ secrets.DEPLOY_SSH_KEY }}" > ~/.ssh/id_rsa
|
|
chmod 600 ~/.ssh/id_rsa
|
|
echo "StrictHostKeyChecking no" > ~/.ssh/config
|
|
|
|
- name: Execute Remote Deployment
|
|
run: |
|
|
# 1. Find the host machine's IP via the docker bridge gateway
|
|
HOST_IP=$(ip route | awk '/default/ { print $3 }')
|
|
echo "==> Detected Host IP: $HOST_IP"
|
|
|
|
# 2. SSH into the host to execute the deployment safely
|
|
ssh adipu@$HOST_IP << 'EOF'
|
|
# Exit immediately if any command fails
|
|
set -e
|
|
|
|
echo "==> Navigating to project directory..."
|
|
cd ~/blinds_express
|
|
|
|
echo "==> Pulling latest code..."
|
|
git pull origin main
|
|
|
|
echo "==> Updating Node version for Docker..."
|
|
NODE_VER=$(cat .node-version)
|
|
# Ensure a trailing newline exists before appending
|
|
echo "" >> .env
|
|
sed -i '/^NODE_VERSION=/d' .env || true
|
|
echo "NODE_VERSION=${NODE_VER}-alpine" >> .env
|
|
|
|
echo "==> Running Build..."
|
|
# If this build fails, 'set -e' aborts the script instantly.
|
|
# Existing containers will NOT be touched, keeping the API up.
|
|
docker compose build
|
|
|
|
echo "==> Build successful! Deploying new containers..."
|
|
# This only runs if the build was 100% successful.
|
|
# `up -d` recreates only the services whose image/config changed,
|
|
# and the backend's CMD applies db/schema.sql before starting,
|
|
# so the schema stays current on every push.
|
|
docker compose up -d
|
|
|
|
echo "==> Cleaning up old images to save disk space..."
|
|
docker image prune -f
|
|
|
|
echo "==> Deployment Complete!"
|
|
EOF
|