Skip to content

Commit

Permalink
feat(cd): publish and pull from dockerhub
Browse files Browse the repository at this point in the history
  • Loading branch information
proffapt committed Jul 1, 2024
1 parent e26eb4c commit 3dee899
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 9 deletions.
59 changes: 51 additions & 8 deletions .github/workflows/deploy.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: Continuous Deployment Pipeline for backend
name: Continuous Deployment Pipeline

on:
push:
Expand All @@ -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:
Expand All @@ -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 }}
Expand All @@ -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:
Expand Down
3 changes: 2 additions & 1 deletion backend/docker-compose.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
services:
iqps-backend:
image: iqps-backend
image: metakgporg/iqps-backend
container_name: iqps-backend
build: .
restart: always
networks:
Expand Down

0 comments on commit 3dee899

Please sign in to comment.