Skip to content

Commit

Permalink
Deployment Pipeline (#132)
Browse files Browse the repository at this point in the history
* feat: CD pipeline

* feat: all container services should live till docker service lives

* feat: trigger based on paths relevant for deployment

* feat: added sync file
  • Loading branch information
proffapt authored Apr 20, 2024
1 parent 0aea68a commit 9371101
Show file tree
Hide file tree
Showing 4 changed files with 112 additions and 0 deletions.
78 changes: 78 additions & 0 deletions .github/workflows/deploy.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
name: Continuous Deployment for Metakgp-Wiki

on:
push:
branches:
- "master"
paths:
- "jobs/**"
- "mediawiki/**"
- "mysql/**"
- "nginx/**"
- "docker-compose.prod.yml"
- "docker-compose.yml"

jobs:
pull:
name: Pull Stage
runs-on: ubuntu-latest

steps:
- name: Sync with remote repository
uses: appleboy/ssh-action@master
env:
WIKI_DIR: ${{ secrets.WIKI_DIR }}
with:
host: ${{ secrets.HOSTNAME }}
username: ${{ secrets.USERNAME }}
key: ${{ secrets.SSH_PRIVATE_KEY }}
passphrase: ${{ secrets.PASSPHRASE }}
envs: WIKI_DIR
script_stop: true
script: |
cd "${WIKI_DIR}/"
sudo git fetch origin
sudo git reset --hard origin/master
build:
name: Build Stage
needs: pull
runs-on: ubuntu-latest

steps:
- name: Build the latest docker container
uses: appleboy/ssh-action@master
env:
WIKI_DIR: ${{ secrets.WIKI_DIR }}
with:
host: ${{ secrets.HOSTNAME }}
username: ${{ secrets.USERNAME }}
key: ${{ secrets.SSH_PRIVATE_KEY }}
passphrase: ${{ secrets.PASSPHRASE }}
envs: WIKI_DIR
script_stop: true
script: |
cd "${WIKI_DIR}/"
sudo docker compose -f docker-compose.prod.yml build
deploy:
name: Deploy Stage
needs: [pull, build]
runs-on: ubuntu-latest

steps:
- name: Deploy the latest build
uses: appleboy/ssh-action@master
env:
WIKI_DIR: ${{ secrets.WIKI_DIR }}
with:
host: ${{ secrets.HOSTNAME }}
username: ${{ secrets.USERNAME }}
key: ${{ secrets.SSH_PRIVATE_KEY }}
passphrase: ${{ secrets.PASSPHRASE }}
envs: WIKI_DIR
script_stop: true
script: |
cd "${WIKI_DIR}/"
sudo docker compose -f docker-compose.prod.yml down
sudo docker compose -f docker-compose.prod.yml up -d
30 changes: 30 additions & 0 deletions .github/workflows/sync.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
name: Sync Important Items Except Those Needed For Deployment

on:
push:
branches:
- "master"
paths:
- "scripts/**"

jobs:
pull:
name: Pull Stage
runs-on: ubuntu-latest

steps:
- name: Sync with remote repository
uses: appleboy/ssh-action@master
env:
WIKI_DIR: ${{ secrets.WIKI_DIR }}
with:
host: ${{ secrets.HOSTNAME }}
username: ${{ secrets.USERNAME }}
key: ${{ secrets.SSH_PRIVATE_KEY }}
passphrase: ${{ secrets.PASSPHRASE }}
envs: WIKI_DIR
script_stop: true
script: |
cd "${WIKI_DIR}/"
sudo git fetch origin
sudo git reset --hard origin/master
1 change: 1 addition & 0 deletions docker-compose.prod.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ include:
services:
jobs:
build: "./jobs"
restart: always
networks:
mysql-network:
environment:
Expand Down
3 changes: 3 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
services:
mysql:
build: "./mysql"
restart: always
networks:
mysql-network:
aliases:
Expand All @@ -15,6 +16,7 @@ services:

mediawiki:
build: "./mediawiki"
restart: always
networks:
mysql-network:
mediawiki-network:
Expand All @@ -36,6 +38,7 @@ services:

nginx:
build: "./nginx"
restart: always
networks:
metaploy-network:
aliases:
Expand Down

0 comments on commit 9371101

Please sign in to comment.