forked from hngprojects/hng_boilerplate_expressjs
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request hngprojects#589 from hngprojects/fix-workflows
updated dockercompose files and workflows
- Loading branch information
Showing
5 changed files
with
86 additions
and
62 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,57 +1,74 @@ | ||
name: Deploy to prod Branch | ||
name: Deploy to Prod | ||
|
||
on: | ||
workflow_run: | ||
workflows: [CI] | ||
types: | ||
- completed | ||
branches: [main] | ||
branches: [prod] | ||
|
||
jobs: | ||
build-and-deploy: | ||
on-success: | ||
runs-on: ubuntu-latest | ||
if: ${{ github.event.workflow_run.conclusion == 'success' }} | ||
steps: | ||
- name: Checkout repository | ||
uses: actions/checkout@v4 | ||
|
||
- name: Install sshpass | ||
run: sudo apt-get install sshpass | ||
|
||
- name: Fetch .env file from server | ||
run: | | ||
sshpass -p ${{ secrets.PASSWORD }} scp -o StrictHostKeyChecking=no ${{ secrets.USERNAME }}@${{ secrets.HOST }}:/var/www/aihomework/staging/.env .env | ||
sshpass -p ${{ secrets.PASSWORD }} scp -o StrictHostKeyChecking=no ${{ secrets.USERNAME }}@${{ secrets.HOST }}:~/prod-deployment/hng_boilerplate_expressjs/.env .env | ||
env: | ||
SSH_HOST: ${{ secrets.HOST }} | ||
SSH_USERNAME: ${{ secrets.USERNAME }} | ||
SSH_PASSWORD: ${{ secrets.PASSWORD }} | ||
|
||
- name: Build Docker images using docker-compose | ||
- name: Build Docker images | ||
run: | | ||
docker compose --env-file .env -f docker-compose.production.yml build | ||
- name: List Docker images | ||
run: docker images | ||
|
||
- name: Save Docker images to tarball | ||
run: | | ||
docker save $(docker compose -f docker-compose.production.yml config | grep 'image:' | awk '{print $2}') | gzip > docker-images.tar.gz | ||
docker save hng_boilerplate_expressjs-backend_prod:latest | gzip > prod-images.tar.gz | ||
- name: Upload to server | ||
run: | | ||
sshpass -p ${{ secrets.PASSWORD }} scp -o StrictHostKeyChecking=no docker-images.tar.gz ${{ secrets.USERNAME }}@${{ secrets.HOST }}:/tmp/ | ||
env: | ||
SSH_HOST: ${{ secrets.HOST }} | ||
SSH_USERNAME: ${{ secrets.USERNAME }} | ||
SSH_PASSWORD: ${{ secrets.PASSWORD }} | ||
- name: Upload artifact | ||
uses: actions/upload-artifact@v2 | ||
with: | ||
name: prod-images | ||
path: prod-images.tar.gz | ||
|
||
- name: Deploy and start on remote server | ||
run: | | ||
sshpass -p ${{ secrets.PASSWORD }} ssh -o StrictHostKeyChecking=no ${{ secrets.USERNAME }}@${{ secrets.HOST }} " | ||
cd /var/www/aihomework/prod | ||
- name: Copy Docker images to server | ||
uses: appleboy/scp-action@master | ||
with: | ||
host: ${{ secrets.HOST }} | ||
username: ${{ secrets.USERNAME }} | ||
password: ${{ secrets.PASSWORD }} | ||
source: "prod-images.tar.gz" | ||
target: "~/images-tar" | ||
|
||
- name: Deploy to server | ||
uses: appleboy/ssh-action@master | ||
with: | ||
host: ${{ secrets.HOST }} | ||
username: ${{ secrets.USERNAME }} | ||
password: ${{ secrets.PASSWORD }} | ||
script: | | ||
cd ~/prod-deployment/hng_boilerplate_expressjs | ||
git stash | ||
git pull origin main | ||
docker load -i /tmp/docker-images.tar.gz | ||
git checkout prod | ||
git pull | ||
docker load -i ~/images-tar/prod-images.tar.gz | ||
docker compose -f docker-compose.production.yml down | ||
docker compose -f docker-compose.production.yml up -d | ||
" | ||
env: | ||
SSH_HOST: ${{ secrets.HOST }} | ||
SSH_USERNAME: ${{ secrets.USERNAME }} | ||
SSH_PASSWORD: ${{ secrets.PASSWORD }} | ||
on-failure: | ||
runs-on: ubuntu-latest | ||
if: ${{ github.event.workflow_run.conclusion == 'failure' }} | ||
steps: | ||
- run: echo "CI Workflow failed. Prod deployment was not triggered." |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,58 +1,74 @@ | ||
name: Deploy to staging Branch | ||
name: Deploy to staging | ||
|
||
on: | ||
workflow_run: | ||
workflows: [CI] | ||
types: | ||
- completed | ||
branches: [staging] | ||
|
||
jobs: | ||
build-and-deploy: | ||
on-success: | ||
runs-on: ubuntu-latest | ||
if: ${{ github.event.workflow_run.conclusion == 'success' }} | ||
steps: | ||
- name: Checkout repository | ||
uses: actions/checkout@v4 | ||
|
||
- name: Install sshpass | ||
run: sudo apt-get install sshpass | ||
|
||
- name: Fetch .env file from server | ||
run: | | ||
sshpass -p ${{ secrets.PASSWORD }} scp -o StrictHostKeyChecking=no ${{ secrets.USERNAME }}@${{ secrets.HOST }}:/var/www/aihomework/staging/.env .env | ||
sshpass -p ${{ secrets.PASSWORD }} scp -o StrictHostKeyChecking=no ${{ secrets.USERNAME }}@${{ secrets.HOST }}:~/staging-deployment/hng_boilerplate_expressjs/.env .env | ||
env: | ||
SSH_HOST: ${{ secrets.HOST }} | ||
SSH_USERNAME: ${{ secrets.USERNAME }} | ||
SSH_PASSWORD: ${{ secrets.PASSWORD }} | ||
|
||
- name: Build Docker images using docker-compose | ||
- name: Build Docker images | ||
run: | | ||
docker compose --env-file .env -f docker-compose.staging.yml build | ||
- name: List Docker images | ||
run: docker images | ||
|
||
- name: Save Docker images to tarball | ||
run: | | ||
docker save $(docker compose -f docker-compose.staging.yml config | grep 'image:' | awk '{print $2}') | gzip > docker-images.tar.gz | ||
docker save hng_boilerplate_expressjs-backend_staging:latest | gzip > staging-images.tar.gz | ||
- name: Upload to server | ||
run: | | ||
sshpass -p ${{ secrets.PASSWORD }} scp -o StrictHostKeyChecking=no docker-images.tar.gz ${{ secrets.USERNAME }}@${{ secrets.HOST }}:/tmp/ | ||
env: | ||
SSH_HOST: ${{ secrets.HOST }} | ||
SSH_USERNAME: ${{ secrets.USERNAME }} | ||
SSH_PASSWORD: ${{ secrets.PASSWORD }} | ||
- name: Upload artifact | ||
uses: actions/upload-artifact@v2 | ||
with: | ||
name: staging-images | ||
path: staging-images.tar.gz | ||
|
||
- name: Deploy and start on remote server | ||
run: | | ||
sshpass -p ${{ secrets.PASSWORD }} ssh -o StrictHostKeyChecking=no ${{ secrets.USERNAME }}@${{ secrets.HOST }} " | ||
cd /var/www/aihomework/staging | ||
- name: Copy Docker images to server | ||
uses: appleboy/scp-action@master | ||
with: | ||
host: ${{ secrets.HOST }} | ||
username: ${{ secrets.USERNAME }} | ||
password: ${{ secrets.PASSWORD }} | ||
source: "staging-images.tar.gz" | ||
target: "~/images-tar" | ||
|
||
- name: Deploy to server | ||
uses: appleboy/ssh-action@master | ||
with: | ||
host: ${{ secrets.HOST }} | ||
username: ${{ secrets.USERNAME }} | ||
password: ${{ secrets.PASSWORD }} | ||
script: | | ||
cd ~/staging-deployment/hng_boilerplate_expressjs | ||
git stash | ||
git pull origin staging | ||
docker load -i /tmp/docker-images.tar.gz | ||
git checkout staging | ||
git pull | ||
docker load -i ~/images-tar/staging-images.tar.gz | ||
docker compose -f docker-compose.staging.yml down | ||
docker compose -f docker-compose.staging.yml up -d | ||
rm /tmp/docker-images.tar.gz | ||
" | ||
env: | ||
SSH_HOST: ${{ secrets.HOST }} | ||
SSH_USERNAME: ${{ secrets.USERNAME }} | ||
SSH_PASSWORD: ${{ secrets.PASSWORD }} | ||
on-failure: | ||
runs-on: ubuntu-latest | ||
if: ${{ github.event.workflow_run.conclusion == 'failure' }} | ||
steps: | ||
- run: echo "CI Workflow failed. Staging deployment was not triggered." |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
services: | ||
backend: | ||
backend_prod: | ||
container_name: backend_prod | ||
build: | ||
context: . | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
services: | ||
backend: | ||
backend_staging: | ||
container_name: backend_staging | ||
build: | ||
context: . | ||
|