diff --git a/.dockerignore b/.dockerignore index 6f737391..b86a2676 100644 --- a/.dockerignore +++ b/.dockerignore @@ -15,3 +15,4 @@ __pycache__ .Python .python-version *.swp +*.trivy diff --git a/.github/workflows/ghcr.yml b/.github/workflows/ghcr.yml index beebfd3c..2359c60e 100644 --- a/.github/workflows/ghcr.yml +++ b/.github/workflows/ghcr.yml @@ -34,17 +34,11 @@ jobs: steps: - uses: actions/checkout@v4 + - uses: sigstore/cosign-installer@v3.4.0 + - name: Set up Docker Buildx uses: docker/setup-buildx-action@v3 - - name: Log in to the Container registry - uses: docker/login-action@v3 - if: github.event_name != 'pull_request' - with: - registry: ${{ env.REGISTRY }} - username: ${{ github.actor }} - password: ${{ secrets.GITHUB_TOKEN }} - - name: Extract metadata (tags, labels) for Docker id: meta uses: docker/metadata-action@v5 @@ -52,11 +46,61 @@ jobs: images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }} tags: | type=raw,value=dev,enable={{is_default_branch}} + type=ref,event=pr type=semver,pattern={{version}} type=semver,pattern={{major}}.{{minor}} type=semver,pattern={{major}} - - name: Build and push + - name: Build + id: docker + uses: docker/build-push-action@v5 + with: + context: . + file: ./Dockerfile + push: false + load: true + tags: ${{ steps.meta.outputs.tags }} + labels: ${{ steps.meta.outputs.labels }} + cache-from: type=gha + cache-to: type=gha,mode=max + + - name: Run Trivy vulnerability scanner + uses: aquasecurity/trivy-action@0.16.1 + with: + image-ref: '${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:${{ steps.meta.outputs.version }}' + format: 'json' + ignore-unfixed: true + list-all-pkgs: true + output: 'trivy.json' + + - name: Convert trivy results to sarif + uses: aquasecurity/trivy-action@0.16.1 + with: + image-ref: trivy.json + scan-type: 'convert' + format: 'sarif' + # we don't actually limit them, but this gates the convert action + limit-severities-for-sarif: true + # empty makes it skip the --vuln-type arg + vuln-type: '' + output: 'trivy.sarif' + + - name: Upload Trivy scan results to GitHub Security tab + uses: github/codeql-action/upload-sarif@v3 + if: always() + with: + sarif_file: 'trivy.sarif' + + - name: Log in to the Container registry + uses: docker/login-action@v3 + if: github.event_name != 'pull_request' + with: + registry: ${{ env.REGISTRY }} + username: ${{ github.actor }} + password: ${{ secrets.GITHUB_TOKEN }} + + - name: Push + id: docker_push uses: docker/build-push-action@v5 with: context: . @@ -66,3 +110,62 @@ jobs: labels: ${{ steps.meta.outputs.labels }} cache-from: type=gha cache-to: type=gha,mode=max + + - name: Sign the images with GitHub OIDC Token using cosign + run: cosign sign --yes ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}@${{ steps.docker_push.outputs.digest }} + if: github.event_name != 'pull_request' && startsWith(github.event.ref, 'refs/tags/v') + env: + TAGS: ${{ steps.meta.outputs.tags }} + + - name: Convert trivy results to CycloneDX + uses: aquasecurity/trivy-action@0.16.1 + with: + image-ref: trivy.json + scan-type: 'convert' + format: 'cyclonedx' + # we don't actually limit them, but this gates the convert action + limit-severities-for-sarif: true + # empty makes it skip the --vuln-type arg + vuln-type: '' + output: 'trivy.cdx' + + - name: Attach an SBOM attestation to the signed image + run: cosign attest --yes --type cyclonedx --predicate trivy.cdx ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}@${{ steps.docker_push.outputs.digest }} + if: github.event_name != 'pull_request' && startsWith(github.event.ref, 'refs/tags/v') + + - name: Set up Helm + uses: azure/setup-helm@v3.5 + with: + version: v3.14.0 + + - uses: actions/setup-python@v4 + with: + python-version: '3.x' + + - name: Install chart-testing + uses: helm/chart-testing-action@v2.6.1 + + - name: Run chart-testing (lint) + run: ct --config=deploy/ct.yaml lint + + - name: Create kind cluster + uses: helm/kind-action@v1.8.0 + + - name: Load dev image into K8s + run: | + docker export -o /tmp/img.tar ghcr.io/projectcaluma/alexandria:dev + kind load image-archive /tmp/img.tar --name chart-testing + + - name: Run chart-testing (install) + run: ct --config=deploy/ct.yaml install + + - name: Prepare Chart Metadata + id: chartmeta + run: echo version=${GITHUB_REF#refs/tags/v} >> $GITHUB_OUTPUT + + - name: Package Chart + run: helm package --version ${{ steps.chartmeta.outputs.version }} --app-version ${{ steps.chartmeta.outputs.version }} --destination=dist deploy/charts/alexandria + + - name: Push Chart + run: helm push dist/*.tgz oci://ghcr.io/projectcaluma/helm + if: github.event_name != 'pull_request' && startsWith(github.event.ref, 'refs/tags/v') diff --git a/.gitignore b/.gitignore index d5f5cbe7..37faba07 100644 --- a/.gitignore +++ b/.gitignore @@ -70,3 +70,6 @@ target/ # Editor swap files *.swp + +# Helm +deploy/charts/*/charts/ diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index e2f48fee..201ac430 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -67,3 +67,13 @@ poetry install poetry run pre-commit install --hook=pre-commit poetry run pre-commit install --hook=commit-msg ``` + +### Helm Chart testing + +You can spin up an instance of alexandria locally with ease. Out of the box this deploys the +latest `dev` tag from ghcr.io. + +```bash +helm dep build deploy/charts/alexandria +helm install alexandria -f deploy/charts/alexandria/ci/default-values.yaml alexandria deploy/charts/alexandria +``` diff --git a/deploy/charts/alexandria/.helmignore b/deploy/charts/alexandria/.helmignore new file mode 100644 index 00000000..0e8a0eb3 --- /dev/null +++ b/deploy/charts/alexandria/.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/deploy/charts/alexandria/Chart.lock b/deploy/charts/alexandria/Chart.lock new file mode 100644 index 00000000..233d5e92 --- /dev/null +++ b/deploy/charts/alexandria/Chart.lock @@ -0,0 +1,9 @@ +dependencies: +- name: postgresql + repository: https://charts.bitnami.com/bitnami + version: 14.0.0 +- name: minio + repository: https://charts.min.io + version: 5.0.15 +digest: sha256:2474e6946f37fc6c60a744f92b3b336cee90ccf9c8dfcdf56bfb425904fe132a +generated: "2024-02-03T00:24:29.412659335+01:00" diff --git a/deploy/charts/alexandria/Chart.yaml b/deploy/charts/alexandria/Chart.yaml new file mode 100644 index 00000000..6e73412b --- /dev/null +++ b/deploy/charts/alexandria/Chart.yaml @@ -0,0 +1,24 @@ +apiVersion: v2 +name: alexandria +description: Deploy the Alexandria DMS to Kubernetes +type: application +# managed by CD +version: 0.0.0 +appVersion: dev +home: https://caluma.io/ +icon: https://avatars0.githubusercontent.com/u/42172011?s=200&v=4 +sources: + - https://github.com/projectcaluma/emeis + - https://github.com/projectcaluma/charts +maintainers: + - name: projectcaluma + email: contact@caluma.io +dependencies: + - name: postgresql + version: ~14.0.0 + repository: https://charts.bitnami.com/bitnami + condition: postgresql.enabled + - name: minio + version: ~5.0.15 + repository: https://charts.min.io + condition: minio.enabled diff --git a/deploy/charts/alexandria/ci/default-values.yaml b/deploy/charts/alexandria/ci/default-values.yaml new file mode 100644 index 00000000..3175ca5e --- /dev/null +++ b/deploy/charts/alexandria/ci/default-values.yaml @@ -0,0 +1,14 @@ +postgresql: + auth: + password: alexandria + primary: + persistence: + enabled: false +minio: + accessKey: alexandria + secretKey: alexandria + persistence: + enabled: false + resources: + requests: + memory: 512Mi diff --git a/deploy/charts/alexandria/templates/NOTES.txt b/deploy/charts/alexandria/templates/NOTES.txt new file mode 100644 index 00000000..8b3e4fdd --- /dev/null +++ b/deploy/charts/alexandria/templates/NOTES.txt @@ -0,0 +1,25 @@ +{{- if or .Values.postgresql.enabled .Values.minio.enabled }} +PRODUCTION WARNING: Either embedded PostgreSQL or MinIO instance is configured! This configuration is not supported for production use! +{{- end }} +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 "alexandria.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 "alexandria.fullname" . }}' + export SERVICE_IP=$(kubectl get svc --namespace {{ .Release.Namespace }} {{ include "alexandria.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 "alexandria.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://127.0.0.1:8080 to use your application" + kubectl --namespace {{ .Release.Namespace }} port-forward $POD_NAME 8080:$CONTAINER_PORT +{{- end }} diff --git a/deploy/charts/alexandria/templates/_helpers.tpl b/deploy/charts/alexandria/templates/_helpers.tpl new file mode 100644 index 00000000..7e6e8d77 --- /dev/null +++ b/deploy/charts/alexandria/templates/_helpers.tpl @@ -0,0 +1,62 @@ +{{/* +Expand the name of the chart. +*/}} +{{- define "alexandria.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 "alexandria.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 "alexandria.chart" -}} +{{- printf "%s-%s" .Chart.Name .Chart.Version | replace "+" "_" | trunc 63 | trimSuffix "-" }} +{{- end }} + +{{/* +Common labels +*/}} +{{- define "alexandria.labels" -}} +helm.sh/chart: {{ include "alexandria.chart" . }} +{{ include "alexandria.selectorLabels" . }} +{{- if .Chart.AppVersion }} +app.kubernetes.io/version: {{ .Chart.AppVersion | quote }} +{{- end }} +app.kubernetes.io/managed-by: {{ .Release.Service }} +{{- end }} + +{{/* +Selector labels +*/}} +{{- define "alexandria.selectorLabels" -}} +app.kubernetes.io/name: {{ include "alexandria.name" . }} +app.kubernetes.io/instance: {{ .Release.Name }} +{{- end }} + +{{/* +Create the name of the service account to use +*/}} +{{- define "alexandria.serviceAccountName" -}} +{{- if .Values.serviceAccount.create }} +{{- default (include "alexandria.fullname" .) .Values.serviceAccount.name }} +{{- else }} +{{- default "default" .Values.serviceAccount.name }} +{{- end }} +{{- end }} diff --git a/deploy/charts/alexandria/templates/configmap.yaml b/deploy/charts/alexandria/templates/configmap.yaml new file mode 100644 index 00000000..cdd3a3fd --- /dev/null +++ b/deploy/charts/alexandria/templates/configmap.yaml @@ -0,0 +1,43 @@ +apiVersion: v1 +kind: ConfigMap +metadata: + name: {{ include "alexandria.fullname" . }} + labels: + {{- include "alexandria.labels" . | nindent 4 }} +data: + # Django + ENV: {{ .Values.alexandria.env | quote }} + ALLOWED_HOSTS: {{ .Values.alexandria.allowedHosts | quote }} + ALLOW_ANONYMOUS_WRITE: {{ .Values.alexandria.allowAnonymousWrite | quote }} + LANGUAGES: {{ join "," .Values.alexandria.languages | quote}} + VISIBILITY_CLASSES: {{ .Values.alexandria.visibilityClasses | quote }} + PERMISSION_CLASSES: {{ .Values.alexandria.permissionClasses | quote }} + # DB + {{- if .Values.postgresql.enabled }} + DATABASE_USER: {{ .Values.postgresql.auth.username | quote }} + DATABASE_NAME: {{ .Values.postgresql.auth.database | quote }} + {{- else }} + DATABASE_USER: {{ .Values.alexandria.postgresql.username | quote }} + DATABASE_NAME: {{ .Values.alexandria.postgresql.database | quote }} + {{- end }} + {{- if and .Values.postgresql.enabled .Values.alexandria.postgresql.existingHost }} + {{ fail "postgresql.enabled and alexandria.postgresql.existingHost are mutually exclusive, please pick one" }} + {{- end }} + {{- if .Values.postgresql.enabled }} + DATABASE_HOST: {{ template "alexandria.fullname" . }}-postgresql + {{- else if .Values.alexandria.postgresql.existingHost }} + DATABASE_HOST: {{ .Values.alexandria.postgresql.existingHost | quote }} + {{- else }} + {{ fail "neither postgresql.enabled or alexandria.postgresql.existingHost are set, please pick one" }} + {{- end }} + # S3 + {{- if and .Values.minio.enabled .Values.alexandria.s3.existingHost }} + {{ fail "minio.enabled and alexandria.s3.existingUrl are mutually exclusive, please pick one" }} + {{- end }} + {{- if .Values.minio.enabled }} + ALEXANDRIA_S3_ENDPOINT_URL: http://{{ template "alexandria.fullname" . }}-minio:9000 + {{- else if .Values.alexandria.s3.existingUrl }} + ALEXANDRIA_S3_ENDPOINT_URL: {{ .Values.alexandria.s3.existingUrl | quote }} + {{- else }} + {{ fail "neither minio.enabled or alexandria.s3.existingHost are set, please pick one" }} + {{- end }} diff --git a/deploy/charts/alexandria/templates/deployment.yaml b/deploy/charts/alexandria/templates/deployment.yaml new file mode 100644 index 00000000..89785ed7 --- /dev/null +++ b/deploy/charts/alexandria/templates/deployment.yaml @@ -0,0 +1,105 @@ +apiVersion: apps/v1 +kind: Deployment +metadata: + name: {{ include "alexandria.fullname" . }} + labels: + {{- include "alexandria.labels" . | nindent 4 }} + annotations: + checksum/secret: {{ include (print $.Template.BasePath "/secret.yaml") . | sha256sum }} + checksum/config: {{ include (print $.Template.BasePath "/configmap.yaml") . | sha256sum }} +spec: + {{- if not .Values.autoscaling.enabled }} + replicas: {{ .Values.replicaCount }} + {{- end }} + selector: + matchLabels: + {{- include "alexandria.selectorLabels" . | nindent 6 }} + template: + metadata: + {{- with .Values.podAnnotations }} + annotations: + {{- toYaml . | nindent 8 }} + {{- end }} + labels: + {{- include "alexandria.labels" . | nindent 8 }} + {{- with .Values.podLabels }} + {{- toYaml . | nindent 8 }} + {{- end }} + spec: + {{- with .Values.imagePullSecrets }} + imagePullSecrets: + {{- toYaml . | nindent 8 }} + {{- end }} + serviceAccountName: {{ include "alexandria.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 }} + envFrom: + - configMapRef: + name: {{ include "alexandria.fullname" . }} + {{- if .Values.existingSecret }} + - secretRef: + name: {{ .Values.existingSecret | quote }} + {{- else }} + - secretRef: + name: {{ include "alexandria.fullname" . }} + {{- end }} + env: + - name: DATABASE_PASSWORD + valueFrom: + secretKeyRef: + {{- if .Values.postgresql.enabled }} + name: "{{ template "alexandria.fullname" . }}-postgresql" + key: password + {{- else }} + name: {{ .Values.existingSecret | quote }} + key: DATABASE_PASSWORD + {{- end }} + {{- with .Values.alexandria.additionalEnvironmentVariables }} + {{ toYaml . | nindent 12 }} + {{- end }} + ports: + - name: http + containerPort: {{ .Values.service.port }} + protocol: TCP + livenessProbe: + httpGet: + # TODO: define better livenessProbe + #path: /healthz + path: /api/v1/categories + port: http + readinessProbe: + httpGet: + # TODO: define better livenessProbe + #path: /healthz + path: /api/v1/categories + port: http + resources: + {{- toYaml .Values.resources | nindent 12 }} + {{- with .Values.volumeMounts }} + volumeMounts: + {{- toYaml . | nindent 12 }} + {{- end }} + volumes: + - name: add-hstore-extension + + {{- with .Values.volumes }} + {{- toYaml . | nindent 8 }} + {{- end }} + {{- 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/deploy/charts/alexandria/templates/hpa.yaml b/deploy/charts/alexandria/templates/hpa.yaml new file mode 100644 index 00000000..deef3577 --- /dev/null +++ b/deploy/charts/alexandria/templates/hpa.yaml @@ -0,0 +1,32 @@ +{{- if .Values.autoscaling.enabled }} +apiVersion: autoscaling/v2 +kind: HorizontalPodAutoscaler +metadata: + name: {{ include "alexandria.fullname" . }} + labels: + {{- include "alexandria.labels" . | nindent 4 }} +spec: + scaleTargetRef: + apiVersion: apps/v1 + kind: Deployment + name: {{ include "alexandria.fullname" . }} + minReplicas: {{ .Values.autoscaling.minReplicas }} + maxReplicas: {{ .Values.autoscaling.maxReplicas }} + metrics: + {{- if .Values.autoscaling.targetCPUUtilizationPercentage }} + - type: Resource + resource: + name: cpu + target: + type: Utilization + averageUtilization: {{ .Values.autoscaling.targetCPUUtilizationPercentage }} + {{- end }} + {{- if .Values.autoscaling.targetMemoryUtilizationPercentage }} + - type: Resource + resource: + name: memory + target: + type: Utilization + averageUtilization: {{ .Values.autoscaling.targetMemoryUtilizationPercentage }} + {{- end }} +{{- end }} diff --git a/deploy/charts/alexandria/templates/ingress.yaml b/deploy/charts/alexandria/templates/ingress.yaml new file mode 100644 index 00000000..e16813a7 --- /dev/null +++ b/deploy/charts/alexandria/templates/ingress.yaml @@ -0,0 +1,61 @@ +{{- if .Values.ingress.enabled -}} +{{- $fullName := include "alexandria.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 "alexandria.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/deploy/charts/alexandria/templates/secret.yaml b/deploy/charts/alexandria/templates/secret.yaml new file mode 100644 index 00000000..5fb44ad0 --- /dev/null +++ b/deploy/charts/alexandria/templates/secret.yaml @@ -0,0 +1,19 @@ +{{- if not .Values.existingSecret }} +apiVersion: v1 +kind: Secret +metadata: + name: {{ include "alexandria.fullname" . }} + labels: + {{- include "alexandria.labels" . | nindent 4 }} +data: + # Django + SECRET_KEY: {{ .Values.alexandria.secretKey | b64enc | quote }} + # S3 + {{- if .Values.minio.enabled }} + ALEXANDRIA_S3_ACCESS_KEY: {{ .Values.minio.accessKey | b64enc | quote }} + ALEXANDRIA_S3_SECRET_KEY: {{ .Values.minio.secretKey | b64enc | quote }} + {{- else if and .Values.alexandria.s3.accessKey .Values.alexandria.s3.secretKey }} + ALEXANDRIA_S3_ACCESS_KEY: {{ .Values.alexandria.s3.accessKey | b64enc | quote }} + ALEXANDRIA_S3_SECRET_KEY: {{ .Values.alexandria.s3.secretKey | b64enc | quote }} + {{- end }} +{{- end }} diff --git a/deploy/charts/alexandria/templates/service.yaml b/deploy/charts/alexandria/templates/service.yaml new file mode 100644 index 00000000..7519ea9d --- /dev/null +++ b/deploy/charts/alexandria/templates/service.yaml @@ -0,0 +1,15 @@ +apiVersion: v1 +kind: Service +metadata: + name: {{ include "alexandria.fullname" . }} + labels: + {{- include "alexandria.labels" . | nindent 4 }} +spec: + type: {{ .Values.service.type }} + ports: + - port: {{ .Values.service.port }} + targetPort: http + protocol: TCP + name: http + selector: + {{- include "alexandria.selectorLabels" . | nindent 4 }} diff --git a/deploy/charts/alexandria/templates/serviceaccount.yaml b/deploy/charts/alexandria/templates/serviceaccount.yaml new file mode 100644 index 00000000..208c22b0 --- /dev/null +++ b/deploy/charts/alexandria/templates/serviceaccount.yaml @@ -0,0 +1,13 @@ +{{- if .Values.serviceAccount.create -}} +apiVersion: v1 +kind: ServiceAccount +metadata: + name: {{ include "alexandria.serviceAccountName" . }} + labels: + {{- include "alexandria.labels" . | nindent 4 }} + {{- with .Values.serviceAccount.annotations }} + annotations: + {{- toYaml . | nindent 4 }} + {{- end }} +automountServiceAccountToken: {{ .Values.serviceAccount.automount }} +{{- end }} diff --git a/deploy/charts/alexandria/templates/tests/test-connection.yaml b/deploy/charts/alexandria/templates/tests/test-connection.yaml new file mode 100644 index 00000000..5a87b5cb --- /dev/null +++ b/deploy/charts/alexandria/templates/tests/test-connection.yaml @@ -0,0 +1,15 @@ +apiVersion: v1 +kind: Pod +metadata: + name: "{{ include "alexandria.fullname" . }}-test-connection" + labels: + {{- include "alexandria.labels" . | nindent 4 }} + annotations: + "helm.sh/hook": test +spec: + containers: + - name: wget + image: busybox + command: ['wget'] + args: ['{{ include "alexandria.fullname" . }}:{{ .Values.service.port }}'] + restartPolicy: Never diff --git a/deploy/charts/alexandria/values.yaml b/deploy/charts/alexandria/values.yaml new file mode 100644 index 00000000..8e4ba1e3 --- /dev/null +++ b/deploy/charts/alexandria/values.yaml @@ -0,0 +1,162 @@ +# Default values for alexandria. +# This is a YAML-formatted file. +# Declare variables to be passed into your templates. + +replicaCount: 1 + +image: + repository: ghcr.io/projectcaluma/alexandria + pullPolicy: IfNotPresent + # Overrides the image tag whose default is the chart appVersion. + tag: "" + +imagePullSecrets: [] +nameOverride: "" +fullnameOverride: "" + +serviceAccount: + # Specifies whether a service account should be created + create: true + # Automatically mount a ServiceAccount's API credentials? + automount: 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: {} +podLabels: {} + +podSecurityContext: {} + # fsGroup: 2000 + +securityContext: {} + # capabilities: + # drop: + # - ALL + # readOnlyRootFilesystem: true + # runAsNonRoot: true + # runAsUser: 1000 + +service: + type: ClusterIP + port: 8000 + +ingress: + enabled: false + className: "" + annotations: {} + # kubernetes.io/ingress.class: nginx + # kubernetes.io/tls-acme: "true" + hosts: + - host: chart-example.local + paths: + - path: / + pathType: ImplementationSpecific + tls: [] + # - secretName: chart-example-tls + # hosts: + # - chart-example.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 + +# Additional volumes on the output Deployment definition. +volumes: [] +# - name: foo +# secret: +# secretName: mysecret +# optional: false + +# Additional volumeMounts on the output Deployment definition. +volumeMounts: [] +# - name: foo +# mountPath: "/etc/foo" +# readOnly: true + +nodeSelector: {} + +tolerations: [] + +affinity: {} + +# -- Name of an existing secret that contains the keys +# - SECRET_KEY +# - DATABASE_PASSWORD +# - ALEXANDRIA_S3_ACCESS_KEY +# - ALEXANDRIA_S3_SECRET_KEY +existingSecret: "" + +alexandria: + env: production + secretKey: "" + allowedHosts: "*" + allowAnonymousWrite: "true" + languages: + - de + - en + visibilityClasses: "" + permissionClasses: "" + postgresql: + # -- Gets used when postgresql.enabled = false + username: "" + # -- Gets used when postgresql.enabled = false + existingHost: "" + # -- Gets used when postgresql.enabled = false + database: "" + s3: + # -- Gets used when minio.enabled = false and no existingSecret is provided + accessKey: "" + # -- Gets used when minio.enabled = false and no existingSecret is provided + secretKey: "" + # -- Gets used when minio.enabled = false + existingHost: "" + + additionalEnvironmentVariables: [] + +postgresql: + enabled: true + auth: + database: alexandria + username: alexandria + primary: + initdb: + scripts: + # -- Load HSTORE extension + # @default -- - + create_extension_hstore.sh: | + # !/bin/sh + # + # This script is being used to temporarily switch socket connections to trusted + # to enable the hstore extension in the database above. + set -xeuf -o pipefail + sed -E -i 's/local +all +all +md5/local all all trust/' /opt/bitnami/postgresql/conf/pg_hba.conf + pg_ctl reload + psql --username=postgres --dbname="${POSTGRES_DATABASE}" --command 'CREATE EXTENSION IF NOT EXISTS hstore;' --echo-errors + sed -E -i 's/local +all +all +trust/local all all md5/' /opt/bitnami/postgresql/conf/pg_hba.conf + pg_ctl reload + +minio: + enabled: true + defaultBucket: + enabled: true + name: alexandria + replicas: 1 + mode: standalone diff --git a/deploy/ct.yaml b/deploy/ct.yaml new file mode 100644 index 00000000..728f5dbc --- /dev/null +++ b/deploy/ct.yaml @@ -0,0 +1,6 @@ +target-branch: main +chart-repos: + - minio=https://charts.min.io + - bitnami=https://charts.bitnami.com/bitnami +charts: + - deploy/charts/alexandria