Skip to content

Commit c71ead6

Browse files
committed
added workflow
1 parent f56810b commit c71ead6

10 files changed

+255
-1
lines changed

.github/workflows/pylint.yml .github/workflows/1_pylint.yml

+2-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,8 @@ on:
99

1010
jobs:
1111
pylint-check:
12-
runs-on: ubuntu-latest
12+
# runs-on: ubuntu-latest -- Used to run on Github hosting
13+
runs-on: self-hosted
1314

1415
steps:
1516
- name: Checkout code

.github/workflows/2_sonar.yml

+34
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
name: Sonar Code Review Workflow
2+
3+
on:
4+
workflow_run:
5+
workflows:
6+
- Python Syntax Code Quality Check Workflow
7+
types:
8+
- completed
9+
10+
jobs:
11+
build:
12+
name: Build
13+
# runs-on: ubuntu-latest -- Used to run on Github hosting
14+
runs-on: self-hosted
15+
steps:
16+
- uses: actions/checkout@v2
17+
with:
18+
fetch-depth: 0 # Shallow clones should be disabled for a better relevancy of analysis
19+
- uses: sonarsource/sonarqube-scan-action@master
20+
env:
21+
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
22+
SONAR_HOST_URL: ${{ secrets.SONAR_HOST_URL }}
23+
# If you wish to fail your job when the Quality Gate is red, uncomment the
24+
# following lines. This would typically be used to fail a deployment.
25+
# - uses: sonarsource/sonarqube-quality-gate-action@master
26+
# timeout-minutes: 5
27+
# env:
28+
# SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
29+
30+
31+
32+
33+
34+

.github/workflows/3_build.yml

+40
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
name: Code Build Workflow
2+
3+
on:
4+
workflow_run:
5+
workflows:
6+
- Sonar Code Review Workflow
7+
types:
8+
- completed
9+
10+
jobs:
11+
build:
12+
name: Build
13+
# runs-on: ubuntu-latest -- Used to run on Github hosting
14+
runs-on: self-hosted
15+
steps:
16+
- name: Checkout code
17+
uses: actions/checkout@v2
18+
19+
- name: Docker build and push
20+
run: |
21+
docker build -t react-aws-eks-github-actions .
22+
docker tag react-aws-eks-github-actions codewithmuh/react-aws-eks-github-actions:latest
23+
docker login -u ${{ secrets.DOCKERHUB_USERNAME }} -p ${{ secrets.DOCKERHUB_TOKEN }}
24+
docker push codewithmuh/react-aws-eks-github-actions:latest
25+
env:
26+
DOCKER_CLI_ACI: 1
27+
28+
29+
- name: Pull the Docker image On AWS EC2 For tetsing of website
30+
run: docker pull sevenajay/tic-tac-toe:latest
31+
32+
33+
- name: Stop and remove existing container
34+
run: |
35+
docker stop react-aws-eks-github-actions || true
36+
docker rm react-aws-eks-github-actions || true
37+
38+
- name: Run the container on AWS EC2 for testing
39+
run: docker run -d --name react-aws-eks-github-actions -p 3000:3000 codewithmuh/react-aws-eks-github-actions:latest
40+

.github/workflows/4_trivy.yml

+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
name: Trivy Image Scan Workflow
2+
3+
on:
4+
workflow_run:
5+
workflows:
6+
# runs-on: ubuntu-latest -- Used to run on Github hosting
7+
- Code Build Workflow
8+
types:
9+
- completed
10+
11+
jobs:
12+
build:
13+
name: Docker Image Scan
14+
runs-on: self-hosted
15+
steps:
16+
- name: Checkout Repository
17+
uses: actions/checkout@v2
18+
19+
- name: Pull the Docker image From DockerHub
20+
run: docker pull codewithmuh/react-aws-eks-github-actions:latest
21+
22+
23+
- name: Trivy image scan
24+
run: trivy image codewithmuh/react-aws-eks-github-actions:latest
25+

.github/workflows/5_deploy.yml

+41
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
name: Deploy To EKS
2+
3+
on:
4+
workflow_run:
5+
workflows:
6+
- Trivy Image Scan Workflow
7+
types:
8+
- completed
9+
10+
jobs:
11+
build:
12+
name: Docker Image Scan
13+
# runs-on: ubuntu-latest -- Used to run on Github hosting
14+
runs-on: self-hosted
15+
steps:
16+
- name: Checkout Repository
17+
uses: actions/checkout@v2
18+
19+
- name: Pull the Docker image
20+
run: docker pull codewithmuh/react-aws-eks-github-actions:latest
21+
22+
23+
- name: Update kubeconfig
24+
run: aws eks --region us-west-1 update-kubeconfig --name EKS_cluster_codewithmuh
25+
26+
- name: Deploy to EKS
27+
run: kubectl apply -f deployment-service.yml
28+
29+
30+
- name: Send a Slack Notification
31+
if: always()
32+
uses: act10ns/slack@v1
33+
with:
34+
status: ${{ job.status }}
35+
steps: ${{ toJson(steps) }}
36+
channel: '#git'
37+
env:
38+
SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK_URL }}
39+
40+
41+

Dockerfile

+40
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
FROM python:3.12-slim
2+
3+
ENV PYTHONUNBUFFERED 1
4+
ENV DJANGO_SETTINGS_MODULE=backend.settings
5+
6+
RUN apt-get update && \
7+
apt-get install -y --no-install-recommends \
8+
git-core \
9+
build-essential \
10+
binutils \
11+
libproj-dev \
12+
gdal-bin \
13+
supervisor && \
14+
rm -rf /var/lib/apt/lists/*
15+
16+
COPY ./requirements /home/codewithmuh-backend/requirements
17+
RUN mkdir -p /home/codewithmuh-backend/media
18+
WORKDIR /home/codewithmuh-backend
19+
20+
21+
RUN pip install --upgrade pip
22+
RUN pip install -r ./requirements/requirements.txt
23+
24+
25+
26+
EXPOSE 8080
27+
28+
RUN mkdir -p /var/logs/codewithmuh
29+
30+
31+
COPY ./build-process/docker-backend-django/scripts /home/docker/scripts
32+
33+
RUN sed -i 's/\r$//' /home/docker/scripts/boot.sh && \
34+
chmod +x /home/docker/scripts/boot.sh
35+
36+
ENTRYPOINT /home/docker/scripts/boot.sh
37+
38+
COPY ./ /home/codewithmuh-backend
39+
40+

build-process/Dockerfile

+40
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
FROM python:3.12-slim
2+
3+
ENV PYTHONUNBUFFERED 1
4+
ENV DJANGO_SETTINGS_MODULE=backend.settings
5+
6+
RUN apt-get update && \
7+
apt-get install -y --no-install-recommends \
8+
git-core \
9+
build-essential \
10+
binutils \
11+
libproj-dev \
12+
gdal-bin \
13+
supervisor && \
14+
rm -rf /var/lib/apt/lists/*
15+
16+
COPY ./requirements /home/codewithmuh-backend/requirements
17+
RUN mkdir -p /home/codewithmuh-backend/media
18+
WORKDIR /home/codewithmuh-backend
19+
20+
21+
RUN pip install --upgrade pip
22+
RUN pip install -r ./requirements/requirements.txt
23+
24+
25+
26+
EXPOSE 8080
27+
28+
RUN mkdir -p /var/logs/codewithmuh
29+
30+
31+
COPY ./build-process/docker-backend-django/scripts /home/docker/scripts
32+
33+
RUN sed -i 's/\r$//' /home/docker/scripts/boot.sh && \
34+
chmod +x /home/docker/scripts/boot.sh
35+
36+
ENTRYPOINT /home/docker/scripts/boot.sh
37+
38+
COPY ./ /home/codewithmuh-backend
39+
40+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
[supervisord]
2+
nodaemon=true
3+
4+
[program:backend]
5+
command=gunicorn --worker-class "sync" --workers "8" --max-requests "33" --threads "4" --limit-request-line 8190 backend.wsgi:application -b 0.0.0.0:8080 --access-logfile -
6+
directory=/home/codewithmuh-backend
7+
user=root
8+
autostart=true
9+
autorestart=true
10+
stdout_logfile=/dev/stdout
11+
stdout_logfile_maxbytes=0
12+
stderr_logfile=/dev/stderr
13+
stderr_logfile_maxbytes=0
14+

build-process/scripts/boot.sh

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
#!/bin/bash
2+
set -e
3+
4+
echo "codewithmuh-backend:boot:env:${APP_ENVIRONMENT}"
5+
6+
python manage.py makemigrations
7+
8+
python manage.py migrate
9+
python manage.py collectstatic --noinput
10+
11+
if [ "$APP_ENVIRONMENT" == "Local" ]; then
12+
echo "codewithmuh-backend:run:local" && python manage.py runserver 0.0.0.0:8080 --insecure
13+
fi
14+
15+
if [ "$APP_ENVIRONMENT" == "Production" ]; then
16+
echo "codewithmuh-backend:run:prod" && /usr/bin/supervisord -c /etc/supervisor/conf.d/supervisor-backend.conf
17+
fi

sonar-project.properties

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
sonar.projectKey=django_project
2+

0 commit comments

Comments
 (0)