diff --git a/.github/workflows/helm-chart-release.yml b/.github/workflows/helm-chart-release.yml new file mode 100644 index 00000000..f4ad1bc0 --- /dev/null +++ b/.github/workflows/helm-chart-release.yml @@ -0,0 +1,42 @@ +name: Release Charts + +on: + push: + paths: + - "charts/**" + branches: + - master + +jobs: + release: + # depending on default permission settings for your org (contents being read-only or read-write for workloads), you will have to add permissions + # see: https://docs.github.com/en/actions/security-guides/automatic-token-authentication#modifying-the-permissions-for-the-github_token + permissions: + contents: write + runs-on: ubuntu-latest + steps: + - name: Checkout + uses: actions/checkout@v3 + with: + fetch-depth: 0 + + - name: Configure Git + run: | + git config user.name "$GITHUB_ACTOR" + git config user.email "$GITHUB_ACTOR@users.noreply.github.com" + + - name: Install Helm + uses: azure/setup-helm@v3 + + - name: Add repositories + run: | + for dir in $(ls -d charts/*/); do + helm dependency list $dir 2> /dev/null | tail +2 | head -n -1 | awk '{ print "helm repo add " $1 " " $3 }' | while read cmd; do $cmd; done + done + + - name: Run chart-releaser for stable + uses: helm/chart-releaser-action@v1.5.0 + with: + charts_dir: charts + env: + CR_TOKEN: "${{ secrets.GITHUB_TOKEN }}" diff --git a/.gitignore b/.gitignore index e1c35863..9d3a0d82 100644 --- a/.gitignore +++ b/.gitignore @@ -10,3 +10,6 @@ docker-compose.override.yml # `npm i --package-lock-only` pnpm-lock.yaml yarn.lock + +# Chart dependencies +**/charts/*.tgz diff --git a/charts/planka/.helmignore b/charts/planka/.helmignore new file mode 100644 index 00000000..0e8a0eb3 --- /dev/null +++ b/charts/planka/.helmignore @@ -0,0 +1,23 @@ +# Patterns to ignore when building packages. +# This supports shell glob matching, relative path matching, and +# negation (prefixed with !). Only one pattern per line. +.DS_Store +# Common VCS dirs +.git/ +.gitignore +.bzr/ +.bzrignore +.hg/ +.hgignore +.svn/ +# Common backup files +*.swp +*.bak +*.tmp +*.orig +*~ +# Various IDEs +.project +.idea/ +*.tmproj +.vscode/ diff --git a/charts/planka/Chart.lock b/charts/planka/Chart.lock new file mode 100644 index 00000000..41033378 --- /dev/null +++ b/charts/planka/Chart.lock @@ -0,0 +1,6 @@ +dependencies: +- name: postgresql + repository: https://charts.bitnami.com/bitnami + version: 12.5.1 +digest: sha256:01dfb2d07ab6800b4a5a6c81f20f3377a758124b2b96b891d0cd6b4f64cf783b +generated: "2023-05-15T00:54:48.1308917+01:00" diff --git a/charts/planka/Chart.yaml b/charts/planka/Chart.yaml new file mode 100644 index 00000000..5afded17 --- /dev/null +++ b/charts/planka/Chart.yaml @@ -0,0 +1,31 @@ +apiVersion: v2 +name: planka +description: A Helm chart to deploy Planka and it's dependencies. + +# A chart can be either an 'application' or a 'library' chart. +# +# Application charts are a collection of templates that can be packaged into versioned archives +# to be deployed. +# +# Library charts provide useful utilities or functions for the chart developer. They're included as +# a dependency of application charts to inject those utilities and functions into the rendering +# pipeline. Library charts do not define any templates and therefore cannot be deployed. +type: application + +# This is the chart version. This version number should be incremented each time you make changes +# to the chart and its templates, including the app version. +# Versions are expected to follow Semantic Versioning (https://semver.org/) +version: 0.1.0 + +# This is the version number of the application being deployed. This version number should be +# incremented each time you make changes to the application. Versions are not expected to +# follow Semantic Versioning. They should reflect the version the application is using. +# It is recommended to use it with quotes. +appVersion: "1.11.0" + +dependencies: +- alias: postgresql + condition: postgresql.enabled + name: postgresql + repository: &bitnami-repo https://charts.bitnami.com/bitnami + version: 12.5.1 \ No newline at end of file diff --git a/charts/planka/README.md b/charts/planka/README.md new file mode 100644 index 00000000..f767f1af --- /dev/null +++ b/charts/planka/README.md @@ -0,0 +1,84 @@ +# Planka Helm Chart + +[Planka](https://github.com/plankanban/planka) is an OSS alternative to Trello that you can host yourself, and this is a Helm Chart to make it easier to deploy to K8s. + +Shoutout to [this issue](https://github.com/plankanban/planka/issues/192) who have been asking for this Helm Chart. + +## Issues + +By using the Bitnami chart for PostgreSQL, there is an issue where once deployed, if trying to use a different password then it will be ignored as the Persistant Volume (PV) will already exist with the previous password. See warning from Bitnami below: + +> **Warning!** Setting a password will be ignored on new installation in the case when previous Posgresql release was deleted through the helm command. In that case, old PVC will have an old password, and setting it through helm won't take effect. Deleting persistent volumes (PVs) will solve the issue. Refer to [issue 2061](https://github.com/bitnami/charts/issues/2061) for more details + +If you want to fully uninstall this chart including the data, follow [these steps](https://github.com/bitnami/charts/blob/main/bitnami/postgresql/README.md#uninstalling-the-chart) from the Bitnami Chart's docs. + +## Usage + +The basic usage of the chart can be found below: + +```bash +git clone https://github.com/Chris-Greaves/planka-helm-chart.git +cd planka-helm-chart +helm dependency build +export SECRETKEY=$(openssl rand -hex 64) +helm install planka . --set secretkey=$SECRETKEY +``` + +> **NOTE:** The command `openssl rand -hex 64` is needed to create a random hexadecimal key for planka. On Windows you can use Git Bash to run that command. + +To access Planka you can port forward using the following command: + +```bash +kubectl port-forward $POD_NAME 3000:1337 +``` + +### Accessing Externally + +To access Planka externally you can use the following configuration + +```bash +# HTTP only +helm install planka . --set secretkey=$SECRETKEY \ +--set ingress.enabled=true \ +--set ingress.hosts[0].host=planka.example.dev \ + +# HTTPS +helm install planka . --set secretkey=$SECRETKEY \ +--set ingress.enabled=true \ +--set ingress.hosts[0].host=planka.example.dev \ +--set ingress.tls[0].secretName=planka-tls \ +--set ingress.tls[0].hosts[0]=planka.example.dev \ +``` + +or create a values.yaml file like: + +```yaml +secretkey: "" +ingress: + enabled: true + hosts: + - host: planka.example.dev + paths: + - path: / + pathType: ImplementationSpecific + +# Needed for HTTPS + tls: + - secretName: planka-tls # existing TLS secret in k8s + hosts: + - planka.example.dev +``` + +```bash +helm install planka . -f values.yaml +``` + +### Things to consider if production hosting + +If you want to host Planka for more than just playing around with, you might want to do the following things: + +- Create a `values.yaml` with your config, as this will make applying upgrades much easier in the future. +- Create your `secretkey` once and store it either in a secure vault, or in your `values.yaml` file so it will be the same for upgrading in the future. +- Specify a password for `postgresql.auth.password` as there have been issues with the postgresql chart generating new passwords locking you out of the data you've already stored. (see [this issue](https://github.com/bitnami/charts/issues/2061)) + +Any questions or concerns, [raise an issue](https://github.com/Chris-Greaves/planka-helm-chart/issues/new). \ No newline at end of file diff --git a/charts/planka/templates/NOTES.txt b/charts/planka/templates/NOTES.txt new file mode 100644 index 00000000..acf07ede --- /dev/null +++ b/charts/planka/templates/NOTES.txt @@ -0,0 +1,22 @@ +1. Get the application URL by running these commands: +{{- if .Values.ingress.enabled }} +{{- range $host := .Values.ingress.hosts }} + {{- range .paths }} + http{{ if $.Values.ingress.tls }}s{{ end }}://{{ $host.host }}{{ .path }} + {{- end }} +{{- end }} +{{- else if contains "NodePort" .Values.service.type }} + export NODE_PORT=$(kubectl get --namespace {{ .Release.Namespace }} -o jsonpath="{.spec.ports[0].nodePort}" services {{ include "planka.fullname" . }}) + export NODE_IP=$(kubectl get nodes --namespace {{ .Release.Namespace }} -o jsonpath="{.items[0].status.addresses[0].address}") + echo http://$NODE_IP:$NODE_PORT +{{- else if contains "LoadBalancer" .Values.service.type }} + NOTE: It may take a few minutes for the LoadBalancer IP to be available. + You can watch the status of by running 'kubectl get --namespace {{ .Release.Namespace }} svc -w {{ include "planka.fullname" . }}' + export SERVICE_IP=$(kubectl get svc --namespace {{ .Release.Namespace }} {{ include "planka.fullname" . }} --template "{{"{{ range (index .status.loadBalancer.ingress 0) }}{{.}}{{ end }}"}}") + echo http://$SERVICE_IP:{{ .Values.service.port }} +{{- else if contains "ClusterIP" .Values.service.type }} + export POD_NAME=$(kubectl get pods --namespace {{ .Release.Namespace }} -l "app.kubernetes.io/name={{ include "planka.name" . }},app.kubernetes.io/instance={{ .Release.Name }}" -o jsonpath="{.items[0].metadata.name}") + export CONTAINER_PORT=$(kubectl get pod --namespace {{ .Release.Namespace }} $POD_NAME -o jsonpath="{.spec.containers[0].ports[0].containerPort}") + echo "Visit http://localhost:3000 to use your application" + kubectl --namespace {{ .Release.Namespace }} port-forward $POD_NAME 3000:$CONTAINER_PORT +{{- end }} diff --git a/charts/planka/templates/_helpers.tpl b/charts/planka/templates/_helpers.tpl new file mode 100644 index 00000000..51099515 --- /dev/null +++ b/charts/planka/templates/_helpers.tpl @@ -0,0 +1,62 @@ +{{/* +Expand the name of the chart. +*/}} +{{- define "planka.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 "planka.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 "planka.chart" -}} +{{- printf "%s-%s" .Chart.Name .Chart.Version | replace "+" "_" | trunc 63 | trimSuffix "-" }} +{{- end }} + +{{/* +Common labels +*/}} +{{- define "planka.labels" -}} +helm.sh/chart: {{ include "planka.chart" . }} +{{ include "planka.selectorLabels" . }} +{{- if .Chart.AppVersion }} +app.kubernetes.io/version: {{ .Chart.AppVersion | quote }} +{{- end }} +app.kubernetes.io/managed-by: {{ .Release.Service }} +{{- end }} + +{{/* +Selector labels +*/}} +{{- define "planka.selectorLabels" -}} +app.kubernetes.io/name: {{ include "planka.name" . }} +app.kubernetes.io/instance: {{ .Release.Name }} +{{- end }} + +{{/* +Create the name of the service account to use +*/}} +{{- define "planka.serviceAccountName" -}} +{{- if .Values.serviceAccount.create }} +{{- default (include "planka.fullname" .) .Values.serviceAccount.name }} +{{- else }} +{{- default "default" .Values.serviceAccount.name }} +{{- end }} +{{- end }} diff --git a/charts/planka/templates/deployment.yaml b/charts/planka/templates/deployment.yaml new file mode 100644 index 00000000..d9b56cd6 --- /dev/null +++ b/charts/planka/templates/deployment.yaml @@ -0,0 +1,95 @@ +apiVersion: apps/v1 +kind: Deployment +metadata: + name: {{ include "planka.fullname" . }} + labels: + {{- include "planka.labels" . | nindent 4 }} +spec: + {{- if not .Values.autoscaling.enabled }} + replicas: {{ .Values.replicaCount }} + {{- end }} + selector: + matchLabels: + {{- include "planka.selectorLabels" . | nindent 6 }} + template: + metadata: + {{- with .Values.podAnnotations }} + annotations: + {{- toYaml . | nindent 8 }} + {{- end }} + labels: + {{- include "planka.selectorLabels" . | nindent 8 }} + spec: + {{- with .Values.imagePullSecrets }} + imagePullSecrets: + {{- toYaml . | nindent 8 }} + {{- end }} + serviceAccountName: {{ include "planka.serviceAccountName" . }} + securityContext: + {{- toYaml .Values.podSecurityContext | nindent 8 }} + 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: {{ .Values.service.port }} + protocol: TCP + livenessProbe: + httpGet: + path: / + port: http + readinessProbe: + httpGet: + path: / + port: http + volumeMounts: + - mountPath: /app/public/user-avatars + subPath: user-avatars + name: planka + - mountPath: /app/public/project-background-images + subPath: project-background-images + name: planka + - mountPath: /app/private/attachments + subPath: attachments + name: planka + resources: + {{- toYaml .Values.resources | nindent 12 }} + env: + - name: DATABASE_URL + valueFrom: + secretKeyRef: + name: planka-postgresql-svcbind-custom-user + key: uri + - name: BASE_URL + {{- if .Values.ingress.enabled }} + value: {{ printf "https://%s" (first .Values.ingress.hosts).host }} + {{- else }} + value: http://localhost:3000 + {{- end }} + - name: SECRET_KEY + value: {{ required "A secret key needs to be generated using 'openssl rand -hex 64' and assigned to secretkey." .Values.secretkey }} + - name: TRUST_PROXY + value: "0" + {{- with .Values.nodeSelector }} + nodeSelector: + {{- toYaml . | nindent 8 }} + {{- end }} + {{- with .Values.affinity }} + affinity: + {{- toYaml . | nindent 8 }} + {{- end }} + {{- with .Values.tolerations }} + tolerations: + {{- toYaml . | nindent 8 }} + {{- end }} + volumes: + - name: planka + {{- if .Values.persistence.enabled }} + persistentVolumeClaim: + claimName: {{ .Values.persistence.existingClaim | default (include "planka.fullname" .) }} + {{- else }} + emptyDir: {} + {{- end }} diff --git a/charts/planka/templates/hpa.yaml b/charts/planka/templates/hpa.yaml new file mode 100644 index 00000000..09e4c398 --- /dev/null +++ b/charts/planka/templates/hpa.yaml @@ -0,0 +1,28 @@ +{{- if .Values.autoscaling.enabled }} +apiVersion: autoscaling/v2beta1 +kind: HorizontalPodAutoscaler +metadata: + name: {{ include "planka.fullname" . }} + labels: + {{- include "planka.labels" . | nindent 4 }} +spec: + scaleTargetRef: + apiVersion: apps/v1 + kind: Deployment + name: {{ include "planka.fullname" . }} + minReplicas: {{ .Values.autoscaling.minReplicas }} + maxReplicas: {{ .Values.autoscaling.maxReplicas }} + metrics: + {{- if .Values.autoscaling.targetCPUUtilizationPercentage }} + - type: Resource + resource: + name: cpu + targetAverageUtilization: {{ .Values.autoscaling.targetCPUUtilizationPercentage }} + {{- end }} + {{- if .Values.autoscaling.targetMemoryUtilizationPercentage }} + - type: Resource + resource: + name: memory + targetAverageUtilization: {{ .Values.autoscaling.targetMemoryUtilizationPercentage }} + {{- end }} +{{- end }} diff --git a/charts/planka/templates/ingress.yaml b/charts/planka/templates/ingress.yaml new file mode 100644 index 00000000..428d7ab4 --- /dev/null +++ b/charts/planka/templates/ingress.yaml @@ -0,0 +1,61 @@ +{{- if .Values.ingress.enabled -}} +{{- $fullName := include "planka.fullname" . -}} +{{- $svcPort := .Values.service.port -}} +{{- if and .Values.ingress.className (not (semverCompare ">=1.18-0" .Capabilities.KubeVersion.GitVersion)) }} + {{- if not (hasKey .Values.ingress.annotations "kubernetes.io/ingress.class") }} + {{- $_ := set .Values.ingress.annotations "kubernetes.io/ingress.class" .Values.ingress.className}} + {{- end }} +{{- end }} +{{- if semverCompare ">=1.19-0" .Capabilities.KubeVersion.GitVersion -}} +apiVersion: networking.k8s.io/v1 +{{- else if semverCompare ">=1.14-0" .Capabilities.KubeVersion.GitVersion -}} +apiVersion: networking.k8s.io/v1beta1 +{{- else -}} +apiVersion: extensions/v1beta1 +{{- end }} +kind: Ingress +metadata: + name: {{ $fullName }} + labels: + {{- include "planka.labels" . | nindent 4 }} + {{- with .Values.ingress.annotations }} + annotations: + {{- toYaml . | nindent 4 }} + {{- end }} +spec: + {{- if and .Values.ingress.className (semverCompare ">=1.18-0" .Capabilities.KubeVersion.GitVersion) }} + ingressClassName: {{ .Values.ingress.className }} + {{- end }} + {{- if .Values.ingress.tls }} + tls: + {{- range .Values.ingress.tls }} + - hosts: + {{- range .hosts }} + - {{ . | quote }} + {{- end }} + secretName: {{ .secretName }} + {{- end }} + {{- end }} + rules: + {{- range .Values.ingress.hosts }} + - host: {{ .host | quote }} + http: + paths: + {{- range .paths }} + - path: {{ .path }} + {{- if and .pathType (semverCompare ">=1.18-0" $.Capabilities.KubeVersion.GitVersion) }} + pathType: {{ .pathType }} + {{- end }} + backend: + {{- if semverCompare ">=1.19-0" $.Capabilities.KubeVersion.GitVersion }} + service: + name: {{ $fullName }} + port: + number: {{ $svcPort }} + {{- else }} + serviceName: {{ $fullName }} + servicePort: {{ $svcPort }} + {{- end }} + {{- end }} + {{- end }} +{{- end }} diff --git a/charts/planka/templates/pvc.yaml b/charts/planka/templates/pvc.yaml new file mode 100644 index 00000000..0a3240b3 --- /dev/null +++ b/charts/planka/templates/pvc.yaml @@ -0,0 +1,25 @@ +{{- if and .Values.persistence.enabled (not .Values.persistence.existingClaim) }} +--- +kind: PersistentVolumeClaim +apiVersion: v1 +metadata: + name: {{ include "planka.fullname" . }} + labels: + app.kubernetes.io/name: {{ include "planka.name" . }} + helm.sh/chart: {{ include "planka.chart" . }} + app.kubernetes.io/instance: {{ .Release.Name }} + app.kubernetes.io/managed-by: {{ .Release.Service }} +spec: + accessModes: + - {{ .Values.persistence.accessMode }} + resources: + requests: + storage: {{ .Values.persistence.size | quote }} +{{- if .Values.persistence.storageClass }} +{{- if (eq "-" .Values.persistence.storageClass) }} + storageClassName: "" +{{- else }} + storageClassName: "{{ .Values.persistence.storageClass }}" +{{- end }} +{{- end }} +{{- end }} \ No newline at end of file diff --git a/charts/planka/templates/service.yaml b/charts/planka/templates/service.yaml new file mode 100644 index 00000000..c7ef2e9d --- /dev/null +++ b/charts/planka/templates/service.yaml @@ -0,0 +1,15 @@ +apiVersion: v1 +kind: Service +metadata: + name: {{ include "planka.fullname" . }} + labels: + {{- include "planka.labels" . | nindent 4 }} +spec: + type: {{ .Values.service.type }} + ports: + - port: {{ .Values.service.port }} + targetPort: http + protocol: TCP + name: http + selector: + {{- include "planka.selectorLabels" . | nindent 4 }} diff --git a/charts/planka/templates/serviceaccount.yaml b/charts/planka/templates/serviceaccount.yaml new file mode 100644 index 00000000..dfef4c51 --- /dev/null +++ b/charts/planka/templates/serviceaccount.yaml @@ -0,0 +1,12 @@ +{{- if .Values.serviceAccount.create -}} +apiVersion: v1 +kind: ServiceAccount +metadata: + name: {{ include "planka.serviceAccountName" . }} + labels: + {{- include "planka.labels" . | nindent 4 }} + {{- with .Values.serviceAccount.annotations }} + annotations: + {{- toYaml . | nindent 4 }} + {{- end }} +{{- end }} diff --git a/charts/planka/templates/tests/test-connection.yaml b/charts/planka/templates/tests/test-connection.yaml new file mode 100644 index 00000000..ee4462e4 --- /dev/null +++ b/charts/planka/templates/tests/test-connection.yaml @@ -0,0 +1,15 @@ +apiVersion: v1 +kind: Pod +metadata: + name: "{{ include "planka.fullname" . }}-test-connection" + labels: + {{- include "planka.labels" . | nindent 4 }} + annotations: + "helm.sh/hook": test +spec: + containers: + - name: wget + image: busybox + command: ['wget'] + args: ['{{ include "planka.fullname" . }}:{{ .Values.service.port }}'] + restartPolicy: Never diff --git a/charts/planka/values.yaml b/charts/planka/values.yaml new file mode 100644 index 00000000..67e48431 --- /dev/null +++ b/charts/planka/values.yaml @@ -0,0 +1,106 @@ +# Default values for planka. +# This is a YAML-formatted file. +# Declare variables to be passed into your templates. + +replicaCount: 1 + +image: + repository: ghcr.io/plankanban/planka + pullPolicy: IfNotPresent + # Overrides the image tag whose default is the chart appVersion. + tag: "" + +imagePullSecrets: [] +nameOverride: "" +fullnameOverride: "" + +# Generate a secret using openssl rand -base64 45 +secretkey: "" + +serviceAccount: + # Specifies whether a service account should be created + create: true + # Annotations to add to the service account + annotations: {} + # The name of the service account to use. + # If not set and create is true, a name is generated using the fullname template + name: "" + +podAnnotations: {} + +podSecurityContext: {} + # fsGroup: 2000 + +securityContext: {} + # capabilities: + # drop: + # - ALL + # readOnlyRootFilesystem: true + # runAsNonRoot: true + # runAsUser: 1000 + +service: + type: ClusterIP + port: 1337 + +ingress: + enabled: false + className: "" + annotations: {} + # kubernetes.io/ingress.class: nginx + # kubernetes.io/tls-acme: "true" + hosts: + - host: planka.local + paths: + - path: / + pathType: ImplementationSpecific + tls: [] + # - secretName: planka-tls + # hosts: + # - planka.local + +resources: {} + # We usually recommend not to specify default resources and to leave this as a conscious + # choice for the user. This also increases chances charts run on environments with little + # resources, such as Minikube. If you do want to specify resources, uncomment the following + # lines, adjust them as necessary, and remove the curly braces after 'resources:'. + # limits: + # cpu: 100m + # memory: 128Mi + # requests: + # cpu: 100m + # memory: 128Mi + +autoscaling: + enabled: false + minReplicas: 1 + maxReplicas: 100 + targetCPUUtilizationPercentage: 80 + # targetMemoryUtilizationPercentage: 80 + +nodeSelector: {} + +tolerations: [] + +affinity: {} + +postgresql: + enabled: true + auth: + database: planka + username: planka + password: "" + postgresPassword: "" + replicationPassword: "" + # existingSecret: planka-postgresql + serviceBindings: + enabled: true + +## PVC-based data storage configuration +persistence: + enabled: false + # existingClaim: netbox-data + # storageClass: "-" + + accessMode: ReadWriteOnce + size: 10Gi