Skip to content

Commit

Permalink
updating the production pipeline
Browse files Browse the repository at this point in the history
  • Loading branch information
mhmdksh committed Dec 4, 2024
1 parent e331dcd commit dd27e5b
Show file tree
Hide file tree
Showing 2 changed files with 67 additions and 20 deletions.
75 changes: 61 additions & 14 deletions .github/workflows/rpgf5-production-deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -42,25 +42,72 @@ jobs:
port: ${{ secrets.SSH_PORT }}
script: |
cd pw-backend
git reset --hard HEAD~1
git reset --hard origin/master
git checkout master
git pull origin master
docker image prune -a --force
docker compose -f docker-compose-prod.yml pull
rollout-deploy-1:
needs: deploy
runs-on: ubuntu-latest
steps:
- name: SSH and Redeploy
uses: appleboy/[email protected]
with:
host: ${{ secrets.RPGF5_PROD_HOST }}
username: ${{ secrets.RPGF5_PROD_USERNAME }}
key: ${{ secrets.RPGF5_PROD_PRIVATE_KEY }}
port: ${{ secrets.SSH_PORT }}
script: |
cd pw-backend
## Update each backend service one by one
docker compose -f docker-compose-prod.yml up -d --no-deps --scale pw-backend1=0 --scale pw-backend2=1
docker compose -f docker-compose-prod.yml up -d
# Check the health of pw-backend1
if [ "$(docker inspect --format='{{json .State.Status}}' pw-backend1)" != "\"running\"" ]; then
echo "pw-backend1 is not running, stopping deployment"
exit 1
## First Deployment
docker compose -f docker-compose-prod.yml rm -fs pw-backend1
docker compose -f docker-compose-prod.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.RPGF5_PROD_HOST }}
username: ${{ secrets.RPGF5_PROD_USERNAME }}
key: ${{ secrets.RPGF5_PROD_PRIVATE_KEY }}
port: ${{ secrets.SSH_PORT }}
script: |
cd pw-backend
## Update each backend service one by one
## Second Deployment
docker compose -f docker-compose-prod.yml rm -fs pw-backend2
docker compose -f docker-compose-prod.yml up --force-recreate -d pw-backend2
docker compose -f docker-compose-prod.yml up -d --no-deps --scale pw-backend1=1 --scale pw-backend2=0
docker compose -f docker-compose-prod.yml up -d
# Check the health of pw-backend2
if [ "$(docker inspect --format='{{json .State.Status}}' pw-backend2)" != "\"running\"" ]; then
echo "pw-backend2 is not running, stopping deployment"
exit 1
fi
# 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"
12 changes: 6 additions & 6 deletions .github/workflows/rpgf5-staging-deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -54,9 +54,9 @@ jobs:
- name: SSH and Redeploy
uses: appleboy/[email protected]
with:
host: ${{ secrets.STAGING_HOST }}
username: ${{ secrets.STAGING_USERNAME }}
key: ${{ secrets.STAGING_PRIVATE_KEY }}
host: ${{ secrets.RPGF5_STAGING_HOST }}
username: ${{ secrets.RPGF5_STAGING_USERNAME }}
key: ${{ secrets.RPGF5_STAGING_PRIVATE_KEY }}
port: ${{ secrets.SSH_PORT }}
script: |
cd pw-backend
Expand Down Expand Up @@ -86,9 +86,9 @@ jobs:
- name: SSH and Redeploy
uses: appleboy/[email protected]
with:
host: ${{ secrets.STAGING_HOST }}
username: ${{ secrets.STAGING_USERNAME }}
key: ${{ secrets.STAGING_PRIVATE_KEY }}
host: ${{ secrets.RPGF5_STAGING_HOST }}
username: ${{ secrets.RPGF5_STAGING_USERNAME }}
key: ${{ secrets.RPGF5_STAGING_PRIVATE_KEY }}
port: ${{ secrets.SSH_PORT }}
script: |
cd pw-backend
Expand Down

0 comments on commit dd27e5b

Please sign in to comment.