From 3bc304047a4d290f4b3be3ec0b2bec107461f2f5 Mon Sep 17 00:00:00 2001 From: Cees-Jan Kiewiet Date: Sat, 8 Jun 2024 18:54:02 +0200 Subject: [PATCH] Initial set up --- .github/FUNDING.yml | 1 + .github/renovate.json | 8 +++ .github/workflows/helm-charts-release.yaml | 33 +++++++++ .github/workflows/helm-charts-test.yaml | 46 ++++++++++++ .gitignore | 1 + charts/mammatus/.helmignore | 22 ++++++ charts/mammatus/Chart.yaml | 10 +++ charts/mammatus/templates/_helpers.tpl | 64 +++++++++++++++++ charts/mammatus/templates/_pod.yaml | 72 +++++++++++++++++++ .../mammatus/templates/configuration/env.yaml | 10 +++ charts/mammatus/templates/cronjobs.yaml | 26 +++++++ charts/mammatus/templates/deployment.yaml | 22 ++++++ charts/mammatus/values.yaml | 34 +++++++++ ct.yaml | 7 ++ etc/kind.yaml | 31 ++++++++ 15 files changed, 387 insertions(+) create mode 100644 .github/FUNDING.yml create mode 100644 .github/renovate.json create mode 100644 .github/workflows/helm-charts-release.yaml create mode 100644 .github/workflows/helm-charts-test.yaml create mode 100644 .gitignore create mode 100644 charts/mammatus/.helmignore create mode 100644 charts/mammatus/Chart.yaml create mode 100644 charts/mammatus/templates/_helpers.tpl create mode 100644 charts/mammatus/templates/_pod.yaml create mode 100644 charts/mammatus/templates/configuration/env.yaml create mode 100644 charts/mammatus/templates/cronjobs.yaml create mode 100644 charts/mammatus/templates/deployment.yaml create mode 100644 charts/mammatus/values.yaml create mode 100644 ct.yaml create mode 100644 etc/kind.yaml diff --git a/.github/FUNDING.yml b/.github/FUNDING.yml new file mode 100644 index 0000000..9c4f1ea --- /dev/null +++ b/.github/FUNDING.yml @@ -0,0 +1 @@ +github: WyriHaximus \ No newline at end of file diff --git a/.github/renovate.json b/.github/renovate.json new file mode 100644 index 0000000..e847fb3 --- /dev/null +++ b/.github/renovate.json @@ -0,0 +1,8 @@ +{ + "$schema": "https://docs.renovatebot.com/renovate-schema.json", + "extends": ["config:base", ":widenPeerDependencies", ":rebaseStalePrs"], + "labels": [ "Dependencies 📦"], + "recreateClosed": true, + "allowScripts": true, + "allowPlugins": true +} diff --git a/.github/workflows/helm-charts-release.yaml b/.github/workflows/helm-charts-release.yaml new file mode 100644 index 0000000..ff67f28 --- /dev/null +++ b/.github/workflows/helm-charts-release.yaml @@ -0,0 +1,33 @@ +name: "helm-charts/release" + +on: + push: + branches: + - main + +jobs: + release: + runs-on: ubuntu-latest + steps: + - name: Checkout + uses: actions/checkout@v4 + + - name: Fetch history + run: git fetch --prune --unshallow + + - name: Configure Git + run: | + git config user.name "$GITHUB_ACTOR" + git config user.email "$GITHUB_ACTOR@users.noreply.github.com" + + # See https://github.com/helm/chart-releaser-action/issues/6 + - name: Install Helm + run: | + curl -fsSLo get_helm.sh https://raw.githubusercontent.com/helm/helm/master/scripts/get-helm-3 + chmod 700 get_helm.sh + ./get_helm.sh + + - name: Run chart-releaser + uses: helm/chart-releaser-action@v1.6.0 + env: + CR_TOKEN: "${{ secrets.CR_TOKEN }}" diff --git a/.github/workflows/helm-charts-test.yaml b/.github/workflows/helm-charts-test.yaml new file mode 100644 index 0000000..47b72b0 --- /dev/null +++ b/.github/workflows/helm-charts-test.yaml @@ -0,0 +1,46 @@ +name: "helm-charts/test" + +on: pull_request + +jobs: + lint: + runs-on: ubuntu-latest + steps: + - name: Checkout + uses: actions/checkout@v4 + - name: Fetch history + run: git fetch --prune --unshallow + - name: Install Chart Tester + uses: helm/chart-testing-action@v2.6.1 + - name: Lint charts + id: lint + run: ct lint --all + + test: + runs-on: ubuntu-latest + needs: lint + strategy: + fail-fast: false + matrix: + k8s: + - "1.28" + - "1.29" + - "1.30" + steps: + - name: Checkout + uses: actions/checkout@v4 + + - name: Fetch history + run: git fetch --prune --unshallow + + - name: Create kind cluster + uses: helm/kind-action@v1.8.0 + with: + installLocalPathProvisioner: true # Only build a kind cluster if there are chart changes to test. + node_image: "kindest/node:v${{ matrix.k8s }}.0" + config: etc/kind.yaml + - run: kubectl get nodes + - name: Install Chart Tester + uses: helm/chart-testing-action@v2.4.0 + - name: Test charts + run: ct install diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..cca1ffb --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +charts/**/charts \ No newline at end of file diff --git a/charts/mammatus/.helmignore b/charts/mammatus/.helmignore new file mode 100644 index 0000000..50af031 --- /dev/null +++ b/charts/mammatus/.helmignore @@ -0,0 +1,22 @@ +# 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 +*~ +# Various IDEs +.project +.idea/ +*.tmproj +.vscode/ diff --git a/charts/mammatus/Chart.yaml b/charts/mammatus/Chart.yaml new file mode 100644 index 0000000..ea4b3cc --- /dev/null +++ b/charts/mammatus/Chart.yaml @@ -0,0 +1,10 @@ +apiVersion: v2 +name: mammatus +description: MammatusPHP Chart +type: application +version: 0.0.1 +appVersion: 0.0.1 +maintainers: + - name: WyriHaximus + email: helm@ceesjankiewiet.nl + url: https://wyrihaximus.net/ diff --git a/charts/mammatus/templates/_helpers.tpl b/charts/mammatus/templates/_helpers.tpl new file mode 100644 index 0000000..47393eb --- /dev/null +++ b/charts/mammatus/templates/_helpers.tpl @@ -0,0 +1,64 @@ +{{/* vim: set filetype=mustache: */}} +{{/* +Expand the name of the chart. +*/}} +{{- define "mammatus.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 "mammatus.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 "mammatus.chart" -}} +{{- printf "%s-%s" .Chart.Name .Chart.Version | replace "+" "_" | trunc 63 | trimSuffix "-" -}} +{{- end -}} + +{{/* +Common labels +*/}} +{{- define "mammatus.labels" -}} +helm.sh/chart: {{ include "mammatus.chart" . }} +{{ include "mammatus.selectorLabels" . }} +{{- if .Chart.AppVersion }} +app.kubernetes.io/version: {{ .Chart.AppVersion | quote }} +{{- end }} +app.kubernetes.io/managed-by: {{ .Release.Service }} +{{- end -}} + +{{/* +Selector labels +*/}} +{{- define "mammatus.selectorLabels" -}} +app.kubernetes.io/name: {{ include "mammatus.name" . }} +app.kubernetes.io/instance: {{ .Release.Name }} +{{- end -}} + +{{/* +Create the name of the service account to use +*/}} +{{- define "mammatus.serviceAccountName" -}} +{{- if .Values.serviceAccount.create -}} + {{ default (include "mammatus.fullname" .) .Values.serviceAccount.name }} +{{- else -}} + {{ default "default" .Values.serviceAccount.name }} +{{- end -}} +{{- end -}} + diff --git a/charts/mammatus/templates/_pod.yaml b/charts/mammatus/templates/_pod.yaml new file mode 100644 index 0000000..f6ec44f --- /dev/null +++ b/charts/mammatus/templates/_pod.yaml @@ -0,0 +1,72 @@ +{{/* vim: set filetype=mustache: */}} +{{- define "mammatus.pod" -}} +containers: + - name: {{ .name }} + image: "{{ .Values.image.repository }}:{{ .Chart.AppVersion }}" + imagePullPolicy: {{ .Values.image.pullPolicy }} + command: + - php + - /opt/app/vendor/bin/{{ .command | default "mamatus"}} + {{- range .arguments }} + - "{{ . | replace "\\" "\\\\" }}" + {{- end }} +{{- include "mammatus.env" . | nindent 4 }} + resources: + limits: + cpu: {{ $.Values.resources.cpu }} + memory: {{ $.Values.resources.memmory }} + requests: + cpu: {{ $.Values.resources.cpu }} + memory: {{ $.Values.resources.memmory }} +{{- include "mammatus.volumeMounts" . | nindent 4 }} +{{ include "mammatus.volumes" . }} +{{- end }} + +{{- define "mammatus.env" -}} +env: + - name: RELEASE_TAG + value: {{ .Chart.AppVersion }} + - name: POD_NAME + valueFrom: + fieldRef: + fieldPath: "metadata.name" + - name: POD_NAMESPACE + valueFrom: + fieldRef: + fieldPath: "metadata.namespace" +{{- if or .Values.env .Values.secrets }} +envFrom: +{{- end }} +{{- if .Values.secrets }} +{{- range .Values.secrets }} + - secretRef: + name: {{ .name }} + prefix: {{ .prefix }} +{{- end }} +{{- end }} +{{- if .Values.env }} + - configMapRef: + name: env +{{- end }} +{{- end -}} + +{{- define "mammatus.volumeMounts" -}} +{{ if .Values.volumes }} +volumeMounts: +{{- range $name, $options := .Values.volumes }} + - name: {{ $name }} + {{ $options.volumeMountOptions | toYaml }} +{{- end -}} +{{- end -}} +{{- end -}} + +{{- define "mammatus.volumes" -}} +{{ if .Values.volumes }} +volumes: +{{- range $name, $options := .Values.volumes }} + - name: {{ $name }} + {{- $options.volumeOptions | toYaml | nindent 4 }} +{{- end -}} +{{- end -}} +{{- end -}} + diff --git a/charts/mammatus/templates/configuration/env.yaml b/charts/mammatus/templates/configuration/env.yaml new file mode 100644 index 0000000..56b269d --- /dev/null +++ b/charts/mammatus/templates/configuration/env.yaml @@ -0,0 +1,10 @@ +{{ if $.Values.env }} +apiVersion: v1 +kind: ConfigMap +metadata: + name: env +data: + {{ range $configName, $configValue := $.Values.env -}} + {{ $configName }}: {{ $configValue | quote }} + {{- end -}} +{{ end }} diff --git a/charts/mammatus/templates/cronjobs.yaml b/charts/mammatus/templates/cronjobs.yaml new file mode 100644 index 0000000..167ca11 --- /dev/null +++ b/charts/mammatus/templates/cronjobs.yaml @@ -0,0 +1,26 @@ +{{- range .Values.mammatus.cronjobs }} +--- +apiVersion: batch/v1 +kind: CronJob +metadata: + name: {{ .name }} + labels: + app.kubernetes.io/name: {{ include "mammatus.name" $ }} + app.kubernetes.io/instance: {{ .name }} +spec: +{{- if eq $.Chart.AppVersion "dev" }} + schedule: "* * * * *" +{{- else }} + schedule: "{{ .schedule }}" +{{- end }} + concurrencyPolicy: Forbid + failedJobsHistoryLimit: 3 + successfulJobsHistoryLimit: 3 + jobTemplate: + spec: + backoffLimit: 0 + template: + spec: + restartPolicy: Never + {{- include "mammatus.pod" (dict "Chart" $.Chart "Values" $.Values "name" .name "arguments" .arguments) | nindent 10 }} +{{- end }} diff --git a/charts/mammatus/templates/deployment.yaml b/charts/mammatus/templates/deployment.yaml new file mode 100644 index 0000000..8048bbb --- /dev/null +++ b/charts/mammatus/templates/deployment.yaml @@ -0,0 +1,22 @@ +{{- range .Values.mammatus.deployments }} +--- +apiVersion: apps/v1 +kind: Deployment +metadata: + name: {{ .name }} + labels: + app.kubernetes.io/name: {{ include "mammatus.name" $ }} + app.kubernetes.io/instance: {{ .name }} +spec: + selector: + matchLabels: + app.kubernetes.io/name: {{ include "mammatus.name" $ }} + app.kubernetes.io/instance: {{ .name }} + template: + metadata: + labels: + app.kubernetes.io/name: {{ include "mammatus.name" $ }} + app.kubernetes.io/instance: {{ .name }} + spec: + {{- include "mammatus.pod" (dict "Chart" $.Chart "Values" $.Values "name" .name "arguments" .arguments) | nindent 6 }} +{{- end }} diff --git a/charts/mammatus/values.yaml b/charts/mammatus/values.yaml new file mode 100644 index 0000000..1ecb84f --- /dev/null +++ b/charts/mammatus/values.yaml @@ -0,0 +1,34 @@ +mammatus: + cronjobs: [] +# - name: some_job +# class: Some\Class\FQCN +# schedule: "0 3 * * *" + deployments: [] +# - name: some_worker +# command: mammatus-queue +# arguments: +# - Some\Class\FQCN +# - name: some_service +# command: mammatus-vhost +# arguments: +# - Some\Class\FQCN +# post: 666 + +env: {} +# key: value +secrets: [] +# - prefix: MQ_ +# name: mq_creds + +image: + repository: ghcr.io/LOGIN/REPO + pullPolicy: IfNotPresent + +resources: + cpu: 100m + memmory: 256Mi + +volumes: {} +# name: +# volumeMountOptions: {} +# volumeOptions: {} diff --git a/ct.yaml b/ct.yaml new file mode 100644 index 0000000..843e003 --- /dev/null +++ b/ct.yaml @@ -0,0 +1,7 @@ +remote: origin +target-branch: master +chart-dirs: + - charts +chart-repos: + - "WyriHaximusNet=https://helm.wyrihaximus.net" +debug: true diff --git a/etc/kind.yaml b/etc/kind.yaml new file mode 100644 index 0000000..2dcdccc --- /dev/null +++ b/etc/kind.yaml @@ -0,0 +1,31 @@ +kind: Cluster +apiVersion: kind.x-k8s.io/v1alpha4 +nodes: + - role: control-plane + kubeadmConfigPatches: + - | + kind: JoinConfiguration + nodeRegistration: + kubeletExtraArgs: + node-labels: "wyrihaximus.net/type=leader" + - role: worker + kubeadmConfigPatches: + - | + kind: JoinConfiguration + nodeRegistration: + kubeletExtraArgs: + node-labels: "wyrihaximus.net/type=worker" + - role: worker + kubeadmConfigPatches: + - | + kind: JoinConfiguration + nodeRegistration: + kubeletExtraArgs: + node-labels: "wyrihaximus.net/type=ingress" + - role: worker + kubeadmConfigPatches: + - | + kind: JoinConfiguration + nodeRegistration: + kubeletExtraArgs: + node-labels: "wyrihaximus.net/type=poen"