Skip to content

Commit d3b131c

Browse files
committed
added helm chart
1 parent 2b69049 commit d3b131c

File tree

13 files changed

+379
-14
lines changed

13 files changed

+379
-14
lines changed

.github/workflows/buildAndRelease.yaml

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -38,21 +38,31 @@ jobs:
3838
3939
- name: Set up Node.js
4040
uses: actions/setup-node@v4
41-
with:
42-
node-version: latest
41+
42+
- name: Set up Helm
43+
uses: azure/setup-helm@v4.2.0
44+
45+
- name: Set up Docker
46+
uses: docker/setup-buildx-action@v2
4347

4448
- name: Install Npm dependencies
4549
run: npm install
4650

4751
- name: Run build script
4852
run: node build.mjs
4953

50-
- name: Zip the out directory
51-
if: startsWith(github.ref, 'refs/tags/v')
54+
- name: Build Web app
5255
run: |
5356
cd out
5457
zip -r ../$NAME-$VERSION.zip *
5558
59+
- name: Build Helm package
60+
run: helm package ./helm
61+
62+
- name: Build Docker image
63+
run: |
64+
docker build -t ghcr.io/${{ github.repository_owner }}/$NAME:$VERSION .
65+
5666
- name: Create GitHub Release
5767
uses: softprops/action-gh-release@v2
5868
if: startsWith(github.ref, 'refs/tags/v')
@@ -65,13 +75,6 @@ jobs:
6575
*.zip
6676
*.tgz
6777
68-
- name: Set up Docker Buildx
69-
uses: docker/setup-buildx-action@v2
70-
71-
- name: Build Docker image
72-
run: |
73-
docker build -t ghcr.io/${{ github.repository_owner }}/$NAME:$VERSION .
74-
7578
- name: Log in to GitHub Container Registry
7679
uses: docker/login-action@v3
7780
if: startsWith(github.ref, 'refs/tags/v')

.gitignore

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,4 @@
11
node_modules
2-
out
2+
out
3+
*.zip
4+
*.tgz

README.md

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,12 +36,19 @@ Just run `make run` or following commands
3636
docker run --name ${NAME} -dt --rm --init -p ${PORT}:3000 ${NAME}:latest
3737
```
3838

39+
Alternatively, you can also use `docker compose up` to start the container,
40+
by using the `docker-compose.yaml`.
41+
3942
# 🐋 Stop Docker App
4043
Just run `make stop` or following commands
4144
```
4245
docker container stop ${NAME}
4346
```
4447

48+
# Run on Kubernetes with Helm
49+
There is also a helm chart provided under `./helm` directory.
50+
51+
4552
# ⚙️ Github Release + Package
4653
Whenever a commit gets pushed to the `main` branch a workflow gets triggered, which builds the app.
4754
When a commit gets tagged with `v*.*` notation (e.g. `v1.0`) the action created a Github release
@@ -58,4 +65,6 @@ Just run `make delete_release version=v1.0` or following commands
5865
```
5966
git tag -d v1.0
6067
git push --delete origin v1.0
61-
```
68+
```
69+
70+
# ☸️ Kubernetes

docker-compose.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
services:
22
webapp:
3-
image: ghcr.io/jamowei/webapp:v1.0
3+
image: ghcr.io/jamowei/webapp:v1.0.0
44
container_name: webapp
55
ports:
66
- 3000:3000

helm/.helmignore

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
# Patterns to ignore when building packages.
2+
# This supports shell glob matching, relative path matching, and
3+
# negation (prefixed with !). Only one pattern per line.
4+
.DS_Store
5+
# Common VCS dirs
6+
.git/
7+
.gitignore
8+
.bzr/
9+
.bzrignore
10+
.hg/
11+
.hgignore
12+
.svn/
13+
# Common backup files
14+
*.swp
15+
*.bak
16+
*.tmp
17+
*.orig
18+
*~
19+
# Various IDEs
20+
.project
21+
.idea/
22+
*.tmproj
23+
.vscode/

helm/Chart.yaml

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
apiVersion: v2
2+
name: webapp
3+
description: A Helm chart for Kubernetes
4+
5+
# A chart can be either an 'application' or a 'library' chart.
6+
#
7+
# Application charts are a collection of templates that can be packaged into versioned archives
8+
# to be deployed.
9+
#
10+
# Library charts provide useful utilities or functions for the chart developer. They're included as
11+
# a dependency of application charts to inject those utilities and functions into the rendering
12+
# pipeline. Library charts do not define any templates and therefore cannot be deployed.
13+
type: application
14+
15+
# This is the chart version. This version number should be incremented each time you make changes
16+
# to the chart and its templates, including the app version.
17+
# Versions are expected to follow Semantic Versioning (https://semver.org/)
18+
version: 1.0.0
19+
20+
# This is the version number of the application being deployed. This version number should be
21+
# incremented each time you make changes to the application. Versions are not expected to
22+
# follow Semantic Versioning. They should reflect the version the application is using.
23+
# It is recommended to use it with quotes.
24+
appVersion: "1.0.0"

helm/templates/NOTES.txt

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
1. Get the application URL by running these commands:
2+
{{- if .Values.ingress.enabled }}
3+
{{- range $host := .Values.ingress.hosts }}
4+
{{- range .paths }}
5+
http{{ if $.Values.ingress.tls }}s{{ end }}://{{ $host.host }}{{ .path }}
6+
{{- end }}
7+
{{- end }}
8+
{{- else if contains "NodePort" .Values.service.type }}
9+
export NODE_PORT=$(kubectl get --namespace {{ .Release.Namespace }} -o jsonpath="{.spec.ports[0].nodePort}" services {{ include "webapp.fullname" . }})
10+
export NODE_IP=$(kubectl get nodes --namespace {{ .Release.Namespace }} -o jsonpath="{.items[0].status.addresses[0].address}")
11+
echo http://$NODE_IP:$NODE_PORT
12+
{{- else if contains "LoadBalancer" .Values.service.type }}
13+
NOTE: It may take a few minutes for the LoadBalancer IP to be available.
14+
You can watch its status by running 'kubectl get --namespace {{ .Release.Namespace }} svc -w {{ include "webapp.fullname" . }}'
15+
export SERVICE_IP=$(kubectl get svc --namespace {{ .Release.Namespace }} {{ include "webapp.fullname" . }} --template "{{"{{ range (index .status.loadBalancer.ingress 0) }}{{.}}{{ end }}"}}")
16+
echo http://$SERVICE_IP:{{ .Values.service.port }}
17+
{{- else if contains "ClusterIP" .Values.service.type }}
18+
export POD_NAME=$(kubectl get pods --namespace {{ .Release.Namespace }} -l "app.kubernetes.io/name={{ include "webapp.name" . }},app.kubernetes.io/instance={{ .Release.Name }}" -o jsonpath="{.items[0].metadata.name}")
19+
export CONTAINER_PORT=$(kubectl get pod --namespace {{ .Release.Namespace }} $POD_NAME -o jsonpath="{.spec.containers[0].ports[0].containerPort}")
20+
echo "Visit http://127.0.0.1:8080 to use your application"
21+
kubectl --namespace {{ .Release.Namespace }} port-forward $POD_NAME 8080:$CONTAINER_PORT
22+
{{- end }}

helm/templates/_helpers.tpl

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
{{/*
2+
Expand the name of the chart.
3+
*/}}
4+
{{- define "webapp.name" -}}
5+
{{- default .Chart.Name .Values.nameOverride | trunc 63 | trimSuffix "-" }}
6+
{{- end }}
7+
8+
{{/*
9+
Create a default fully qualified app name.
10+
We truncate at 63 chars because some Kubernetes name fields are limited to this (by the DNS naming spec).
11+
If release name contains chart name it will be used as a full name.
12+
*/}}
13+
{{- define "webapp.fullname" -}}
14+
{{- if .Values.fullnameOverride }}
15+
{{- .Values.fullnameOverride | trunc 63 | trimSuffix "-" }}
16+
{{- else }}
17+
{{- $name := default .Chart.Name .Values.nameOverride }}
18+
{{- if contains $name .Release.Name }}
19+
{{- .Release.Name | trunc 63 | trimSuffix "-" }}
20+
{{- else }}
21+
{{- printf "%s-%s" .Release.Name $name | trunc 63 | trimSuffix "-" }}
22+
{{- end }}
23+
{{- end }}
24+
{{- end }}
25+
26+
{{/*
27+
Create chart name and version as used by the chart label.
28+
*/}}
29+
{{- define "webapp.chart" -}}
30+
{{- printf "%s-%s" .Chart.Name .Chart.Version | replace "+" "_" | trunc 63 | trimSuffix "-" }}
31+
{{- end }}
32+
33+
{{/*
34+
Common labels
35+
*/}}
36+
{{- define "webapp.labels" -}}
37+
helm.sh/chart: {{ include "webapp.chart" . }}
38+
{{ include "webapp.selectorLabels" . }}
39+
{{- if .Chart.AppVersion }}
40+
app.kubernetes.io/version: {{ .Chart.AppVersion | quote }}
41+
{{- end }}
42+
app.kubernetes.io/managed-by: {{ .Release.Service }}
43+
{{- end }}
44+
45+
{{/*
46+
Selector labels
47+
*/}}
48+
{{- define "webapp.selectorLabels" -}}
49+
app.kubernetes.io/name: {{ include "webapp.name" . }}
50+
app.kubernetes.io/instance: {{ .Release.Name }}
51+
{{- end }}
52+
53+
{{/*
54+
Create the name of the service account to use
55+
*/}}
56+
{{- define "webapp.serviceAccountName" -}}
57+
{{- if .Values.serviceAccount.create }}
58+
{{- default (include "webapp.fullname" .) .Values.serviceAccount.name }}
59+
{{- else }}
60+
{{- default "default" .Values.serviceAccount.name }}
61+
{{- end }}
62+
{{- end }}

helm/templates/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: {{ include "webapp.fullname" . }}
5+
labels:
6+
{{- include "webapp.labels" . | nindent 4 }}
7+
spec:
8+
replicas: {{ .Values.replicaCount }}
9+
selector:
10+
matchLabels:
11+
{{- include "webapp.selectorLabels" . | nindent 6 }}
12+
template:
13+
metadata:
14+
{{- with .Values.podAnnotations }}
15+
annotations:
16+
{{- toYaml . | nindent 8 }}
17+
{{- end }}
18+
labels:
19+
{{- include "webapp.labels" . | nindent 8 }}
20+
{{- with .Values.podLabels }}
21+
{{- toYaml . | nindent 8 }}
22+
{{- end }}
23+
spec:
24+
{{- with .Values.imagePullSecrets }}
25+
imagePullSecrets:
26+
{{- toYaml . | nindent 8 }}
27+
{{- end }}
28+
securityContext:
29+
{{- toYaml .Values.podSecurityContext | nindent 8 }}
30+
containers:
31+
- name: {{ .Chart.Name }}
32+
securityContext:
33+
{{- toYaml .Values.securityContext | nindent 12 }}
34+
image: "{{ .Values.image.repository }}:{{ .Values.image.tag | default .Chart.AppVersion }}"
35+
imagePullPolicy: {{ .Values.image.pullPolicy }}
36+
ports:
37+
- name: http
38+
containerPort: {{ .Values.service.port }}
39+
protocol: TCP
40+
livenessProbe:
41+
{{- toYaml .Values.livenessProbe | nindent 12 }}
42+
readinessProbe:
43+
{{- toYaml .Values.readinessProbe | nindent 12 }}
44+
resources:
45+
{{- toYaml .Values.resources | nindent 12 }}
46+
{{- with .Values.nodeSelector }}
47+
nodeSelector:
48+
{{- toYaml . | nindent 8 }}
49+
{{- end }}
50+
{{- with .Values.affinity }}
51+
affinity:
52+
{{- toYaml . | nindent 8 }}
53+
{{- end }}
54+
{{- with .Values.tolerations }}
55+
tolerations:
56+
{{- toYaml . | nindent 8 }}
57+
{{- end }}

helm/templates/ingress.yaml

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
{{- if .Values.ingress.enabled -}}
2+
apiVersion: networking.k8s.io/v1
3+
kind: Ingress
4+
metadata:
5+
name: {{ include "webapp.fullname" . }}
6+
labels:
7+
{{- include "webapp.labels" . | nindent 4 }}
8+
{{- with .Values.ingress.annotations }}
9+
annotations:
10+
{{- toYaml . | nindent 4 }}
11+
{{- end }}
12+
spec:
13+
{{- with .Values.ingress.className }}
14+
ingressClassName: {{ . }}
15+
{{- end }}
16+
{{- if .Values.ingress.tls }}
17+
tls:
18+
{{- range .Values.ingress.tls }}
19+
- hosts:
20+
{{- range .hosts }}
21+
- {{ . | quote }}
22+
{{- end }}
23+
secretName: {{ .secretName }}
24+
{{- end }}
25+
{{- end }}
26+
rules:
27+
{{- range .Values.ingress.hosts }}
28+
- host: {{ .host | quote }}
29+
http:
30+
paths:
31+
{{- range .paths }}
32+
- path: {{ .path }}
33+
{{- with .pathType }}
34+
pathType: {{ . }}
35+
{{- end }}
36+
backend:
37+
service:
38+
name: {{ include "webapp.fullname" $ }}
39+
port:
40+
number: {{ $.Values.service.port }}
41+
{{- end }}
42+
{{- end }}
43+
{{- end }}

helm/templates/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+
name: {{ include "webapp.fullname" . }}
5+
labels:
6+
{{- include "webapp.labels" . | nindent 4 }}
7+
spec:
8+
type: {{ .Values.service.type }}
9+
ports:
10+
- port: {{ .Values.service.port }}
11+
targetPort: http
12+
protocol: TCP
13+
name: http
14+
selector:
15+
{{- include "webapp.selectorLabels" . | nindent 4 }}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
apiVersion: v1
2+
kind: Pod
3+
metadata:
4+
name: "{{ include "webapp.fullname" . }}-test-connection"
5+
labels:
6+
{{- include "webapp.labels" . | nindent 4 }}
7+
annotations:
8+
"helm.sh/hook": test
9+
spec:
10+
containers:
11+
- name: wget
12+
image: busybox
13+
command: ['wget']
14+
args: ['{{ include "webapp.fullname" . }}:{{ .Values.service.port }}']
15+
restartPolicy: Never

0 commit comments

Comments
 (0)