Skip to content

Commit 0952e2c

Browse files
authoredJun 1, 2022
feat: add helm deployment setup (#20)
* feat: set indent_size for yaml files * feat: init helm chart * fix: update wrong value * fix: udpate litestream settings
1 parent cd68f69 commit 0952e2c

9 files changed

+344
-0
lines changed
 

‎.editorconfig

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
root = true
2+
3+
[*.{yaml,yml}]
4+
indent_size = 2

‎charts/sqlite-rest/.helmignore

+23
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/

‎charts/sqlite-rest/Chart.yaml

+27
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
apiVersion: v2
2+
name: sqlite-rest
3+
description: A Helm chart for sqlite-rest
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: 0.1.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.16.0"
25+
26+
sources:
27+
- "https://github.com/b4fun/sqlite-rest"
+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
1. Get the application URL by running these commands:
2+
{{- if contains "NodePort" .Values.service.type }}
3+
export NODE_PORT=$(kubectl get --namespace {{ .Release.Namespace }} -o jsonpath="{.spec.ports[0].nodePort}" services {{ include "sqlite-rest.fullname" . }})
4+
export NODE_IP=$(kubectl get nodes --namespace {{ .Release.Namespace }} -o jsonpath="{.items[0].status.addresses[0].address}")
5+
echo http://$NODE_IP:$NODE_PORT
6+
{{- else if contains "LoadBalancer" .Values.service.type }}
7+
NOTE: It may take a few minutes for the LoadBalancer IP to be available.
8+
You can watch the status of by running 'kubectl get --namespace {{ .Release.Namespace }} svc -w {{ include "sqlite-rest.fullname" . }}'
9+
export SERVICE_IP=$(kubectl get svc --namespace {{ .Release.Namespace }} {{ include "sqlite-rest.fullname" . }} --template "{{"{{ range (index .status.loadBalancer.ingress 0) }}{{.}}{{ end }}"}}")
10+
echo http://$SERVICE_IP:{{ .Values.service.port }}
11+
{{- else if contains "ClusterIP" .Values.service.type }}
12+
export POD_NAME=$(kubectl get pods --namespace {{ .Release.Namespace }} -l "app.kubernetes.io/name={{ include "sqlite-rest.name" . }},app.kubernetes.io/instance={{ .Release.Name }}" -o jsonpath="{.items[0].metadata.name}")
13+
export CONTAINER_PORT=$(kubectl get pod --namespace {{ .Release.Namespace }} $POD_NAME -o jsonpath="{.spec.containers[0].ports[0].containerPort}")
14+
echo "Visit http://127.0.0.1:8080 to use your application"
15+
kubectl --namespace {{ .Release.Namespace }} port-forward $POD_NAME 8080:$CONTAINER_PORT
16+
{{- end }}
+51
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
{{/*
2+
Expand the name of the chart.
3+
*/}}
4+
{{- define "sqlite-rest.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 "sqlite-rest.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 "sqlite-rest.chart" -}}
30+
{{- printf "%s-%s" .Chart.Name .Chart.Version | replace "+" "_" | trunc 63 | trimSuffix "-" }}
31+
{{- end }}
32+
33+
{{/*
34+
Common labels
35+
*/}}
36+
{{- define "sqlite-rest.labels" -}}
37+
helm.sh/chart: {{ include "sqlite-rest.chart" . }}
38+
{{ include "sqlite-rest.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 "sqlite-rest.selectorLabels" -}}
49+
app.kubernetes.io/name: {{ include "sqlite-rest.name" . }}
50+
app.kubernetes.io/instance: {{ .Release.Name }}
51+
{{- end }}
+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
apiVersion: v1
2+
kind: Service
3+
metadata:
4+
name: {{ include "sqlite-rest.fullname" . }}
5+
labels:
6+
{{- include "sqlite-rest.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 "sqlite-rest.selectorLabels" . | nindent 4 }}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
apiVersion: v1
2+
kind: ServiceAccount
3+
metadata:
4+
name: {{ .Values.serviceAccount.name }}
5+
labels:
6+
{{- include "sqlite-rest.labels" . | nindent 4 }}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,152 @@
1+
apiVersion: apps/v1
2+
kind: StatefulSet
3+
metadata:
4+
name: {{ include "sqlite-rest.fullname" . }}
5+
labels:
6+
{{- include "sqlite-rest.labels" . | nindent 4 }}
7+
spec:
8+
selector:
9+
matchLabels:
10+
{{- include "sqlite-rest.selectorLabels" . | nindent 6 }}
11+
serviceName: {{ include "sqlite-rest.name" . }}
12+
13+
replicas: 1
14+
15+
volumeClaimTemplates:
16+
{{- if .Values.data.enabled }}
17+
- metadata:
18+
name: data
19+
spec:
20+
accessModes: ["ReadWriteOnce"]
21+
{{- if .Values.data.storageClassName }}
22+
storageClassName: {{ .Values.data.storageClassName }}
23+
{{- end }}
24+
resources:
25+
{{- toYaml .Values.data.resource | nindent 10 }}
26+
{{- end }}
27+
28+
template:
29+
metadata:
30+
labels:
31+
{{- include "sqlite-rest.selectorLabels" . | nindent 8 }}
32+
spec:
33+
volumes:
34+
{{- if .Values.server.secretNameAuthToken }}
35+
- name: auth-token-file
36+
secret:
37+
secretName: {{ .Values.server.secretNameAuthToken }}
38+
{{- end }}
39+
{{- if .Values.server.secretNameAuthRSAPublicKey }}
40+
- name: auth-rsa-public-key
41+
secret:
42+
secretName: {{ .Values.server.secretNameAuthRSAPublicKey }}
43+
{{- end }}
44+
{{- if (not .Values.data.enabled) }}
45+
- name: data
46+
emptyDir: {}
47+
{{- end }}
48+
{{- if .Values.migrations.enabled }}
49+
- name: migrations
50+
configMap:
51+
name: {{ .Values.migrations.configMapName }}
52+
{{- end }}
53+
{{- if .Values.litestream.enabled }}
54+
- name: litestream-config
55+
secret:
56+
secretName: {{ .Values.litestream.secretName }}
57+
{{- end }}
58+
initContainers:
59+
{{- if .Values.litestream.enabled }}
60+
- name: litestream-init
61+
image: {{ .Values.litestream.image.repository }}:{{ .Values.litestream.image.tag }}
62+
imagePullPolicy: {{ .Values.litestream.image.pullPolicy }}
63+
args:
64+
- restore
65+
- '-if-db-not-exists'
66+
- '-if-replica-exists'
67+
- '-v'
68+
- '/data/db.sqlite3'
69+
volumeMounts:
70+
- name: data
71+
mountPath: /data
72+
- name: litestream-config
73+
mountPath: /etc/litestream.yml
74+
subPath: litestream.yml
75+
{{- end }}
76+
{{- if .Values.migrations.enabled }}
77+
- name: migrations
78+
image: "{{ .Values.image.repository }}:{{ .Values.image.tag | default .Chart.AppVersion }}"
79+
imagePullPolicy: {{ .Values.image.pullPolicy }}
80+
command:
81+
- sqlite-rest-server
82+
- migrate
83+
args:
84+
- /migrations
85+
- --db-dsn=/data/db.sqlite3
86+
- --log-level={{ .Values.server.logLevel }}
87+
- --log-devel={{ .Values.server.useDevelLog }}
88+
volumeMounts:
89+
- name: data
90+
mountPath: /data
91+
- name: migrations
92+
mountPath: /migrations
93+
{{- end }}
94+
containers:
95+
- name: server
96+
image: "{{ .Values.image.repository }}:{{ .Values.image.tag | default .Chart.AppVersion }}"
97+
imagePullPolicy: {{ .Values.image.pullPolicy }}
98+
command:
99+
- sqlite-rest-server
100+
- serve
101+
args:
102+
- --db-dsn=/data/db.sqlite3
103+
- --security-allow-table={{ .Values.server.securityAllowTable }}
104+
- --log-level={{ .Values.server.logLevel }}
105+
- --log-devel={{ .Values.server.useDevelLog }}
106+
{{- if .Values.server.secretNameAuthToken }}
107+
- --auth-token-file=/auth-token
108+
{{- end }}
109+
{{- if .Values.server.secretNameAuthRSAPublicKey }}
110+
- --auth-rsa-public-key=/auth-rsa-public-key
111+
{{- end }}
112+
ports:
113+
- name: http
114+
containerPort: 8080
115+
protocol: TCP
116+
resources:
117+
{{- toYaml .Values.resources | nindent 12 }}
118+
volumeMounts:
119+
- name: data
120+
mountPath: /data
121+
{{- if .Values.server.secretNameAuthToken }}
122+
- name: auth-token-file
123+
mountPath: /auth-token
124+
subPath: auth.yaml
125+
readOnly: true
126+
{{- end }}
127+
{{- if .Values.server.secretNameAuthRSAPublicKey }}
128+
- name: auth-rsa-public-key
129+
mountPath: /auth-rsa-public-key
130+
subPath: auth.yaml
131+
readOnly: true
132+
{{- end }}
133+
{{- if .Values.litestream.enabled }}
134+
- name: litestream
135+
image: {{ .Values.litestream.image.repository }}:{{ .Values.litestream.image.tag }}
136+
imagePullPolicy: {{ .Values.litestream.image.pullPolicy }}
137+
args:
138+
- replicate
139+
volumeMounts:
140+
- name: data
141+
mountPath: /data
142+
- name: litestream-config
143+
mountPath: /etc/litestream.yml
144+
subPath: litestream.yml
145+
ports:
146+
- name: ls-metrics
147+
containerPort: 9090
148+
{{- end }}
149+
{{- with .Values.nodeSelector }}
150+
nodeSelector:
151+
{{- toYaml . | nindent 8 }}
152+
{{- end }}

‎charts/sqlite-rest/values.yaml

+50
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
server:
2+
logLevel: 5
3+
useDevelLog: true
4+
secretNameAuthToken: ""
5+
secretNameAuthRSAPublicKey: ""
6+
securityAllowTable: ""
7+
8+
migrations:
9+
enabled: false
10+
configMapName: sqlite-rest-migrations
11+
12+
litestream:
13+
enabled: false
14+
image:
15+
repository: litestream/litestream
16+
pullPolicy: IfNotPresent
17+
tag: "0.3.6"
18+
secretName: sqlite-rest-litestream-config
19+
20+
data:
21+
enabled: false
22+
storageClassName: ""
23+
resource:
24+
requests:
25+
storage: "100Mi"
26+
27+
labels:
28+
build4.fun/app: sqlite-rest
29+
30+
image:
31+
repository: ghcr.io/b4fun/sqlite-rest/server
32+
pullPolicy: IfNotPresent
33+
tag: "v0.1.0"
34+
35+
service:
36+
type: ClusterIP
37+
port: 8080
38+
39+
serviceAccount:
40+
name: sqlite-rest-server
41+
42+
resources:
43+
limits:
44+
memory: 512Mi
45+
requests:
46+
cpu: 100m
47+
memory: 20Mi
48+
49+
nodeSelector:
50+
kubernetes.io/os: linux

0 commit comments

Comments
 (0)
Please sign in to comment.