Files
Lumina-MSK/.gitea/workflows/deploy-cd-server.yaml
DatTT127 e3b6989af8
Some checks failed
Deploy CD Server / deploy (push) Failing after 1m36s
update
2026-07-19 18:35:37 +07:00

93 lines
3.2 KiB
YAML

name: Deploy CD Server
on:
push:
# paths:
# - 'workspace/sprint_1_2/CODEBASE/deps/implementation/CD_server/**'
jobs:
deploy:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4
with:
fetch-depth: 1
- name: Prepare VM directories
uses: appleboy/ssh-action@v1.0.3
with:
host: ${{ vars.LIGHTSAIL_DEPLOY_HOST }}
username: ${{ secrets.LIGHTSAIL_USERNAME }}
key: ${{ secrets.LIGHTSAIL_SSH_KEY }}
port: ${{ vars.LIGHTSAIL_PORT }}
script: |
set -euo pipefail
DEPLOY_DIR="/opt/cd-server"
sudo mkdir -p "$DEPLOY_DIR"
sudo chown $USER:$USER "$DEPLOY_DIR"
sudo chmod 755 "$DEPLOY_DIR"
echo "[prepare] $DEPLOY_DIR ready"
- name: Copy CD server code to VM
uses: appleboy/scp-action@v0.1.7
with:
host: ${{ vars.LIGHTSAIL_DEPLOY_HOST }}
username: ${{ secrets.LIGHTSAIL_USERNAME }}
key: ${{ secrets.LIGHTSAIL_SSH_KEY }}
port: ${{ vars.LIGHTSAIL_PORT }}
source: "workspace/sprint_1_2/CODEBASE/deps/implementation/CD_server/"
target: "/opt/cd-server/"
strip_components: 6
- name: Deploy to Lightsail VM
uses: appleboy/ssh-action@v1.0.3
with:
host: ${{ vars.LIGHTSAIL_DEPLOY_HOST }}
username: ${{ secrets.LIGHTSAIL_USERNAME }}
key: ${{ secrets.LIGHTSAIL_SSH_KEY }}
port: ${{ vars.LIGHTSAIL_PORT }}
script: |
set -euo pipefail
DEPLOY_DIR="/opt/cd-server"
SERVICE_NAME="cd-server"
echo "[deploy] Creating deploy user if missing"
if ! id -u deploy &>/dev/null; then
sudo useradd -m -s /bin/bash deploy
fi
echo "[deploy] Adding deploy user to docker group"
sudo usermod -aG docker deploy || true
echo "[deploy] Ensuring $DEPLOY_DIR ownership"
sudo chown -R deploy:docker "$DEPLOY_DIR"
echo "[deploy] Creating .env file"
sudo -u deploy bash -c "echo 'WEBHOOK_SECRET=${{ secrets.WEBHOOK_SECRET }}' >> $DEPLOY_DIR/.env"
sudo -u deploy bash -c "echo 'AWS_ECR_REGION=${{ secrets.AWS_ECR_REGION }}' >> $DEPLOY_DIR/.env"
sudo chmod 600 "$DEPLOY_DIR/.env"
echo "[deploy] Building CD server Docker image"
sudo -u deploy docker compose -f "$DEPLOY_DIR/docker-compose.yml" build --no-cache
echo "[deploy] Starting CD server container"
sudo -u deploy docker compose -f "$DEPLOY_DIR/docker-compose.yml" up -d --force-recreate
echo "[deploy] Waiting for service to be healthy"
for i in {1..30}; do
if curl -s http://127.0.0.1:3333/health > /dev/null; then
echo "[deploy] Service is healthy"
break
fi
if [ "$i" -eq 30 ]; then
echo "[deploy] Service failed health check"
sudo docker logs cd-server --no-pager || true
exit 1
fi
sleep 2
done
echo "[deploy] Deployment completed successfully"