Skip to content

Commit

Permalink
Updating the branches and pipeline for different envs
Browse files Browse the repository at this point in the history
  • Loading branch information
mhmdksh committed Sep 24, 2024
1 parent 2ef82f2 commit 00c237a
Show file tree
Hide file tree
Showing 6 changed files with 163 additions and 75 deletions.
17 changes: 9 additions & 8 deletions .github/workflows/rpgf5-production-deploy.yml
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
name: rpgf5-prod-deploy-pipeline

on:
push:
branches:
- rpgf5
workflow_dispatch:
# push:
# branches:
# - master

jobs:
publish:
Expand Down Expand Up @@ -45,19 +46,19 @@ jobs:
git checkout rpgf5
git pull origin rpgf5
docker image prune -a --force
docker compose pull
docker compose -f docker-compose-prod.yml pull
## Update each backend service one by one
docker compose up -d --no-deps --scale pw-backend1=0 --scale pw-backend2=1
docker compose up -d
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
fi
docker compose up -d --no-deps --scale pw-backend1=1 --scale pw-backend2=0
docker compose up -d
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"
Expand Down
59 changes: 48 additions & 11 deletions .github/workflows/rpgf5-staging-deploy.yml
Original file line number Diff line number Diff line change
@@ -1,28 +1,65 @@
name: rpgf5-staging-deploy-pipeline

on:
workflow_dispatch:
# push:
# branches:
# - rpgf5-prototype
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 Staging
- 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 rpgf4-pw-backend
docker-compose down -v
docker image prune -a --force
cd pw-backend
git reset --hard HEAD~1
git checkout staging
git reset --hard origin/staging
git pull origin staging
docker-compose build --no-cache
docker-compose up -d
docker image prune -a --force
docker compose -f docker-compose-staging.yml pull
## 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
fi
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
17 changes: 0 additions & 17 deletions docker-compose-local.yml

This file was deleted.

50 changes: 50 additions & 0 deletions docker-compose-prod.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
version: '3'

services:
pw-backend1:
image: ghcr.io/generalmagicio/rpgf5-be:main
container_name: pw-backend1
restart: always
ports:
- 7070
env_file:
- .env
networks:
- pw-backend

pw-backend2:
image: ghcr.io/generalmagicio/rpgf5-be:main
container_name: pw-backend2
restart: always
ports:
- 7070
env_file:
- .env
networks:
- pw-backend

caddy:
image: caddy:2-alpine
container_name: caddy
restart: unless-stopped
networks:
- pw-backend
ports:
- 80:80
- 443:443
env_file:
- .env
environment:
- BACKEND_URL=${BACKEND_URL:-}
- IP_WHITELIST=${IP_WHITELIST:-0.0.0.0/0}
volumes:
- caddy_data:/data
- caddy_config:/config
- ./Caddyfile:/etc/caddy/Caddyfile

volumes:
caddy_config:
caddy_data:

networks:
pw-backend:
50 changes: 50 additions & 0 deletions docker-compose-staging.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
version: '3'

services:
pw-backend1:
image: ghcr.io/generalmagicio/rpgf5-be:staging
container_name: pw-backend1
restart: always
ports:
- 7070
env_file:
- .env
networks:
- pw-backend

pw-backend2:
image: ghcr.io/generalmagicio/rpgf5-be:staging
container_name: pw-backend2
restart: always
ports:
- 7070
env_file:
- .env
networks:
- pw-backend

caddy:
image: caddy:2-alpine
container_name: caddy
restart: unless-stopped
networks:
- pw-backend
ports:
- 80:80
- 443:443
env_file:
- .env
environment:
- BACKEND_URL=${BACKEND_URL:-}
- IP_WHITELIST=${IP_WHITELIST:-0.0.0.0/0}
volumes:
- caddy_data:/data
- caddy_config:/config
- ./Caddyfile:/etc/caddy/Caddyfile

volumes:
caddy_config:
caddy_data:

networks:
pw-backend:
45 changes: 6 additions & 39 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -1,50 +1,17 @@
version: '3'

services:
pw-backend1:
image: ghcr.io/generalmagicio/rpgf5-be:main
container_name: pw-backend1
pw-backend:
build:
context: .
container_name: rpgf4-pw-backend
restart: always
ports:
- 7070
env_file:
- .env
- 7071:7070
networks:
- pw-backend

pw-backend2:
image: ghcr.io/generalmagicio/rpgf5-be:main
container_name: pw-backend2
restart: always
ports:
- 7070
env_file:
- .env
networks:
- pw-backend

caddy:
image: caddy:2-alpine
container_name: caddy
restart: unless-stopped
networks:
- pw-backend
ports:
- 80:80
- 443:443
env_file:
- .env
environment:
- BACKEND_URL=${BACKEND_URL:-}
- IP_WHITELIST=${IP_WHITELIST:-0.0.0.0/0}
volumes:
- caddy_data:/data
- caddy_config:/config
- ./Caddyfile:/etc/caddy/Caddyfile

volumes:
caddy_config:
caddy_data:
- ./data:/usr/src/app/data

networks:
pw-backend:

0 comments on commit 00c237a

Please sign in to comment.