Skip to content

Commit fe6fe62

Browse files
authored
feat: CI/CD to GKE with multi-arch image builder, bash script (#33)
* dev: k8s agent deployment, service * dev: pv and pvc setup with gcp-pd * dev: controller deployment, service * dev: database deployment, service * dev: add Dockerfile for each module * dev: image builder and pusher script * dev: ingress pod and their routes * dev: ignore secrets * dev: gke continuous deploy workflow * fix: path rewrite #32 * fix: remove / in COPY prefix path #32 * fix: change use of build-push-action #32 * fix: test buildx path #32 * fix: rewrite Dockerfile path with -f option #32 * fix: add . end of push #32 * fix: change context path with : #32 * fix: use support option of file, version : #32 * fix: valid option reset : #32 * fix: add Dockerfile to file option : #32 * fix: remove context : #32 * fix: add . prefix : #32 * fix: add context and set default workdir : #32 * fix: add ARG for dockerfile : #32 * fix: add ARG for dockerfile : #32 * fix: arg option to build-arg : #32 * fix: remove default JAR_PATH : #32 * fix: set default JAR_PATH : #32 * fix: test echoing path : #32 * fix: remove docker build push marketplace : #32 * fix: add custom script for build multi-arch and push : #32 * fix: add sh args for getting token & etc : #32 * fix: remove QEMU and buildx plugin : #32 * fix: sh to bash : #32 * fix: image list extract with ghkdqhrbals prefix : #32 * fix: builx -f option path redefine #32 * fix: secret key #32 * fix: jar_path call with {} #32 * dev: change push to workflow_run develop branch
1 parent f789846 commit fe6fe62

File tree

16 files changed

+405
-0
lines changed

16 files changed

+405
-0
lines changed

.github/workflows/deploy.yaml

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
name: Continuous Deploy with GKE
2+
3+
on:
4+
workflow_run:
5+
workflows: [ "CI with test coverage" ]
6+
types:
7+
- completed
8+
branches:
9+
- develop
10+
11+
defaults:
12+
run:
13+
working-directory: ./
14+
15+
jobs:
16+
docker:
17+
runs-on: ubuntu-latest
18+
steps:
19+
- name: Checkout
20+
uses: actions/checkout@v4
21+
22+
- name: Set up Corretto openJDK 17
23+
uses: actions/setup-java@v3 # check specific version in https://github.com/actions/setup-java
24+
with:
25+
distribution: 'corretto'
26+
java-version: '17'
27+
28+
- name: Gradle caching
29+
uses: actions/cache@v3
30+
with:
31+
path: |
32+
~/.gradle/caches
33+
~/.gradle/wrapper
34+
key: ${{ runner.os }}-gradle-${{ hashFiles('**/*.gradle*', '**/gradle-wrapper.properties') }}
35+
restore-keys: |
36+
${{ runner.os }}-gradle-
37+
38+
- name: Grant execute permission for gradlew
39+
run: chmod +x ./gradlew
40+
41+
- name: Build and test project
42+
run: ./gradlew build
43+
44+
# - name: Set up QEMU
45+
# uses: docker/setup-qemu-action@v3
46+
#
47+
# - name: Set up Docker Buildx
48+
# uses: docker/setup-buildx-action@v3
49+
50+
- name: Build docker image and push
51+
run: bash ./script/img_push_multi_arch.sh -u ${{ secrets.DOCKERHUB_USERNAME }} -t ${{ secrets.DOCKERHUB_TOKEN }}
52+
53+
- name: Configure google cloud credentials
54+
id: auth
55+
uses: google-github-actions/auth@v2
56+
with:
57+
credentials_json: ${{ secrets.GKE_SA_KEY }}
58+
59+
- name: Set up gcloud cli
60+
uses: google-github-actions/setup-gcloud@v2
61+
62+
- name: Set GKE cluster context
63+
uses: google-github-actions/get-gke-credentials@v2
64+
with:
65+
cluster_name: ${{ secrets.GKE_CLUSTER }}
66+
location: ${{ secrets.GKE_ZONE }}
67+
68+
- name: Deploy to GKE
69+
run: |
70+
kubectl apply -f ./kubernetes/volume
71+
kubectl apply -f ./kubernetes/ingress
72+
kubectl apply -f ./kubernetes/service
73+
kubectl apply -f ./kubernetes/deploy

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
# Compiled class file
22
*.class
33
.idea
4+
/data
5+
/backups
6+
*-secret.yaml
47

58
# Log file
69
*.log

bm-agent/Dockerfile

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
FROM amazoncorretto:17-alpine3.16-jdk
2+
ARG JAR_PATH=/build/libs
3+
4+
WORKDIR /app
5+
6+
COPY ${JAR_PATH}/bm-agent-1.0.0.jar /app/app.jar
7+
8+
ENTRYPOINT java -jar app.jar

bm-controller/Dockerfile

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
FROM amazoncorretto:17-alpine3.16-jdk
2+
ARG JAR_PATH=/build/libs
3+
4+
WORKDIR /app
5+
6+
COPY ${JAR_PATH}/bm-controller-1.0.0.jar /app/app.jar
7+
8+
ENTRYPOINT java -jar app.jar

kubernetes/deploy/agent-deploy.yaml

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
apiVersion: apps/v1
2+
kind: Deployment
3+
metadata:
4+
name: agent-deployment
5+
spec:
6+
replicas: 1
7+
selector:
8+
matchLabels:
9+
app: agent-service
10+
template:
11+
metadata:
12+
labels:
13+
app: agent-service
14+
spec:
15+
containers:
16+
- env:
17+
- name: SERVER_PORT
18+
value: "8081"
19+
image: ghkdqhrbals/bm-agent:latest
20+
name: bm-agent
21+
restartPolicy: Always
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
apiVersion: apps/v1
2+
kind: Deployment
3+
metadata:
4+
name: controller-deployment
5+
spec:
6+
replicas: 1
7+
selector:
8+
matchLabels:
9+
app: controller-service
10+
template:
11+
metadata:
12+
labels:
13+
app: controller-service
14+
spec:
15+
containers:
16+
- env:
17+
- name: SERVER_PORT
18+
value: "8080"
19+
- name: spring_datasource_url
20+
value: "jdbc:postgresql://benchmark-db:5433/test"
21+
- name: spring_datasource_hikari_password
22+
valueFrom:
23+
secretKeyRef:
24+
name: db-secret
25+
key: password
26+
- name: spring_datasource_hikari_username
27+
valueFrom:
28+
secretKeyRef:
29+
name: db-secret
30+
key: username
31+
- name: token_secret
32+
valueFrom:
33+
secretKeyRef:
34+
name: token-secret
35+
key: secret
36+
- name: token_expiration_time
37+
valueFrom:
38+
secretKeyRef:
39+
name: token-secret
40+
key: exp
41+
image: ghkdqhrbals/bm-controller:latest
42+
name: bm-controller
43+
restartPolicy: Always

kubernetes/deploy/db-deployment.yaml

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
apiVersion: apps/v1
2+
kind: Deployment
3+
metadata:
4+
name: db-deployment
5+
spec:
6+
replicas: 1
7+
selector:
8+
matchLabels:
9+
app: benchmark-db
10+
template:
11+
metadata:
12+
labels:
13+
app: benchmark-db
14+
spec:
15+
# directory creation setup
16+
initContainers:
17+
- name: init-data-dir
18+
image: busybox
19+
command: ["sh", "-c", "mkdir -p /var/lib/postgresql/production/data"]
20+
volumeMounts:
21+
- name: benchmark-vol
22+
mountPath: /var/lib/postgresql/production/data
23+
containers:
24+
- args:
25+
- -c
26+
- wal_level=logical
27+
- -c
28+
- max_connections=500
29+
- -p
30+
- "5433"
31+
env:
32+
- name: POSTGRES_DB
33+
value: test
34+
- name: POSTGRES_PASSWORD
35+
valueFrom:
36+
secretKeyRef:
37+
name: db-secret
38+
key: password
39+
- name: POSTGRES_USER
40+
valueFrom:
41+
secretKeyRef:
42+
name: db-secret
43+
key: username
44+
image: postgres:12-alpine
45+
name: chat-db
46+
ports:
47+
- containerPort: 5433
48+
hostPort: 5433
49+
protocol: TCP
50+
volumeMounts:
51+
- name: benchmark-vol
52+
mountPath: /var/lib/postgresql/production/data
53+
restartPolicy: Always
54+
volumes:
55+
- name: benchmark-vol
56+
persistentVolumeClaim:
57+
claimName: benchmark-pvc

kubernetes/image_push.sh

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
#!/bin/bash
2+
3+
# Build the docker image
4+
echo "Build the docker image"
5+
PREFIX="ghkdqhrbals"
6+
docker compose -f ../docker-compose.yaml build
7+
8+
images=$(docker images --format "{{.Repository}}" | grep "^${PREFIX}")
9+
10+
# Push the docker image to docker hub
11+
echo "Image deploy to docker hub"
12+
for image in $images; do
13+
echo "${image}"
14+
docker tag "${image}" "${image}:amd64"
15+
docker push "${image}:amd64"
16+
done

kubernetes/ingress/ingress.yaml

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
apiVersion: v1
2+
kind: Pod
3+
metadata:
4+
labels:
5+
run: mynginx
6+
name: mynginx
7+
spec:
8+
containers:
9+
- image: nginx:1.16
10+
name: mynginx
11+
resources: {}
12+
restartPolicy: Always
13+
---
14+
apiVersion: v1
15+
kind: Service
16+
metadata:
17+
name: nginxsvc
18+
spec:
19+
ports:
20+
- port: 80
21+
protocol: TCP
22+
targetPort: 80
23+
selector:
24+
run: mynginx

kubernetes/ingress/routes.yaml

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
apiVersion: networking.k8s.io/v1
2+
kind: Ingress
3+
metadata:
4+
name: example
5+
spec:
6+
ingressClassName: nginx
7+
rules:
8+
- host: www.high-load.org
9+
http:
10+
paths:
11+
- pathType: Prefix
12+
backend:
13+
service:
14+
name: controller-service
15+
port:
16+
number: 80
17+
path: /

kubernetes/service/agent-service.yaml

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
apiVersion: v1
2+
kind: Service
3+
metadata:
4+
labels:
5+
app: agent-service
6+
name: agent-service
7+
spec:
8+
ports:
9+
- name: http
10+
protocol: TCP
11+
port: 8081 # This is the port that the service listens on
12+
targetPort: 8081 # This is the port that the container listens on
13+
type: ClusterIP
14+
selector:
15+
app: agent-service
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
apiVersion: v1
2+
kind: Service
3+
metadata:
4+
labels:
5+
app: controller-service
6+
name: controller-service
7+
spec:
8+
ports:
9+
- name: http
10+
protocol: TCP
11+
port: 8080
12+
targetPort: 8080
13+
nodePort: 30000 # Specify the NodePort value
14+
type: NodePort # Expose the service with a NodePort
15+
selector:
16+
app: controller-service

kubernetes/service/db-service.yaml

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
apiVersion: v1
2+
kind: Service
3+
metadata:
4+
labels:
5+
app: benchmark-db
6+
name: benchmark-db
7+
spec:
8+
ports:
9+
- name: benchmark-db
10+
protocol: TCP
11+
port: 5433
12+
targetPort: 5433
13+
selector:
14+
app: benchmark-db

kubernetes/volume/benchmark-pv.yaml

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
apiVersion: v1
2+
kind: PersistentVolume
3+
metadata:
4+
name: benchmark-pv
5+
spec:
6+
capacity:
7+
storage: 10Gi
8+
accessModes:
9+
- ReadWriteMany
10+
storageClassName: "benchmark-gce-pd-1"
11+
persistentVolumeReclaimPolicy: Retain
12+
gcePersistentDisk:
13+
pdName: pd-1 # GCE PD의 이름
14+
fsType: ext4

kubernetes/volume/benchmark-pvc.yaml

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
apiVersion: v1
2+
kind: PersistentVolumeClaim
3+
metadata:
4+
name: benchmark-pvc
5+
spec:
6+
accessModes:
7+
- ReadWriteMany
8+
volumeName: benchmark-pv
9+
resources:
10+
requests:
11+
storage: 10Gi
12+
storageClassName: "benchmark-gce-pd-1"

0 commit comments

Comments
 (0)