feat(ci): add deploy step to pull and run images on server
Some checks failed
CI/CD Pipeline / Code Quality Checks (push) Successful in 1m56s
CI/CD Pipeline / Run Tests (push) Successful in 2m10s
CI/CD Pipeline / Build Docker Images (push) Successful in 2s
CI/CD Pipeline / Push to Gitea Registry (push) Successful in 15s
CI/CD Pipeline / Deploy to Server (push) Failing after 1s

This commit is contained in:
2026-02-02 14:20:59 +01:00
parent 6c0e7bad9b
commit 404e380661
2 changed files with 166 additions and 0 deletions

View File

@@ -167,3 +167,46 @@ jobs:
- name: Image summary
run: |
echo "Images pushed to git.dev.nii-ecos.ru/${{ github.repository_owner }}/"
deploy:
name: Deploy to Server
runs-on: ubuntu-latest
needs: [push]
if: github.ref == 'refs/heads/main' || github.ref == 'refs/heads/develop' || github.ref == 'refs/heads/dev'
steps:
- name: Deploy via SSH
run: |
BRANCH_TAG=$(echo ${GITHUB_REF_NAME} | sed 's/\//-/g')
# Setup SSH
mkdir -p ~/.ssh
echo "${DEPLOY_SSH_KEY}" > ~/.ssh/deploy_key
chmod 600 ~/.ssh/deploy_key
ssh-keyscan -H ${DEPLOY_HOST} >> ~/.ssh/known_hosts 2>/dev/null
# Deploy commands
ssh -i ~/.ssh/deploy_key -o StrictHostKeyChecking=no ${DEPLOY_USER}@${DEPLOY_HOST} << EOF
cd /opt/mostovik-backend
# Login to registry
echo "${REGISTRY_PASSWORD}" | docker login --username "${REGISTRY_USER}" --password-stdin git.dev.nii-ecos.ru
# Pull new images
export IMAGE_TAG=${BRANCH_TAG}
docker compose -f docker-compose.prod.yml pull web celery_worker celery_beat
# Restart services
docker compose -f docker-compose.prod.yml up -d web celery_worker celery_beat
# Cleanup old images
docker image prune -f
EOF
echo "Deployed ${BRANCH_TAG} to ${DEPLOY_HOST}"
env:
DEPLOY_HOST: ${{ secrets.DEPLOY_HOST }}
DEPLOY_USER: ${{ secrets.DEPLOY_USER }}
DEPLOY_SSH_KEY: ${{ secrets.DEPLOY_SSH_KEY }}
REGISTRY_USER: ${{ secrets.REGISTRY_USER }}
REGISTRY_PASSWORD: ${{ secrets.REGISTRY_TOKEN }}