Skip to content

addig a local build compose file #23

addig a local build compose file

addig a local build compose file #23

name: rpgf5-staging-deploy-pipeline
on:
push:
branches:
- staging
jobs:
publish:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Set up QEMU
uses: docker/setup-qemu-action@v3
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Login to GitHub Container Registry
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Build and push
uses: docker/build-push-action@v6
with:
context: .
push: true
tags: ghcr.io/generalmagicio/rpgf5-be:staging
deploy:
runs-on: ubuntu-latest
needs: publish
steps:
- name: SSH and Redeploy Production
uses: appleboy/[email protected]
with:
host: ${{ secrets.RPGF5_STAGING_HOST }}
username: ${{ secrets.RPGF5_STAGING_USERNAME }}
key: ${{ secrets.RPGF5_STAGING_PRIVATE_KEY }}
port: ${{ secrets.SSH_PORT }}
script: |
cd pw-backend
git reset --hard origin/staging
git checkout staging
git pull origin staging
docker image prune -a --force
docker compose -f docker-compose-staging.yml pull
rollout-deploy-1:
needs: deploy
runs-on: ubuntu-latest
steps:
- name: SSH and Redeploy
uses: appleboy/[email protected]
with:
host: ${{ secrets.STAGING_HOST }}
username: ${{ secrets.STAGING_USERNAME }}
key: ${{ secrets.STAGING_PRIVATE_KEY }}
port: ${{ secrets.SSH_PORT }}
script: |
cd pw-backend
## Update each backend service one by one
## First Deployment
docker compose -f docker-compose-staging.yml rm -fs pw-backend1
docker compose -f docker-compose-staging.yml up --force-recreate -d pw-backend1
# Wait for pw-backend1 to be healthy (timeout after 5 minutes)
echo "Waiting for pw-backend1 to become healthy..."
timeout 300 bash -c 'until [ "$(docker inspect --format="{{json .State.Health.Status}}" pw-backend1)" == "\"healthy\"" ]; do echo "Waiting for pw-backend1 to be healthy..."; sleep 5; done'
if [ $? -eq 124 ]; then
echo "Timeout waiting for pw-backend1 to become healthy"
exit 1
fi
# Check if pw-backend1 is healthy
if [ "$(docker inspect --format='{{json .State.Health.Status}}' pw-backend1)" != "\"healthy\"" ]; then
echo "pw-backend1 is not healthy, stopping deployment"
exit 1
fi
echo "First deployment phase completed successfully"
rollout-deploy-2:
needs: rollout-deploy-1
runs-on: ubuntu-latest
steps:
- name: SSH and Redeploy
uses: appleboy/[email protected]
with:
host: ${{ secrets.STAGING_HOST }}
username: ${{ secrets.STAGING_USERNAME }}
key: ${{ secrets.STAGING_PRIVATE_KEY }}
port: ${{ secrets.SSH_PORT }}
script: |
cd pw-backend
## Update each backend service one by one
## Second Deployment
docker compose -f docker-compose-staging.yml rm -fs pw-backend2
docker compose -f docker-compose-staging.yml up --force-recreate -d pw-backend2
# Wait for pw-backend2 to be healthy (timeout after 5 minutes)
echo "Waiting for pw-backend2 to become healthy..."
timeout 300 bash -c 'until [ "$(docker inspect --format="{{json .State.Health.Status}}" pw-backend2)" == "\"healthy\"" ]; do echo "Waiting for pw-backend2 to be healthy..."; sleep 5; done'
if [ $? -eq 124 ]; then
echo "Timeout waiting for pw-backend2 to become healthy"
exit 1
fi
# Check if pw-backend2 is healthy
if [ "$(docker inspect --format='{{json .State.Health.Status}}' pw-backend2)" != "\"healthy\"" ]; then
echo "pw-backend2 is not healthy, stopping deployment"
exit 1
fi
echo "Second deployment phase completed successfully"