Skip to content

Commit

Permalink
split the pipline to 2 jobs and checkout different branch for each job
Browse files Browse the repository at this point in the history
  • Loading branch information
norali12 committed Sep 18, 2024
1 parent 7adca9c commit df04302
Showing 1 changed file with 57 additions and 20 deletions.
77 changes: 57 additions & 20 deletions .github/workflows/ci-cd.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,23 @@ name: CI/CD Pipeline

on:
push:
# branches:
# - CI-CD-pipline
# - main-backend
# - main-frontend
tags:
- v*

jobs:
build-and-deploy:
build-backend:
runs-on: ubuntu-latest

steps:
- name: Checkout code
- name: Checkout Initial Branch
uses: actions/checkout@v4
with:
ref: CI-CD-pipline

- name: Switch to Backend Branch
run: |
git fetch origin
git checkout main-backend
- name: Log in to Docker Hub
uses: docker/login-action@v3
Expand All @@ -27,23 +30,57 @@ jobs:
run: echo "TAG=$(git describe --tags --abbrev=0)" >> $GITHUB_ENV

- name: Build and Push Backend Image
if: github.ref == 'refs/heads/CI-CD-pipline'
# main-backend
uses: docker/build-push-action@v6
with:
push: true
tags: noraali/backend:${{ env.TAG }}
context: .
file: ./Dockerfile

# - name: Build and Push Frontend Image
# if: github.ref == 'refs/heads/CI-CD-pipline'
# # main-frontend
# uses: docker/build-push-action@v6
# with:
# push: true
# tags: noraali/front_end_project:${{ env.TAG }}
# context: ./templates #frontend folder
# file: ./templates/Dockerfile
context: . #./backend
file: ./Dockerfile #./backend/Dockerfile

build-frontend:
runs-on: ubuntu-latest

steps:
- name: Checkout Initial Branch
uses: actions/checkout@v4
with:
ref: CI-CD-pipline

- name: Switch to frontend Branch
run: |
git fetch origin
git checkout main-frontend
- name: Log in to Docker Hub
uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKER_USERNAME }}
password: ${{ secrets.DOCKER_ACCESS_TOKEN}}

- name: Extract the latest Git tag
run: echo "TAG=$(git describe --tags --abbrev=0)" >> $GITHUB_ENV

- name: Build and Push frontend Image
uses: docker/build-push-action@v6
with:
push: true
tags: noraali/frontend:${{ env.TAG }}
context: . #./frontend
file: ./Dockerfile #./frontend/Dockerfile






# branches:
# - CI-CD-pipline
# - main-backend
# - main-frontend



# if: github.ref == 'refs/heads/CI-CD-pipline'
# main-backend


0 comments on commit df04302

Please sign in to comment.