Skip to content

Commit e3d7488

Browse files
committed
Added deployment pipeline and documentation
1 parent 9d0b7f7 commit e3d7488

File tree

4 files changed

+122
-0
lines changed

4 files changed

+122
-0
lines changed

.github/workflows/cicd.yaml

+69
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
name: CI/CD
2+
3+
on:
4+
push:
5+
branches:
6+
- 'develop'
7+
8+
jobs:
9+
CI:
10+
name: Build and Push Docker image
11+
runs-on: ubuntu-latest
12+
13+
steps:
14+
- name: Checkout repository
15+
uses: actions/checkout@v2
16+
17+
# Include unit tests here
18+
19+
- name: Login to Docker Hub
20+
uses: docker/login-action@v3
21+
with:
22+
username: ${{ secrets.DOCKERHUB_USERNAME }}
23+
password: ${{ secrets.DOCKERHUB_TOKEN }}
24+
25+
- name: Build and push
26+
uses: docker/build-push-action@v5
27+
with:
28+
push: true
29+
tags: abdullahxy/goapp:latest
30+
31+
CD:
32+
name: Deploy API
33+
needs:
34+
- CI
35+
runs-on: ubuntu-latest
36+
37+
steps:
38+
- name: Deploy EC2
39+
run: |
40+
echo "SSH into server or bastion client... "
41+
echo "docker stop goapp"
42+
echo "docker rm goapp"
43+
echo "docker pull abdullahxy/goapp:latest"
44+
echo "docker run -d --name goapp -p 3000:80 abdullahxy/goapp:latest"
45+
echo "docker image rm abdullahxy/goapp:latest"
46+
47+
- name: Deploy Kubernetes
48+
run: |
49+
echo "helm repo add go-application <link to helm chart>"
50+
echo "helm repo update"
51+
echo "Set up kube config... "
52+
echo "helm upgrade --install --atomic --cleanup-on-fail --wait --timeout 600s
53+
<k8s deployment name> \
54+
--namespace=<k8s namespace name> \
55+
--set image=abdullahxy/goapp:latest \
56+
go-application\go-app"
57+
58+
Health-Check:
59+
name: Deploy API
60+
needs:
61+
- CD
62+
runs-on: ubuntu-latest
63+
64+
steps:
65+
- name: Ping API
66+
run: |
67+
echo "Make an HTTP request to health check path using curl or any other utility... "
68+
echo "If response in 2xx range do nothing else return non zero exit code"
69+
echo "As non zero exit code will fail this job hence pipeline fails"

Dockerfile

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
FROM golang:1.20
2+
3+
WORKDIR /app
4+
5+
COPY go.mod go.sum ./
6+
7+
RUN go mod download
8+
9+
COPY * ./
10+
11+
RUN CGO_ENABLED=0 GOOS=linux go build -o /web-server
12+
13+
CMD ["/web-server"]

README.md

+23
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,29 @@ Direct Dependencies:
1111
- Bcrypy
1212
- Golang-jwt
1313

14+
## CI/CD architecture
15+
16+
Platform: Github Actions
17+
18+
The pipeline is triggered by a push commit in `develop` branch. This includes the PRs merged into the branch. `develop` branch is a protected branch also known as the integration branch. All feature branches should be checked out and merged back from `develop` branch after being tested and approved by the relevent code owners. Currently CI/CD setup performs the following steps:
19+
20+
### CI
21+
- Checkout repository
22+
- Perform unit testing and linting (no unit tests in project as of this moment)
23+
- Login to Docker Hub
24+
- Builds Docker image using approved code
25+
- Pushes Docker image to docker hub
26+
27+
### CD
28+
- Deploy to EC2 (Explained all the steps, Does not actually deploy)
29+
- Deploy to Kubernetes (Explained all the steps, Does not actually deploy)
30+
31+
### Health check
32+
- Make an HTTP request to health check url using curl or any other utility
33+
- If response is in 2xx range then returns 0 else return non zero exit code
34+
- As non zero exit code will fail this job hence pipeline fails
35+
36+
1437
## Routes
1538

1639
### 1. /ping

docker-compose.yaml

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
version: '3.7'
2+
3+
services:
4+
api:
5+
build:
6+
context: .
7+
env_file: .env
8+
depends_on:
9+
- postgresql
10+
ports:
11+
- "3000:3000"
12+
13+
postgresql:
14+
image: postgres:12.4-alpine
15+
env_file: .env
16+
expose:
17+
- "5432"

0 commit comments

Comments
 (0)