Skip to content

Enhancement: MERN stack project for Kubernetes deployment #3

Enhancement: MERN stack project for Kubernetes deployment

Enhancement: MERN stack project for Kubernetes deployment #3

Workflow file for this run

name: Backend CI/CD
on:
push:
branches:
- main
paths:
- 'backend/**' # Trigger only for changes in the backend directory
jobs:
build-and-push-backend:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v3.5.3
- name: Build & push backend Docker image
uses: mr-smithers-excellent/docker-build-push@v6
with:
directory: backend
image: saurabhkr952/book-store-mern
tags: backend-${{ github.sha }}
registry: docker.io
dockerfile: backend/Dockerfile
username: ${{ secrets.DOCKER_USERNAME }}
password: ${{ secrets.DOCKER_PASSWORD }}
update-kubernetes-manifest: # this job will update the kubernetes manifest files image version tag
runs-on: ubuntu-latest
needs:
- build-and-push-backend
steps:
- uses: actions/checkout@v3
with:
repository: saurabhkr952/Book-Store-MERN-Stack
ref: 'main'
token: ${{ secrets.PAT_TOKEN }}
- name: setup git config
run: |
git config --local user.email "saurabhkr952@gmail.com"
git config --local user.name "saurabhkr952"
echo ${{ github.sha }}
sed -i 's+saurabhkr952/book-store-mern:backend.*+saurabhkr952/book-store-mern:backend-${{ github.sha }}+g' kubernetes-manifests/2.backend.yaml
git add -A
git commit -m "update image tag for - ${{ github.sha }}"
- name: Push changes
uses: ad-m/github-push-action@master
with:
github_token: ${{ secrets.PAT_TOKEN }}
repository: saurabhkr952/Book-Store-MERN-Stack
force: true