From 9e7903d02e01bb7c18da51a6320fefb5c097ab33 Mon Sep 17 00:00:00 2001
From: Janne Mareike Koschinski <janne@kuschku.de>
Date: Thu, 12 May 2022 01:15:39 +0200
Subject: [PATCH] feat: port actual-budget

---
 .gitlab-ci.yml                   |  1 +
 actual/Chart.yaml                |  6 +++
 actual/pipeline.yml              | 12 ++++++
 actual/templates/_helpers.tpl    | 56 ++++++++++++++++++++++++
 actual/templates/configmap.yaml  | 16 +++++++
 actual/templates/deployment.yaml | 74 ++++++++++++++++++++++++++++++++
 actual/templates/ingress.yaml    | 20 +++++++++
 actual/templates/service.yaml    | 15 +++++++
 actual/values.yaml               | 49 +++++++++++++++++++++
 9 files changed, 249 insertions(+)
 create mode 100644 actual/Chart.yaml
 create mode 100644 actual/pipeline.yml
 create mode 100644 actual/templates/_helpers.tpl
 create mode 100644 actual/templates/configmap.yaml
 create mode 100644 actual/templates/deployment.yaml
 create mode 100644 actual/templates/ingress.yaml
 create mode 100644 actual/templates/service.yaml
 create mode 100644 actual/values.yaml

diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml
index 9d11548..75be8c3 100644
--- a/.gitlab-ci.yml
+++ b/.gitlab-ci.yml
@@ -7,6 +7,7 @@ stages:
   - lint
   - release
 include:
+- actual/pipeline.yml
 - jellyfin/pipeline.yml
 - mailu/pipeline.yml
 - oauth2-proxy/pipeline.yml
diff --git a/actual/Chart.yaml b/actual/Chart.yaml
new file mode 100644
index 0000000..abbfddf
--- /dev/null
+++ b/actual/Chart.yaml
@@ -0,0 +1,6 @@
+apiVersion: v2
+name: actual
+description: Helm Chart for actual
+type: application
+version: 1.0.0
+appVersion: "134b9fcc"
diff --git a/actual/pipeline.yml b/actual/pipeline.yml
new file mode 100644
index 0000000..b768c27
--- /dev/null
+++ b/actual/pipeline.yml
@@ -0,0 +1,12 @@
+lint-actual:
+  stage: lint
+  script:
+    - helm lint actual
+
+release-actual:
+  stage: release
+  script:
+    - apk add --no-cache git
+    - helm plugin install https://github.com/chartmuseum/helm-push.git
+    - helm repo add --username gitlab-ci-token --password $CI_JOB_TOKEN repo ${CI_API_V4_URL}/projects/${CI_PROJECT_ID}/packages/helm/stable
+    - helm cm-push actual repo
diff --git a/actual/templates/_helpers.tpl b/actual/templates/_helpers.tpl
new file mode 100644
index 0000000..65f41dc
--- /dev/null
+++ b/actual/templates/_helpers.tpl
@@ -0,0 +1,56 @@
+{{/*
+Expand the name of the chart.
+*/}}
+{{- define "actual-helm.name" -}}
+{{- default .Chart.Name .Values.nameOverride | trunc 63 | trimSuffix "-" }}
+{{- end }}
+
+{{/*
+Create a default fully qualified app name.
+We truncate at 63 chars because some Kubernetes name fields are limited to this (by the DNS naming spec).
+If release name contains chart name it will be used as a full name.
+*/}}
+{{- define "actual-helm.fullname" -}}
+{{- if .Values.fullnameOverride }}
+{{- .Values.fullnameOverride | trunc 63 | trimSuffix "-" }}
+{{- else }}
+{{- $name := default .Chart.Name .Values.nameOverride }}
+{{- if contains $name .Release.Name }}
+{{- .Release.Name | trunc 63 | trimSuffix "-" }}
+{{- else }}
+{{- printf "%s-%s" .Release.Name $name | trunc 63 | trimSuffix "-" }}
+{{- end }}
+{{- end }}
+{{- end }}
+
+{{/*
+Create chart name and version as used by the chart label.
+*/}}
+{{- define "actual-helm.chart" -}}
+{{- printf "%s-%s" .Chart.Name .Chart.Version | replace "+" "_" | trunc 63 | trimSuffix "-" }}
+{{- end }}
+
+{{/*
+Common labels
+*/}}
+{{- define "actual-helm.labels" -}}
+helm.sh/chart: {{ include "actual-helm.chart" . }}
+{{ include "actual-helm.selectorLabels" . }}
+{{- if .Chart.AppVersion }}
+app.kubernetes.io/version: {{ .Chart.AppVersion | quote }}
+{{- end }}
+app.kubernetes.io/managed-by: {{ .Release.Service }}
+{{- end }}
+
+{{/*
+Selector labels
+*/}}
+{{- define "actual-helm.selectorLabels" -}}
+app.kubernetes.io/name: {{ include "actual-helm.name" . }}
+app.kubernetes.io/instance: {{ .Release.Name }}
+{{- end }}
+
+
+{{- define "actual-helm.sslPath" -}}
+/certs
+{{- end }}
diff --git a/actual/templates/configmap.yaml b/actual/templates/configmap.yaml
new file mode 100644
index 0000000..1a53ff3
--- /dev/null
+++ b/actual/templates/configmap.yaml
@@ -0,0 +1,16 @@
+apiVersion: v1
+kind: ConfigMap
+metadata:
+  name: {{ include "actual-helm.fullname" . }}
+  labels:
+    {{- include "actual-helm.labels" . | nindent 4 }}
+data:
+  "config.json": |-
+    {
+      "mode": "production",
+      "port": 8080,
+      "hostname": "0.0.0.0",
+      "serverFiles": "/data/server-files",
+      "userFiles": "/data/user-files",
+      "sync": "{{ .Values.syncMode }}"
+    }
diff --git a/actual/templates/deployment.yaml b/actual/templates/deployment.yaml
new file mode 100644
index 0000000..cd4919e
--- /dev/null
+++ b/actual/templates/deployment.yaml
@@ -0,0 +1,74 @@
+apiVersion: apps/v1
+kind: Deployment
+metadata:
+  name: {{ include "actual-helm.fullname" . }}
+  labels:
+    {{- include "actual-helm.labels" . | nindent 4 }}
+spec:
+  replicas: {{ .Values.replicaCount }}
+  selector:
+    matchLabels:
+      {{- include "actual-helm.selectorLabels" . | nindent 6 }}
+  template:
+    metadata:
+      {{- with .Values.podAnnotations }}
+      annotations:
+        {{- toYaml . | nindent 8 }}
+      {{- end }}
+      labels:
+        {{- include "actual-helm.selectorLabels" . | nindent 8 }}
+    spec:
+      {{- with .Values.imagePullSecrets }}
+      imagePullSecrets:
+        {{- toYaml . | nindent 8 }}
+      {{- end }}
+      securityContext:
+        {{- toYaml .Values.podSecurityContext | nindent 8 }}
+      volumes:
+        - name: data
+          {{- .Values.volume | nindent 10 }}
+        - name: config
+          configMap:
+            name: {{ include "actual-helm.fullname" . }}
+      containers:
+        - name: {{ .Chart.Name }}
+          securityContext:
+            {{- toYaml .Values.securityContext | nindent 12 }}
+          image: "{{ .Values.image.repository }}:{{ .Values.image.tag | default .Chart.AppVersion }}"
+          imagePullPolicy: {{ .Values.image.pullPolicy }}
+          ports:
+            - name: http
+              containerPort: 8080
+              protocol: TCP
+          startupProbe:
+            httpGet:
+              path: /
+              port: http
+          livenessProbe:
+            httpGet:
+              path: /
+              port: http
+          readinessProbe:
+            httpGet:
+              path: /
+              port: http
+          resources:
+            {{- toYaml .Values.resources | nindent 12 }}
+          volumeMounts:
+            - mountPath: "/app/config.json"
+              name: config
+              subPath: "config.json"
+            - mountPath: "/data"
+              name: data
+      {{- with .Values.nodeSelector }}
+      nodeSelector:
+        {{- toYaml . | nindent 8 }}
+      {{- end }}
+      {{- with .Values.affinity }}
+      affinity:
+        {{- toYaml . | nindent 8 }}
+      {{- end }}
+      {{- with .Values.tolerations }}
+      tolerations:
+        {{- toYaml . | nindent 8 }}
+      {{- end }}
diff --git a/actual/templates/ingress.yaml b/actual/templates/ingress.yaml
new file mode 100644
index 0000000..5d57e50
--- /dev/null
+++ b/actual/templates/ingress.yaml
@@ -0,0 +1,20 @@
+apiVersion: networking.k8s.io/v1
+kind: Ingress
+metadata:
+  name: {{ include "actual-helm.fullname" . }}
+  labels:
+    {{- include "actual-helm.labels" . | nindent 4 }}
+  annotations:
+    {{- .Values.ingress.annotations | toYaml | nindent 4 }}
+spec:
+  rules:
+    - host: "{{ .Values.ingress.host }}"
+      http:
+        paths:
+          - path: "{{ .Values.ingress.path }}"
+            backend:
+              service:
+                name: {{ include "actual-helm.fullname" . }}
+                port:
+                  name: http
+            pathType: Prefix
diff --git a/actual/templates/service.yaml b/actual/templates/service.yaml
new file mode 100644
index 0000000..0f89c2e
--- /dev/null
+++ b/actual/templates/service.yaml
@@ -0,0 +1,15 @@
+apiVersion: v1
+kind: Service
+metadata:
+  name: {{ include "actual-helm.fullname" . }}
+  labels:
+    {{- include "actual-helm.labels" . | nindent 4 }}
+spec:
+  type: {{ .Values.service.type }}
+  ports:
+    - port: 80
+      targetPort: http
+      protocol: TCP
+      name: http
+  selector:
+    {{- include "actual-helm.selectorLabels" . | nindent 4 }}
diff --git a/actual/values.yaml b/actual/values.yaml
new file mode 100644
index 0000000..5594fa2
--- /dev/null
+++ b/actual/values.yaml
@@ -0,0 +1,49 @@
+replicaCount: 1
+
+image:
+  repository: k8r.eu/justjanne/actual-server
+  pullPolicy: IfNotPresent
+  tag: ""
+
+imagePullSecrets: [ ]
+nameOverride: ""
+fullnameOverride: ""
+
+syncMode: simple
+
+volume: |-
+  emptyDir: {}
+
+service:
+  type: ClusterIP
+
+ingress:
+  host: "example.com"
+  path: "/"
+  annotations: { }
+
+podAnnotations: { }
+
+podSecurityContext:
+  fsGroup: 2000
+
+securityContext:
+  capabilities:
+    drop:
+      - ALL
+  runAsNonRoot: true
+  runAsUser: 1000
+
+resources:
+  limits:
+    cpu: "2"
+    memory: 2Gi
+  requests:
+    cpu: 400m
+    memory: 512Mi
+
+nodeSelector: { }
+
+tolerations: [ ]
+
+affinity: { }
-- 
GitLab