Skip to content

Commit

Permalink
Merge pull request prasadhonrao#17 from prasadhonrao/feature/api-ci-c…
Browse files Browse the repository at this point in the history
…d-workflow

Set Up CI/CD Pipeline Using GitHub Actions for API project
  • Loading branch information
prasadhonrao authored Sep 14, 2024
2 parents 8a38ad0 + 079c5af commit 9629ff5
Show file tree
Hide file tree
Showing 4 changed files with 104 additions and 3 deletions.
41 changes: 41 additions & 0 deletions .github/workflows/api-build.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
name: API - Build

on:
push:
branches:
- main
paths:
- 'api/**'
pull_request:
branches:
- main
paths:
- 'api/**'
workflow_dispatch:

env:
DOCKER_IMAGE: prasadhonrao/devcamper-api

jobs:
build:
runs-on: ubuntu-latest

steps:
- name: Checkout code
uses: actions/checkout@v4

- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v1

- name: Log in to Docker Hub
uses: docker/login-action@v1
with:
username: ${{ secrets.DOCKER_USERNAME }}
password: ${{ secrets.DOCKER_PASSWORD }}

- name: Build and push Docker image
run: |
docker build -t ${{ env.DOCKER_IMAGE }}:${{ github.sha }} -f api/Dockerfile api
docker tag ${{ env.DOCKER_IMAGE }}:${{ github.sha }} ${{ env.DOCKER_IMAGE }}:latest
docker push ${{ env.DOCKER_IMAGE }}:${{ github.sha }}
docker push ${{ env.DOCKER_IMAGE }}:latest
35 changes: 35 additions & 0 deletions .github/workflows/api-deploy.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
name: API - Deploy

on:
push:
branches:
- main
paths:
- 'api/**'
pull_request:
branches:
- main
paths:
- 'api/**'
workflow_dispatch:

jobs:
deploy:
runs-on: ubuntu-latest

steps:
- name: Checkout code
uses: actions/checkout@v4

- name: Set up Node.js
uses: actions/setup-node@v4
with:
node-version: '20'

- name: Install dependencies
run: npm install --prefix api

- name: Deploy
run: |
# Add your deployment steps here
echo "Deploying the application..."
29 changes: 28 additions & 1 deletion .github/workflows/api.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@ on:
- 'api/**'
workflow_dispatch:

env:
DOCKER_IMAGE: prasadhonrao/devcamper-api

jobs:
lint:
runs-on: ubuntu-latest
Expand Down Expand Up @@ -128,10 +131,34 @@ jobs:
name: coverage-report
path: api/coverage

deploy:
build:
runs-on: ubuntu-latest
needs: code-coverage

steps:
- name: Checkout code
uses: actions/checkout@v4

- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v1

- name: Log in to Docker Hub
uses: docker/login-action@v1
with:
username: ${{ secrets.DOCKER_USERNAME }}
password: ${{ secrets.DOCKER_PASSWORD }}

- name: Build and push Docker image
run: |
docker build -t ${{ env.DOCKER_IMAGE }}:${{ github.sha }} -f api/Dockerfile api
docker tag ${{ env.DOCKER_IMAGE }}:${{ github.sha }} ${{ env.DOCKER_IMAGE }}:latest
docker push ${{ env.DOCKER_IMAGE }}:${{ github.sha }}
docker push ${{ env.DOCKER_IMAGE }}:latest
deploy:
runs-on: ubuntu-latest
needs: build

steps:
- name: Checkout code
uses: actions/checkout@v4
Expand Down
2 changes: 0 additions & 2 deletions api/.dockerignore
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
node_modules
npm-debug.log
Dockerfile
.dockerignore
docker-compose.yml
.git
.gitignore
_postman
Expand Down

0 comments on commit 9629ff5

Please sign in to comment.