Skip to content

Commit

Permalink
fixing rollout deployment & Build
Browse files Browse the repository at this point in the history
  • Loading branch information
mhmdksh committed Dec 3, 2024
1 parent 02142ee commit 706a55f
Show file tree
Hide file tree
Showing 4 changed files with 87 additions and 19 deletions.
75 changes: 61 additions & 14 deletions .github/workflows/rpgf5-staging-deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -41,25 +41,72 @@ jobs:
port: ${{ secrets.SSH_PORT }}
script: |
cd pw-backend
git reset --hard HEAD~1
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
docker compose -f docker-compose-staging.yml up -d --no-deps --scale pw-backend1=0 --scale pw-backend2=1
docker compose -f docker-compose-staging.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-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
docker compose -f docker-compose-staging.yml up -d --no-deps --scale pw-backend1=1 --scale pw-backend2=0
docker compose -f docker-compose-staging.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"
1 change: 1 addition & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ COPY package*.json ./
COPY tsconfig*.json ./
RUN npm install -g @nestjs/cli
RUN npm install
RUN apk add git curl
COPY . .
RUN npm run build
EXPOSE 7070
Expand Down
16 changes: 13 additions & 3 deletions docker-compose-prod.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
version: '3'

services:
pw-backend1:
image: ghcr.io/generalmagicio/rpgf5-be:main
Expand All @@ -11,6 +9,12 @@ services:
- .env
networks:
- pw-backend
healthcheck:
test: ['CMD', 'curl', '-f', 'http://localhost:7070']
interval: 30s
timeout: 10s
retries: 5
start_period: 60s

pw-backend2:
image: ghcr.io/generalmagicio/rpgf5-be:main
Expand All @@ -22,7 +26,13 @@ services:
- .env
networks:
- pw-backend

healthcheck:
test: ['CMD', 'curl', '-f', 'http://localhost:7070']
interval: 30s
timeout: 10s
retries: 5
start_period: 60s

caddy:
image: caddy:2-alpine
container_name: caddy
Expand Down
14 changes: 12 additions & 2 deletions docker-compose-staging.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
version: '3'

services:
pw-backend1:
image: ghcr.io/generalmagicio/rpgf5-be:staging
Expand All @@ -11,6 +9,12 @@ services:
- .env
networks:
- pw-backend
healthcheck:
test: ['CMD', 'curl', '-f', 'http://localhost:7070']
interval: 30s
timeout: 10s
retries: 5
start_period: 60s

pw-backend2:
image: ghcr.io/generalmagicio/rpgf5-be:staging
Expand All @@ -22,6 +26,12 @@ services:
- .env
networks:
- pw-backend
healthcheck:
test: ['CMD', 'curl', '-f', 'http://localhost:7070']
interval: 30s
timeout: 10s
retries: 5
start_period: 60s

caddy:
image: caddy:2-alpine
Expand Down

0 comments on commit 706a55f

Please sign in to comment.