From 3dee899fa6a73c016490b5fdf569e6f913fee53b Mon Sep 17 00:00:00 2001 From: proffapt Date: Mon, 1 Jul 2024 13:33:52 +0530 Subject: [PATCH] feat(cd): publish and pull from dockerhub --- .github/workflows/deploy.yaml | 59 ++++++++++++++++++++++++++++++----- backend/docker-compose.yaml | 3 +- 2 files changed, 53 insertions(+), 9 deletions(-) diff --git a/.github/workflows/deploy.yaml b/.github/workflows/deploy.yaml index e515d66b..1ff6b544 100644 --- a/.github/workflows/deploy.yaml +++ b/.github/workflows/deploy.yaml @@ -1,4 +1,4 @@ -name: Continuous Deployment Pipeline for backend +name: Continuous Deployment Pipeline on: push: @@ -9,8 +9,51 @@ on: - ".github/workflows/deploy.yaml" jobs: + dockerhub: + name: Publish Docker Image(s) to Dockerhub + 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 Docker Hub + uses: docker/login-action@v3 + with: + username: ${{ secrets.DOCKERHUB_USERNAME }} + password: ${{ secrets.DOCKERHUB_PASSWORD }} + + - name: Cache Docker layers for IQPS Backend + uses: actions/cache@v3 + with: + path: /tmp/.buildx-cache-iqps-backend + key: ${{ runner.os }}-buildx-iqps-backend-${{ github.sha }} + restore-keys: | + ${{ runner.os }}-buildx-iqps-backend- + + - name: Build & Push IQPS Backend + uses: docker/build-push-action@v5 + with: + context: ./backend/ + push: true + tags: ${{ secrets.DOCKERHUB_USERNAME }}/iqps-backend:latest + cache-from: type=local,src=/tmp/.buildx-cache-iqps-backend + cache-to: type=local,dest=/tmp/.buildx-cache-iqps-backend-new,mode=max + + - name: Move IQPS cache + run: | + rm -rf /tmp/.buildx-cache-iqps-backend + mv /tmp/.buildx-cache-iqps-backend-new /tmp/.buildx-cache-iqps-backend + push: - name: Push Stage + name: Push Code Stage + needs: dockerhub runs-on: ubuntu-latest steps: @@ -26,17 +69,17 @@ jobs: envs: PROJECT_DIR script_stop: true script: | - cd "${PROJECT_DIR}/" + cd "${PROJECT_DIR}/backend/" sudo git fetch origin sudo git reset --hard origin/main - build: - name: Build Stage + pull: + name: Pull Image Stage needs: push runs-on: ubuntu-latest steps: - - name: Build the latest container(s) + - name: Pull the latest images(s) uses: appleboy/ssh-action@master env: PROJECT_DIR: ${{ secrets.PROJECT_DIR }} @@ -49,11 +92,11 @@ jobs: script_stop: true script: | cd "${PROJECT_DIR}/backend/" - sudo docker compose build + sudo docker compose pull deploy: name: Deploy Stage - needs: [push, build] + needs: pull runs-on: ubuntu-latest steps: diff --git a/backend/docker-compose.yaml b/backend/docker-compose.yaml index 636b8fd9..3cfeccf1 100644 --- a/backend/docker-compose.yaml +++ b/backend/docker-compose.yaml @@ -1,6 +1,7 @@ services: iqps-backend: - image: iqps-backend + image: metakgporg/iqps-backend + container_name: iqps-backend build: . restart: always networks: