Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ujwal cicd #3

Merged
merged 70 commits into from
Nov 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
70 commits
Select commit Hold shift + click to select a range
44b2d39
[backend] Added dockerfile for backend
Uj5Ghare Nov 15, 2024
1b3beac
[frontend] Added dockerfile for frontend
Uj5Ghare Nov 15, 2024
3609fc1
[frontend] updated package-lock.json && Added docker-compose.yml file
Uj5Ghare Nov 15, 2024
85e3f88
[tf] Added terraform manifests in /tf/manifests
Uj5Ghare Nov 15, 2024
746d26d
[tf] renamed tf/manifest -> tf/files
Uj5Ghare Nov 16, 2024
ef4f391
[helm] Added helm chart and templates for backend
Uj5Ghare Nov 16, 2024
0dfd4dd
[helm] Added helm chart and templates for frontend
Uj5Ghare Nov 16, 2024
f8b54a8
[k8s] Added backend k8s manifests in k8s/manifests/backend/
Uj5Ghare Nov 16, 2024
cfd6b20
[k8s] Added frontend k8s manifests in k8s/manifests/frontend/ with in…
Uj5Ghare Nov 16, 2024
38ed1b4
[ghci] Added main.yml workflow
Uj5Ghare Nov 16, 2024
3ed12ca
Update main.yml
Uj5Ghare Nov 16, 2024
3f03836
[ghci] Updated main.yml
Uj5Ghare Nov 16, 2024
63991d0
Update main.yml
Uj5Ghare Nov 16, 2024
7cdb031
[ghci] Added docker.yml workflow
Uj5Ghare Nov 16, 2024
efe05ea
Revert "[ghci] Added docker.yml workflow"
Uj5Ghare Nov 16, 2024
60ac764
[ghci] Added docker.yml workflow
Uj5Ghare Nov 16, 2024
dacc0e6
Merge branch 'ujwal-cicd' of https://github.com/Uj5Ghare/fullstack-as…
Uj5Ghare Nov 16, 2024
fa0f177
Update docker.yml
Uj5Ghare Nov 16, 2024
5f20445
Update main.yml
Uj5Ghare Nov 16, 2024
7ab85c1
Update docker.yml
Uj5Ghare Nov 16, 2024
3bd0dcf
[ghci] Updated docker.yml workflow
Uj5Ghare Nov 16, 2024
b2c5704
Merge branch 'ujwal-cicd' of https://github.com/Uj5Ghare/fullstack-as…
Uj5Ghare Nov 16, 2024
d757ead
Update docker.yml
Uj5Ghare Nov 16, 2024
78df4fb
Update docker.yml
Uj5Ghare Nov 16, 2024
95a611b
[ghci] updated main.yml
Uj5Ghare Nov 16, 2024
a4695e8
Update main.yml
Uj5Ghare Nov 16, 2024
7d9bb64
[ghci] updated main.yml
Uj5Ghare Nov 16, 2024
d545920
[ghci] updated docker.yml
Uj5Ghare Nov 16, 2024
1bdb788
updated main.yml
Uj5Ghare Nov 16, 2024
451eee7
updated main.yml
Uj5Ghare Nov 16, 2024
e435db3
updated main.yml
Uj5Ghare Nov 16, 2024
a1201db
updated main.yml
Uj5Ghare Nov 16, 2024
c2a09ab
[ghci] Added tf.yml workflow
Uj5Ghare Nov 16, 2024
81b975a
[ghci] Updted tf.yml workflow
Uj5Ghare Nov 16, 2024
205d1ba
[ghci] Updted tf.yml workflow
Uj5Ghare Nov 16, 2024
9f92a1c
Added working_dir as default for jobs
Uj5Ghare Nov 16, 2024
4d46af0
updated main.yml
Uj5Ghare Nov 16, 2024
ba92b8d
[ghci] updated tf.yml
Uj5Ghare Nov 16, 2024
a60c9ae
updated workflow
Uj5Ghare Nov 16, 2024
36ecfdb
updated tf.yml
Uj5Ghare Nov 16, 2024
f919956
updated main.yml
Uj5Ghare Nov 16, 2024
0371629
updated main.yml
Uj5Ghare Nov 16, 2024
15d8f0b
updated main.yml
Uj5Ghare Nov 16, 2024
b75be38
testing push to dockerhub job
Uj5Ghare Nov 16, 2024
9ba81e3
test 2
Uj5Ghare Nov 16, 2024
d987161
test 3
Uj5Ghare Nov 16, 2024
811aaa7
test 4
Uj5Ghare Nov 16, 2024
dfe70c0
test 5
Uj5Ghare Nov 16, 2024
285d07a
Merge pull request #1 from Uj5Ghare/ujwal-helm
Uj5Ghare Nov 16, 2024
0cf8b28
Merge pull request #2 from Uj5Ghare/ujwal-k8s
Uj5Ghare Nov 16, 2024
cf0387c
test 6
Uj5Ghare Nov 16, 2024
a3a3559
[helm] Updated tag in chatgpt-backend/values.yaml && [k8s] updated ba…
Uj5Ghare Nov 16, 2024
59e5aff
test 7
Uj5Ghare Nov 16, 2024
da3556f
[helm] Updated tag in chatgpt-frontend/values.yaml && [k8s] updated f…
Uj5Ghare Nov 16, 2024
cba38da
[fix] docker push and tag update errors
Uj5Ghare Nov 16, 2024
d2d3ddb
[tf] updated tf.yml
Uj5Ghare Nov 16, 2024
085db0a
[helm] Updated tag in chatgpt-backend/values.yaml && [k8s] updated ba…
Uj5Ghare Nov 16, 2024
8068e74
[fix] working dir syntax error in tf.yml
Uj5Ghare Nov 16, 2024
f4d442a
[helm] Updated tag in chatgpt-frontend/values.yaml && [k8s] updated f…
Uj5Ghare Nov 16, 2024
059fa5a
[fix] flag --auto-approve in tf.yml
Uj5Ghare Nov 16, 2024
a58ecaf
[fix] flag error totally in tf.yml
Uj5Ghare Nov 16, 2024
172911a
tf test 1
Uj5Ghare Nov 16, 2024
662bc49
tf test 2
Uj5Ghare Nov 16, 2024
70a302b
tf test 3
Uj5Ghare Nov 16, 2024
d36f872
tf test 4
Uj5Ghare Nov 16, 2024
ad28665
tf test 5
Uj5Ghare Nov 16, 2024
8a814d4
tf test 6
Uj5Ghare Nov 16, 2024
2015f65
tf test 7 Apply
Uj5Ghare Nov 16, 2024
a51d571
tf test 8 Apply
Uj5Ghare Nov 16, 2024
cccae3e
Terraform Destroy
Uj5Ghare Nov 16, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 45 additions & 0 deletions .github/workflows/docker.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
name: Docker Compose Deployment Workflow

on:
push:
branches: [ujwal-cicd, ujwal-docker]
paths:
- ".github/workflows/docker.yml"
- "backend/**"
- "frontend/**"
- ".github/workflows/docker.yml"
pull_request:
types: [synchronize]
workflow_dispatch:

defaults:
run:
shell: bash

permissions:
actions: read
contents: read

jobs:
Docker-Compose-Deployment:
runs-on: self-hosted-runner
steps:

- name: Checkout Code
uses: actions/checkout@v4
with:
ref: ${{ github.ref_name }}

- name: Setup Env variables
run: |
echo -e ${{ secrets.FRONTEND_ENV }} > frontend/.env.local
echo -e ${{ secrets.BACKEND_ENV }} > backend/.env

- name: Destroy Previous Deployment
run: docker compose down

- name: Apply New Deployment
run: docker compose up -d

- name: Restart Nginx
run: sudo systemctl restart nginx
267 changes: 267 additions & 0 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,267 @@
name: ChatGPT Workflow

on:
push:
branches:
- main
- ujwal-devops
- ujwal-cicd
paths:
- ".github/workflows/main.yml"
- "backend/**"
- "frontend/**"
- "images/**"
- "prompts/**"
pull_request:
types: [synchronize]
workflow_dispatch:

defaults:
run:
shell: bash

permissions:
actions: write
contents: write

jobs:
SonarQube-Analysis:
runs-on: ubuntu-24.04
steps:
- name: Checkout Code
uses: actions/checkout@v4
with:
ref: ${{ github.ref_name }}
- name: Setup Environment variables
run: echo -e ${{ secrets.SONAR_PROPERTIES }} > sonar-project.properties
- name: Sonar Scan
uses: SonarSource/sonarcloud-github-action@master
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}

Build-App-Backend:
runs-on: ubuntu-22.04
needs: [SonarQube-Analysis]
defaults:
run:
shell: bash
working-directory: backend/
steps:
- name: Checkout Code
uses: actions/checkout@v4
with:
ref: ${{ github.ref_name }}
- name: Setup Python Environment
uses: actions/setup-python@v5
with:
python-version: "3.11"
- name: Install PM2
run: npm install -g pm2
- name: Setup Env variables
run: |
echo -e ${{ secrets.BACKEND_ENV }} > .env
- name: Install Dependencies
run: pwd && pip install -r dependencies.txt
- name: Make Migrations
run: python manage.py migrate
- name: Collect Static Content
run: python manage.py collectstatic
- name: Start App
run: pm2 start "gunicorn backend.wsgi:application -b 0.0.0.0:8000 --reload" --name backend

Build-App-Frontend:
runs-on: ubuntu-22.04
needs: [SonarQube-Analysis]
defaults:
run:
shell: bash
working-directory: frontend/
steps:
- name: Checkout Code
uses: actions/checkout@v4
with:
ref: ${{ github.ref_name }}
- name: Setup node Environment
uses: actions/setup-node@v4
with:
node-version: 18.20.5
- name: Install PM2
run: npm install -g pm2
- name: Setup Env variables
run: |
echo -e ${{ secrets.FRONTEND_ENV }} > .env.local
- name: Install Dependencies
run: pwd && npm install
- name: Static Build
run: npm run build
- name: Start App
run: pm2 start "npm start" --name frontend

Image-Vuln-Check-Backend:
runs-on: ubuntu-24.04
needs: [Build-App-Backend]
continue-on-error: true
defaults:
run:
shell: bash
working-directory: backend/
steps:
- name: Checkout Code
uses: actions/checkout@v4
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Build Docker Image
run: docker build -t docker.io/${{ vars.DOCKERHUB_USERNAME }}/chatgpt-backend:${{ github.sha }} .
- name: Run Trivy Vulnerability Scanner
uses: aquasecurity/trivy-action@0.20.0
with:
image-ref: "docker.io/${{ vars.DOCKERHUB_USERNAME }}/chatgpt-backend:${{ github.sha }}"
format: "table"
exit-code: "1"
ignore-unfixed: true
output: trivy-report-backend.txt
vuln-type: "os,library"
severity: "CRITICAL,HIGH"
- name: Upload Artifact
uses: actions/upload-artifact@v4
with:
name: trivy-report-backend
path: trivy-report-backend.txt

Image-Vuln-Check-Frontend:
runs-on: ubuntu-24.04
needs: [Build-App-Frontend]
continue-on-error: true
defaults:
run:
shell: bash
working-directory: frontend/
steps:
- name: Checkout Code
uses: actions/checkout@v4
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Build Docker Image
run: docker build -t docker.io/${{ vars.DOCKERHUB_USERNAME }}/chatgpt-frontend:${{ github.sha }} .
- name: Run Trivy Vulnerability Scanner
uses: aquasecurity/trivy-action@0.20.0
with:
image-ref: "docker.io/${{ vars.DOCKERHUB_USERNAME }}/chatgpt-frontend:${{ github.sha }}"
format: "table"
exit-code: "1"
ignore-unfixed: true
output: trivy-report-frontend.txt
vuln-type: "os,library"
severity: "CRITICAL,HIGH"
- name: Upload Artifact
uses: actions/upload-artifact@v4
with:
name: trivy-report-frontend
path: trivy-report-frontend.txt

Push-To-DockerHub-Backend:
runs-on: ubuntu-24.04
needs: [Image-Vuln-Check-Backend]
defaults:
run:
shell: bash
working-directory: backend/
steps:
- name: Checkout Code
uses: actions/checkout@v4
with:
ref: ${{ github.ref_name }}
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Login to Docker Registry
uses: docker/login-action@v3
with:
username: ${{ vars.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
- name: Building Docker Image
run: docker build . -t ${{ vars.DOCKERHUB_USERNAME }}/chatgpt-backend:1.${{ github.run_number }}.${{ github.run_attempt}}
- name: Pushing Docker Image
run: docker push ${{ vars.DOCKERHUB_USERNAME }}/chatgpt-backend:1.${{ github.run_number }}.${{ github.run_attempt}}
# - name: Build and push
# uses: docker/build-push-action@v6
# with:
# file: backend/Dockerfile
# push: true
# tags: ${{ vars.DOCKERHUB_USERNAME }}/chatgpt-backend:1.${{ github.run_number }}.${{ github.run_attempt}}

Push-To-DockerHub-Frontend:
runs-on: ubuntu-24.04
needs: [Image-Vuln-Check-Frontend]
defaults:
run:
shell: bash
working-directory: frontend/
steps:
- name: Checkout Code
uses: actions/checkout@v4
with:
ref: ${{ github.ref_name }}
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Login to Docker Registry
uses: docker/login-action@v3
with:
username: ${{ vars.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
- name: Building Docker Image
run: docker build . -t ${{ vars.DOCKERHUB_USERNAME }}/chatgpt-frontend:1.${{ github.run_number }}.${{ github.run_attempt}}
- name: Pushing Docker Image
run: docker push ${{ vars.DOCKERHUB_USERNAME }}/chatgpt-frontend:1.${{ github.run_number }}.${{ github.run_attempt}}
# - name: Build and push
# uses: docker/build-push-action@v6
# with:
# file: frontend/Dockerfile
# push: true
# tags: ${{ vars.DOCKERHUB_USERNAME }}/chatgpt-frontend:1.${{ github.run_number }}.${{ github.run_attempt}}

Update-Helm-Chart-Backend:
runs-on: ubuntu-24.04
needs: [Push-To-DockerHub-Backend]
steps:
- name: Checkout Code
uses: actions/checkout@v4
with:
token: ${{ secrets.GITHUB_TOKEN }}
- name: Update tag in Helm chart
run: |
sed -i 's/tag: .*/tag: "1.${{ github.run_number }}.${{ github.run_attempt}}"/' helm/charts/chatgpt-backend/values.yaml
- name: Update tag in K8s Deployment
run: |
sed -i 's|\(uj5ghare/chatgpt-backend:\)[^[:space:]]*|\1"1.${{ github.run_number }}.${{ github.run_attempt}}"|' k8s/manifests/backend/deployment.yml
- name: Commit and push changes
run: |
git pull origin ${{ github.ref_name }}
git config --global user.email "${{ secrets.GH_USER_MAIL }}"
git config --global user.name "${{ vars.GH_USER_NAME }}"
git add .
git commit -m "[helm] Updated tag in chatgpt-backend/values.yaml && [k8s] updated backend deployment image tag"
git push

Update-Helm-Chart-Frontend:
runs-on: ubuntu-24.04
needs: [Push-To-DockerHub-Frontend]
steps:
- name: Checkout Code
uses: actions/checkout@v4
with:
token: ${{ secrets.GITHUB_TOKEN }}
- name: Update tag in Helm chart
run: |
sed -i 's/tag: .*/tag: "1.${{ github.run_number }}.${{ github.run_attempt}}"/' helm/charts/chatgpt-frontend/values.yaml
- name: Update tag in K8s Deployment
run: |
sed -i 's|\(uj5ghare/chatgpt-frontend:\)[^[:space:]]*|\1"1.${{ github.run_number }}.${{ github.run_attempt}}"|' k8s/manifests/frontend/deployment.yml
- name: Commit and push changes
run: |
git pull origin ${{ github.ref_name }}
git config --global user.email "${{ secrets.GH_USER_MAIL }}"
git config --global user.name "${{ vars.GH_USER_NAME }}"
git add .
git commit -m "[helm] Updated tag in chatgpt-frontend/values.yaml && [k8s] updated frontend deployment image tag"
git push
70 changes: 70 additions & 0 deletions .github/workflows/tf.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
name: Terraform Deployment Workflow

on:
push:
branches:
- ujwal-cicd
- ujwal-tf
paths:
- ".github/workflows/tf.yml"
- "tf/files/**"
pull_request:
types: [synchronize]
workflow_dispatch:

defaults:
run:
shell: bash
working-directory: tf/files/

permissions:
actions: read
contents: read
pull-requests: write

env:
AWS_REGION: ${{ vars.AWS_REGION }}
AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }}
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }}

jobs:
Terraform-Deployment:
runs-on: ubuntu-24.04
steps:
- name: Checkout Code
uses: actions/checkout@v4
with:
ref: ${{ github.ref_name }}

- name: Setup Terraform
uses: hashicorp/setup-terraform@v3
with:
terraform_version: "1.9.8"

- name: Terraform fmt
id: fmt
run: terraform fmt -check
continue-on-error: true

- name: Terraform Init
id: init
run: terraform init

- name: Terraform Validate
id: validate
run: terraform validate

- name: Terraform Plan
id: plan
run: terraform plan -var-file=variables.tfvars -out=tfplan
continue-on-error: true

- name: Terraform Apply
if: "contains(github.event.head_commit.message, 'Apply')"
id: apply
run: terraform apply -var-file=variables.tfvars --auto-approve

- name: Terraform Destroy
if: "contains(github.event.head_commit.message, 'Destroy')"
id: destroy
run: terraform destroy -var-file=variables.tfvars --auto-approve
Loading
Loading