Skip to content

Commit 159e68c

Browse files
committed
Add Github Actions CI for CI/CD
1 parent c3027bc commit 159e68c

File tree

6 files changed

+128
-20
lines changed

6 files changed

+128
-20
lines changed

.dockerignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,5 @@ src/master/venv/
44
.git/
55
# tags
66
tag*
7+
# build folder
8+
build/

.github/workflows/ci-pipeline.yml

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
#
2+
# k8s-cms
3+
# Github Actions: CI pipeline
4+
#
5+
6+
name: ci-pipeline
7+
on: [ push, pull_request ]
8+
env:
9+
# container build args
10+
VERSION: latest
11+
N_CONCURRENT: 12
12+
DOCKER_REGISTRY: "docker.io"
13+
DOCKER_USER: mrzzy
14+
15+
jobs:
16+
## build pipiline
17+
# build cms containers
18+
build-containers:
19+
runs-on: ubuntu-18.04
20+
steps:
21+
- uses: actions/checkout@v2
22+
with:
23+
submodules: recursive
24+
- name: "Build Containers"
25+
run: |
26+
make -j ${N_CONCURRENT}
27+
make export
28+
df -h
29+
free -h
30+
- uses: actions/upload-artifact@v1
31+
with:
32+
name: containers
33+
path: build/containers
34+
35+
## helm chart
36+
# lints helm chart
37+
lint-helm-chart:
38+
runs-on: ubuntu-18.04
39+
steps:
40+
- uses: actions/checkout@v2
41+
- name: "Pull dependencies"
42+
run: |
43+
# pull helm
44+
curl -fsSL https://raw.githubusercontent.com/helm/helm/master/scripts/get-helm-3 | bash -
45+
- name: "Lint Helm chart"
46+
run: |
47+
helm lint chart
48+
49+
## release pipeline - run only on main repo
50+
publish-containers:
51+
#if: github.repository == "np-overflow/k8s-cms" && github.head_ref == "master"
52+
runs-on: ubuntu-18.04
53+
needs:
54+
- build-containers
55+
steps:
56+
- uses: actions/checkout@v2
57+
- uses: actions/download-artifact@v1
58+
with:
59+
name: containers
60+
path: build/containers
61+
- name: "Push Containers to Dockerhub"
62+
env:
63+
DOCKER_TOKEN: "${{ secrets.DOCKER_TOKEN }}"
64+
run: |
65+
make load
66+
echo "$DOCKER_TOKEN" | docker login -u "$DOCKER_USER" --password-stdin
67+
make push -j ${N_CONCURRENT}
68+

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,3 +8,5 @@ tags*
88
charts/
99
# ccls cache
1010
.ccls-cache/
11+
# build folder
12+
build/

chart/Chart.lock

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
dependencies:
2+
- name: nginx-ingress
3+
repository: https://kubernetes-charts.storage.googleapis.com
4+
version: 1.28.2
5+
- name: cert-manager
6+
repository: https://charts.jetstack.io
7+
version: v0.12.0
8+
- name: prometheus-operator
9+
repository: https://kubernetes-charts.storage.googleapis.com
10+
version: 8.5.4
11+
digest: sha256:0e8987ebbff72192ebb651ec5110187d4d7bb9b87dbfa962c569b5b0dd79c67c
12+
generated: "2020-01-09T20:59:57.36369708+08:00"

docker-compose.yml

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ services:
1010
build:
1111
context: .
1212
dockerfile: containers/cms-db/Dockerfile
13-
image: "mrzzy/cms-db"
13+
image: "docker.io/mrzzy/cms-db:latest"
1414
expose:
1515
- "5432"
1616
env_file:
@@ -26,7 +26,7 @@ services:
2626
build:
2727
context: .
2828
dockerfile: containers/cms-log/Dockerfile
29-
image: "mrzzy/cms-log"
29+
image: "docker.io/mrzzy/cms-log:latest"
3030
env_file:
3131
- ".env"
3232
- "config/config.env"
@@ -38,7 +38,7 @@ services:
3838
build:
3939
context: .
4040
dockerfile: containers/cms-scoring/Dockerfile
41-
image: "mrzzy/cms-scoring"
41+
image: "docker.io/mrzzy/cms-scoring:latest"
4242
env_file:
4343
- ".env"
4444
- "config/config.env"
@@ -50,7 +50,7 @@ services:
5050
build:
5151
context: .
5252
dockerfile: containers/cms-resource/Dockerfile
53-
image: "mrzzy/cms-resource"
53+
image: "docker.io/mrzzy/cms-resource:latest"
5454
env_file:
5555
- ".env"
5656
- "config/config.env"
@@ -62,7 +62,7 @@ services:
6262
build:
6363
context: .
6464
dockerfile: containers/cms-proxy/Dockerfile
65-
image: "mrzzy/cms-proxy"
65+
image: "docker.io/mrzzy/cms-proxy:latest"
6666
env_file:
6767
- ".env"
6868
- "config/config.env"
@@ -75,7 +75,7 @@ services:
7575
build:
7676
context: .
7777
dockerfile: containers/cms-printing/Dockerfile
78-
image: "mrzzy/cms-printing"
78+
image: "docker.io/mrzzy/cms-printing:latest"
7979
env_file:
8080
- ".env"
8181
- "config/config.env"
@@ -87,7 +87,7 @@ services:
8787
build:
8888
context: .
8989
dockerfile: containers/cms-evaluation/Dockerfile
90-
image: "mrzzy/cms-evaluation"
90+
image: "docker.io/mrzzy/cms-evaluation:latest"
9191
env_file:
9292
- ".env"
9393
- "config/config.env"
@@ -99,7 +99,7 @@ services:
9999
build:
100100
context: .
101101
dockerfile: containers/cms-checker/Dockerfile
102-
image: "mrzzy/cms-checker"
102+
image: "docker.io/mrzzy/cms-checker:latest"
103103
env_file:
104104
- ".env"
105105
- "config/config.env"
@@ -124,7 +124,7 @@ services:
124124
build:
125125
context: .
126126
dockerfile: containers/cms-web-ranking/Dockerfile
127-
image: "mrzzy/cms-web-ranking"
127+
image: "docker.io/mrzzy/cms-web-ranking:latest"
128128
env_file:
129129
- ".env"
130130
- "config/config.env"
@@ -136,7 +136,7 @@ services:
136136
build:
137137
context: .
138138
dockerfile: containers/cms-web-admin/Dockerfile
139-
image: "mrzzy/cms-web-admin"
139+
image: "docker.io/mrzzy/cms-web-admin:latest"
140140
ports:
141141
- "8889:8889"
142142
expose:
@@ -150,7 +150,7 @@ services:
150150
build:
151151
context: .
152152
dockerfile: containers/cms-web-contest/Dockerfile
153-
image: "mrzzy/cms-web-contest"
153+
image: "docker.io/mrzzy/cms-web-contest:latest"
154154
ports:
155155
- "8888:8888"
156156
expose:
@@ -166,7 +166,7 @@ services:
166166
build:
167167
context: .
168168
dockerfile: containers/cms-worker/Dockerfile
169-
image: "mrzzy/cms-worker"
169+
image: "docker.io/mrzzy/cms-worker:latest"
170170
expose:
171171
- "26000"
172172
env_file:
@@ -183,7 +183,7 @@ services:
183183
build:
184184
context: .
185185
dockerfile: containers/cms-worker/Dockerfile
186-
image: "mrzzy/cms-worker"
186+
image: "docker.io/mrzzy/cms-worker:latest"
187187
expose:
188188
- "26000"
189189
env_file:
@@ -201,7 +201,7 @@ services:
201201
build:
202202
context: .
203203
dockerfile: containers/k8s-cms-master/Dockerfile
204-
image: "mrzzy/k8s-cms-master"
204+
image: "docker.io/mrzzy/k8s-cms-master:latest"
205205
ports:
206206
- "5000:5000"
207207
env_file:

makefile

Lines changed: 30 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,25 +4,31 @@
44
#
55

66
# vars
7-
VERSION:=0.4.0b
7+
VERSION:=latest
8+
89

910
DOCKER:=docker
10-
TAG_PREFIX:=mrzzy
11+
DOCKER_REGISTRY:=docker.io
12+
DOCKER_USER:=mrzzy
13+
TAG_PREFIX:=$(DOCKER_REGISTRY)/$(DOCKER_USER)
1114

1215
CMS_SRC_DIR:=deps/cms/
16+
EXPORT_DIR:=build/containers
1317

1418
# names of the docker images
1519
IMG_NAMES:=$(notdir $(wildcard containers/*))
1620
IMAGES:=$(foreach img,$(IMG_NAMES),$(TAG_PREFIX)/$(img))
1721
BASE_IMAGE:=$(TAG_PREFIX)/cms-base
1822
# names of the images that depends on base image
19-
DEP_BASE_NAMES:=$(filter-out cms-base,$(filter-out cms-db, $(IMG_NAMES)))
23+
DEP_BASE_NAMES:=$(filter-out cms-base, $(IMG_NAMES))
2024
DEP_BASE_IMAGES:=$(foreach img,$(DEP_BASE_NAMES),$(TAG_PREFIX)/$(img))
2125

2226
PUSH_TARGETS:=$(foreach img,$(IMAGES),push/$(img))
27+
EXPORT_TARGETS:=$(foreach img,$(IMAGES),export/$(img))
28+
LOAD_TARGETS:=$(foreach img,$(IMAGES),load/$(img))
2329

2430
# phony rules
25-
.PHONY: all push clean clean-version
31+
.PHONY: all push clean clean-version export load
2632
.DEFAULT: all
2733

2834
all: $(DEP_BASE_IMAGES)
@@ -41,9 +47,27 @@ $(TAG_PREFIX)/%: containers/%/Dockerfile $(CMS_SRC_DIR)
4147
# docker push rule
4248
push: $(PUSH_TARGETS)
4349

44-
push/%: %
45-
docker push $<
50+
push/%:
51+
docker push $(subst push/,,$@)
52+
53+
# export docker images as tar archive
54+
export: $(EXPORT_TARGETS)
55+
56+
export/%:
57+
mkdir -p $(EXPORT_DIR)
58+
docker save $(subst export/,,$@):$(VERSION) | gzip > $(EXPORT_DIR)/$(notdir $@).tgz
59+
@# purge built docker image layers
60+
@# necessary due to disk limit in github acti
61+
docker rmi -f $(subst export/,,$@):$(VERSION)
62+
63+
# load docker images from a tar archive
64+
load: $(LOAD_TARGETS)
4665

66+
load/%:
67+
zcat $(EXPORT_DIR)/$(notdir $@).tgz | docker load
68+
@# auto delete the tgz file after import to reduce disk consumption
69+
@# necessary due to disk limit in github actions
70+
rm -f $(EXPORT_DIR)/$(notdir $@).tar
4771

4872
# cleans docker images
4973
# clean all docker images

0 commit comments

Comments
 (0)