From 93711015e6a934b29041eef30c96b6027e3c238c Mon Sep 17 00:00:00 2001 From: Arpit Bhardwaj Date: Sat, 20 Apr 2024 15:40:12 +0530 Subject: [PATCH] Deployment Pipeline (#132) * 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 --- .github/workflows/deploy.yaml | 78 +++++++++++++++++++++++++++++++++++ .github/workflows/sync.yaml | 30 ++++++++++++++ docker-compose.prod.yml | 1 + docker-compose.yml | 3 ++ 4 files changed, 112 insertions(+) create mode 100644 .github/workflows/deploy.yaml create mode 100644 .github/workflows/sync.yaml diff --git a/.github/workflows/deploy.yaml b/.github/workflows/deploy.yaml new file mode 100644 index 0000000..9ab7a23 --- /dev/null +++ b/.github/workflows/deploy.yaml @@ -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 diff --git a/.github/workflows/sync.yaml b/.github/workflows/sync.yaml new file mode 100644 index 0000000..e086fc8 --- /dev/null +++ b/.github/workflows/sync.yaml @@ -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 \ No newline at end of file diff --git a/docker-compose.prod.yml b/docker-compose.prod.yml index f79286d..f624002 100644 --- a/docker-compose.prod.yml +++ b/docker-compose.prod.yml @@ -4,6 +4,7 @@ include: services: jobs: build: "./jobs" + restart: always networks: mysql-network: environment: diff --git a/docker-compose.yml b/docker-compose.yml index 2d5db53..0e919b4 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -1,6 +1,7 @@ services: mysql: build: "./mysql" + restart: always networks: mysql-network: aliases: @@ -15,6 +16,7 @@ services: mediawiki: build: "./mediawiki" + restart: always networks: mysql-network: mediawiki-network: @@ -36,6 +38,7 @@ services: nginx: build: "./nginx" + restart: always networks: metaploy-network: aliases: