This is Ci and Cd #87
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: project_backend_ci_cd_workflows | |
on: | |
push: | |
branches: | |
- develop | |
jobs: | |
build-node: | |
runs-on: self-hosted # Self-hosted runner for the first job | |
steps: | |
- name: Checkout code | |
uses: actions/checkout@v3 | |
- name: Set up Node.js | |
uses: actions/setup-node@v3 | |
with: | |
node-version: '20' # Specify the Node.js version you're using | |
- name: Install dependencies | |
run: npm install | |
build-docker: | |
runs-on: ubuntu-latest # GitHub-hosted runner for the second job | |
steps: | |
- name: Checkout code | |
uses: actions/checkout@v3 | |
- name: Login Dockerhub | |
env: | |
DOCKER_USERNAME: ${{ secrets.DOCKER_USERNAME }} | |
DOCKER_PASSWORD: ${{ secrets.DOCKER_PASSWORD }} | |
run: docker login -u $DOCKER_USERNAME -p $DOCKER_PASSWORD | |
- name: Build the Docker image | |
run: docker build -t sachin816/cicd-pipeline . | |
- name: Push to Dockerhub | |
run: docker push sachin816/cicd-pipeline:latest | |
deploy-docker: | |
runs-on: self-hosted # Self-hosted runner for the deployment job | |
steps: | |
- name: Pull Docker image | |
run: sudo docker pull sachin816/cicd-pipeline:latest | |
- name: Delete Old Docker container | |
run: sudo docker rm -f cicd-pipeline-container || true | |
- name: Run Docker Container | |
run: sudo docker run -d -p 7000:7000 --name cicd-pipeline-container sachin816/cicd-pipeline |