Skip to content

Commit

Permalink
Use OpenProject slim image and seeder job + initcontainer for migrati…
Browse files Browse the repository at this point in the history
…ons (#22)

* use slim image

* use core helper to wait for db

* support custom root CA for outgoing SSL

* fix labels

* fix tls option name

* use https=false to make linting work, maybe

* set timeout for testing to 600s

* fix health check

* Update chart to 2.0.0 due to change to slim

---------

Co-authored-by: Oliver Günther <[email protected]>
  • Loading branch information
machisuji and oliverguenther authored Oct 20, 2023
1 parent 1e0631e commit d2b4712
Show file tree
Hide file tree
Showing 9 changed files with 229 additions and 8 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/lint-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -40,4 +40,4 @@ jobs:
if: steps.list-changed.outputs.changed == 'true'

- name: Run chart-testing (install)
run: ct install --target-branch ${{ github.event.repository.default_branch }} --chart-repos bitnami=https://charts.bitnami.com/bitnami
run: ct install --target-branch ${{ github.event.repository.default_branch }} --chart-repos bitnami=https://charts.bitnami.com/bitnami --helm-extra-set-args "--set environment.OPENPROJECT_HTTPS=false" --helm-extra-args "--timeout 600s"
2 changes: 1 addition & 1 deletion charts/openproject/Chart.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ description: "A Helm chart for running OpenProject via Kubernetes"
home: "https://www.openproject.org/"
icon: "https://www.openproject.org/assets/images/press/openproject-icon-original-color-41055eb6.png"
type: "application"
version: "1.8.1"
version: "2.0.0"
appVersion: "12"
maintainers:
- name: OpenProject
Expand Down
52 changes: 52 additions & 0 deletions charts/openproject/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
# Helm chart for OpenProject

This is the chart for OpenProject itself.

## Development

To install or update from this directory run the following command.

```bash
helm upgrade \
--create-namespace --namespace openproject \
--install --reuse-values openproject-dev .
```

### TLS

Create a TLS certificate, e.g. using [mkcert](https://github.com/FiloSottile/mkcert).

```
mkcert helm-example.openproject-dev.com
```

Create the tls secret in kubernetes.

```
kubectl -n openproject create secret tls openproject-tls \
--key="helm-example.openproject-dev.com-key.pem" \
--cert="helm-example.openproject-dev.com.pem"
```

Set the tls secret value during installation or an upgrade by adding the following.

```
--set ingress.tls.enabled=true --set tls.secretName=openproject-tls
```

#### Root CA

If you want to add your own root CA for outgoing TLS connection, do the following.

1. Put the certificate into a config map.

```
kubectl -n openproject-dev create configmap ca-pemstore --from-file=/path/to/rootCA.pem
```

To make OpenProject use this CA for outgoing TLS connection, set the following options.

```
--set egress.tls.rootCA.configMap=ca-pemstore \
--set egress.tls.rootCA.fileName=rootCA.pem
```
21 changes: 21 additions & 0 deletions charts/openproject/templates/seeder-job.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
apiVersion: batch/v1
kind: Job
metadata:
name: {{ include "common.names.fullname" . }}-seeder-{{ now | date "20060102150405" }}
labels:
{{- include "common.labels.standard" . | nindent 4 }}
spec:
ttlSecondsAfterFinished: 6000
template:
spec:
containers:
- name: seeder
image: "{{ .Values.image.registry }}/{{ .Values.image.repository }}{{ if .Values.image.sha256 }}@sha256:{{ .Values.image.sha256 }}{{ else }}:{{ .Values.image.tag }}{{ end }}"
imagePullPolicy: {{ .Values.image.imagePullPolicy }}
args:
- bash
- /app/docker/prod/seeder
envFrom:
- secretRef:
name: {{ include "common.names.fullname" . }}
restartPolicy: OnFailure
1 change: 1 addition & 0 deletions charts/openproject/templates/service.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -26,5 +26,6 @@ spec:
{{- end }}
selector:
{{- include "common.labels.matchLabels" . | nindent 4 }}
openproject/process: web
{{- end }}
...
2 changes: 1 addition & 1 deletion charts/openproject/templates/tests/test-connection.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,6 @@ spec:
- '--no-verbose'
- '--tries=1'
- '--spider'
- '{{ include "common.names.fullname" . }}:{{ .Values.service.ports.http.port }}/health_checks/all'
- '{{ include "common.names.fullname" . }}:{{ .Values.service.ports.http.port }}/health_check'
restartPolicy: "Never"
...
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,18 @@
apiVersion: {{ include "common.capabilities.deployment.apiVersion" . }}
kind: Deployment
metadata:
name: {{ include "common.names.fullname" . }}
name: {{ include "common.names.fullname" . }}-web
labels:
{{- include "common.labels.standard" . | nindent 4 }}
openproject/process: web
spec:
replicas: {{ .Values.replicaCount }}
strategy:
type: {{ .Values.strategy.type }}
selector:
matchLabels:
{{- include "common.labels.matchLabels" . | nindent 6 }}
openproject/process: web
template:
metadata:
annotations:
Expand All @@ -24,6 +26,7 @@ spec:
checksum/config: {{ values $secretData | sortAlpha | cat | sha256sum }}
labels:
{{- include "common.labels.standard" . | nindent 8 }}
openproject/process: web
spec:
{{- if or .Values.imagePullSecrets .Values.global.imagePullSecrets }}
imagePullSecrets:
Expand All @@ -48,12 +51,29 @@ spec:
{{ toYaml . | nindent 8 | trim }}
{{- end }}
serviceAccountName: {{ include "common.names.fullname" . }}
{{- if .Values.persistence.enabled }}
volumes:
{{- if .Values.egress.tls.rootCA.fileName }}
- name: ca-pemstore
configMap:
name: "{{- .Values.egress.tls.rootCA.configMap }}"
{{- end }}
{{- if .Values.persistence.enabled }}
- name: "data"
persistentVolumeClaim:
claimName: {{ include "common.names.fullname" . }}
{{- end }}
initContainers:
- name: wait-for-db
securityContext:
{{- toYaml .Values.securityContext | nindent 12 }}
image: "{{ .Values.image.registry }}/{{ .Values.image.repository }}{{ if .Values.image.sha256 }}@sha256:{{ .Values.image.sha256 }}{{ else }}:{{ .Values.image.tag }}{{ end }}"
imagePullPolicy: {{ .Values.image.imagePullPolicy }}
envFrom:
- secretRef:
name: {{ include "common.names.fullname" . }}
command:
- bash
- /app/docker/prod/wait-for-db
containers:
- name: "openproject"
securityContext:
Expand All @@ -63,11 +83,22 @@ spec:
envFrom:
- secretRef:
name: {{ include "common.names.fullname" . }}
{{- if .Values.persistence.enabled }}
{{- if .Values.egress.tls.rootCA.fileName }}
env:
- name: SSL_CERT_FILE
value: "/etc/ssl/certs/custom-ca.pem"
{{- end }}
volumeMounts:
{{- if .Values.persistence.enabled }}
- name: "data"
mountPath: "/var/openproject/assets"
{{- end }}
{{- if .Values.egress.tls.rootCA.fileName }}
- name: ca-pemstore
mountPath: /etc/ssl/certs/custom-ca.pem
subPath: {{ .Values.egress.tls.rootCA.fileName }}
readOnly: false
{{- end }}
ports:
{{- range $key, $value := .Values.service.ports }}
- name: {{ $key }}
Expand Down
106 changes: 106 additions & 0 deletions charts/openproject/templates/worker-deployment.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
---
apiVersion: {{ include "common.capabilities.deployment.apiVersion" . }}
kind: Deployment
metadata:
name: {{ include "common.names.fullname" . }}-worker
labels:
{{- include "common.labels.standard" . | nindent 4 }}
openproject/process: worker
spec:
replicas: {{ .Values.backgroundReplicaCount }}
strategy:
type: {{ .Values.strategy.type }}
selector:
matchLabels:
{{- include "common.labels.matchLabels" . | nindent 6 }}
openproject/process: worker
template:
metadata:
annotations:
{{- range $key, $val := .Values.podAnnotations }}
{{ $key }}: {{ $val | quote }}
{{- end }}
# annotate pods with env value checksum so changes trigger re-deployments
{{- $secretObj := (lookup "v1" "Secret" .Release.Namespace (include "common.names.fullname" .)) | default dict }}
{{- $secretData := (get $secretObj "data") | default dict }}
checksum/config: {{ values $secretData | sortAlpha | cat | sha256sum }}
labels:
{{- include "common.labels.standard" . | nindent 8 }}
openproject/process: worker
spec:
{{- if or .Values.imagePullSecrets .Values.global.imagePullSecrets }}
imagePullSecrets:
{{- range (coalesce .Values.imagePullSecrets .Values.global.imagePullSecrets) }}
- name: "{{ . }}"
{{- end }}
{{- end }}
{{- with .Values.affinity }}
affinity:
{{ toYaml . | nindent 8 | trim }}
{{- end }}
{{- with .Values.tolerations }}
tolerations:
{{ toYaml . | nindent 8 | trim }}
{{- end }}
{{- with .Values.nodeSelector }}
nodeSelector:
{{ toYaml . | nindent 8 | trim }}
{{- end }}
{{- with .Values.podSecurityContext }}
securityContext:
{{ toYaml . | nindent 8 | trim }}
{{- end }}
serviceAccountName: {{ include "common.names.fullname" . }}
volumes:
{{- if .Values.egress.tls.rootCA.fileName }}
- name: ca-pemstore
configMap:
name: "{{- .Values.egress.tls.rootCA.configMap }}"
{{- end }}
{{- if .Values.persistence.enabled }}
- name: "data"
persistentVolumeClaim:
claimName: {{ include "common.names.fullname" . }}
{{- end }}
initContainers:
- name: wait-for-db
securityContext:
{{- toYaml .Values.securityContext | nindent 12 }}
image: "{{ .Values.image.registry }}/{{ .Values.image.repository }}{{ if .Values.image.sha256 }}@sha256:{{ .Values.image.sha256 }}{{ else }}:{{ .Values.image.tag }}{{ end }}"
imagePullPolicy: {{ .Values.image.imagePullPolicy }}
envFrom:
- secretRef:
name: {{ include "common.names.fullname" . }}
command:
- bash
- /app/docker/prod/wait-for-db
containers:
- name: "openproject"
securityContext:
{{- toYaml .Values.securityContext | nindent 12 }}
image: "{{ .Values.image.registry }}/{{ .Values.image.repository }}{{ if .Values.image.sha256 }}@sha256:{{ .Values.image.sha256 }}{{ else }}:{{ .Values.image.tag }}{{ end }}"
imagePullPolicy: {{ .Values.image.imagePullPolicy }}
envFrom:
- secretRef:
name: {{ include "common.names.fullname" . }}
{{- if .Values.egress.tls.rootCA.fileName }}
env:
- name: SSL_CERT_FILE
value: "/etc/ssl/certs/custom-ca.pem"
{{- end }}
command:
- bash
- /app/docker/prod/worker
volumeMounts:
{{- if .Values.persistence.enabled }}
- name: "data"
mountPath: "/var/openproject/assets"
{{- end }}
{{- if .Values.egress.tls.rootCA.fileName }}
- name: ca-pemstore
mountPath: /etc/ssl/certs/custom-ca.pem
subPath: {{ .Values.egress.tls.rootCA.fileName }}
readOnly: false
{{- end }}
resources:
{{- toYaml .Values.resources | nindent 12 }}
14 changes: 12 additions & 2 deletions charts/openproject/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,12 @@ ingress:
#
secretName: ""

egress:
tls:
rootCA:
configMap: ""
fileName: ""

## Define image setting
#
image:
Expand Down Expand Up @@ -118,7 +124,7 @@ image:

## Define image tag.
##
tag: "12"
tag: "13-slim"

## Define image sha256 - mutual exclusive with image tag.
## The sha256 has a higher precedence than
Expand Down Expand Up @@ -382,10 +388,14 @@ probes:
#
successThreshold: 1

## Number of OpenProject replicas.
## Number of OpenProject web process replicas.
#
replicaCount: 1

## Number of OpenProject background worker process replicas.
#
backgroundReplicaCount: 1

## Configure resource requests and limits.
##
## http://kubernetes.io/docs/user-guide/compute-resources/
Expand Down

0 comments on commit d2b4712

Please sign in to comment.