Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
69 changes: 69 additions & 0 deletions .github/workflows/helm.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
name: publish-chart

permissions:
packages: write
contents: read

on:
# we only publish the chart after succesful Docker build so we trigger
# a full build when chart templates are changed, this is slightly suboptimal
# TODO automatically bump chart version during build
workflow_run:
workflows: ["publish-image"]
types: [completed]
branches: ["main"]

jobs:
publish-chart:
if: ${{ github.event.workflow_run.conclusion == 'success' }}
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
include:
- chart_name: mod-cyclops
chart_base_version: "0.1.0-main.${{ github.run_number }}"
chart_path: ./chart
md_path: ./descriptors/ModuleDescriptor-template.json
steps:
- uses: actions/checkout@v6

- name: Calculate chart and app version with short SHA
run: |
SHORT_SHA=$(echo $GITHUB_SHA | cut -c1-7)
ARTIFACT_ID=$(sed -n 's|^module .*/||p' go.mod)
CHART_VERSION="${{ matrix.chart_base_version }}+sha.$SHORT_SHA"
APP_VERSION="sha-$SHORT_SHA"
echo "ARTIFACT_ID=$ARTIFACT_ID" >> $GITHUB_ENV
echo "CHART_VERSION=$CHART_VERSION" >> $GITHUB_ENV
echo "APP_VERSION=$APP_VERSION" >> $GITHUB_ENV

- name: Process MD for okapi-hooks
if: ${{ matrix.md_path }}
run: |
sed -i -e "s/@artifactId@/$ARTIFACT_ID/g" -e "s/@version@/$CHART_VERSION/g" ${{ matrix.md_path }}
sed 's/^/ /' ${{ matrix.md_path }} > indented.json
sed -i -e '/@descriptor@/{
r indented.json
d
}' ${{ matrix.chart_path }}/values.yaml

- name: helm lint
run: |
helm lint ${{ matrix.chart_path }}

- name: helm login
run: |
echo ${{ secrets.GITHUB_TOKEN }} | helm registry login ghcr.io -u $ --password-stdin

- name: helm dependency
run: |
helm dependency build ${{ matrix.chart_path }}

- name: helm package
run: |
helm package ${{ matrix.chart_path }} --version "$CHART_VERSION" --app-version "$APP_VERSION"

- name: helm push
run: |
helm push "${{ matrix.chart_name }}-$CHART_VERSION.tgz" oci://ghcr.io/${{ github.repository_owner }}/charts
23 changes: 23 additions & 0 deletions chart/.helmignore
Original file line number Diff line number Diff line change
@@ -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/
16 changes: 16 additions & 0 deletions chart/Chart.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
apiVersion: v2
name: mod-cyclops
description: Mod Cyclops
type: application

# Use semver, note that this is replaced by the publish action
version: 0.1.0

# appVersion is used as the Docker image tag by the chart
appVersion: "main"

dependencies:
- name: okapi-hooks
repository: oci://ghcr.io/indexdata/charts
version: ">0.1.0-0"
condition: okapi-hooks.enabled
62 changes: 62 additions & 0 deletions chart/templates/_helpers.tpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
{{/*
Expand the name of the chart.
*/}}
{{- define "..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 "..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 "..chart" -}}
{{- printf "%s-%s" .Chart.Name .Chart.Version | replace "+" "_" | trunc 63 | trimSuffix "-" }}
{{- end }}

{{/*
Common labels
*/}}
{{- define "..labels" -}}
helm.sh/chart: {{ include "..chart" . }}
{{ include "..selectorLabels" . }}
{{- if .Chart.AppVersion }}
app.kubernetes.io/version: {{ .Chart.AppVersion | quote }}
{{- end }}
app.kubernetes.io/managed-by: {{ .Release.Service }}
{{- end }}

{{/*
Selector labels
*/}}
{{- define "..selectorLabels" -}}
app.kubernetes.io/name: {{ include "..name" . }}
app.kubernetes.io/instance: {{ .Release.Name }}
{{- end }}

{{/*
Create the name of the service account to use
*/}}
{{- define "..serviceAccountName" -}}
{{- if .Values.serviceAccount.create }}
{{- default (include "..fullname" .) .Values.serviceAccount.name }}
{{- else }}
{{- default "default" .Values.serviceAccount.name }}
{{- end }}
{{- end }}
100 changes: 100 additions & 0 deletions chart/templates/deployment.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
apiVersion: apps/v1
kind: Deployment
metadata:
name: {{ include "..fullname" . }}
labels:
{{- include "..labels" . | nindent 4 }}
spec:
{{- if not .Values.autoscaling.enabled }}
replicas: {{ .Values.replicaCount }}
{{- end }}
selector:
matchLabels:
{{- include "..selectorLabels" . | nindent 6 }}
template:
metadata:
{{- with .Values.podAnnotations }}
annotations:
{{- toYaml . | nindent 8 }}
{{- end }}
labels:
{{- include "..labels" . | nindent 8 }}
{{- with .Values.podLabels }}
{{- toYaml . | nindent 8 }}
{{- end }}
spec:
{{- with .Values.imagePullSecrets }}
imagePullSecrets:
{{- toYaml . | nindent 8 }}
{{- end }}
serviceAccountName: {{ include "..serviceAccountName" . }}
securityContext:
{{- toYaml .Values.podSecurityContext | nindent 8 }}
containers:
- name: {{ .Chart.Name }}
env:
- name: HTTP_PORT
value: "{{ .Values.containerPort }}"
{{- range $k, $v := .Values.env }}
{{- if ne $k "HTTP_PORT" }}
- name: {{ $k }}
value: "{{ $v }}"
{{- end }}
{{- end }}
{{- range $k, $v := .Values.envSecrets }}
{{- if ne $k "HTTP_PORT" }}
- name: {{ $k }}
valueFrom:
secretKeyRef:
name: "{{ $v.name }}"
key: "{{ $v.key }}"
{{- end }}
{{- end }}
{{- range $k, $v := .Values.envConfigMaps }}
{{- if ne $k "HTTP_PORT" }}
- name: {{ $k }}
valueFrom:
configMapKeyRef:
name: "{{ $v.name }}"
key: "{{ $v.key }}"
{{- end }}
{{- end }}
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.containerPort }}
protocol: TCP
# there is no healthz. -ih
#livenessProbe:
# httpGet:
# path: /healthz
# port: http
#readinessProbe:
# httpGet:
# path: /healthz
# port: http
resources:
{{- toYaml .Values.resources | nindent 12 }}
{{- with .Values.volumeMounts }}
volumeMounts:
{{- toYaml . | nindent 12 }}
{{- end }}
{{- with .Values.volumes }}
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 }}
19 changes: 19 additions & 0 deletions chart/templates/service.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
apiVersion: v1
kind: Service
metadata:
name: {{ include "..fullname" . }}
{{- with .Values.serviceAnnotations }}
annotations:
{{- toYaml . | nindent 8 }}
{{- end }}
labels:
{{- include "..labels" . | nindent 4 }}
spec:
type: {{ .Values.service.type }}
ports:
- port: {{ .Values.service.httpPort }}
targetPort: {{ .Values.service.httpTargetPort }}
protocol: TCP
name: http
selector:
{{- include "..selectorLabels" . | nindent 4 }}
13 changes: 13 additions & 0 deletions chart/templates/serviceaccount.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{{- if .Values.serviceAccount.create -}}
apiVersion: v1
kind: ServiceAccount
metadata:
name: {{ include "..serviceAccountName" . }}
labels:
{{- include "..labels" . | nindent 4 }}
{{- with .Values.serviceAccount.annotations }}
annotations:
{{- toYaml . | nindent 4 }}
{{- end }}
automountServiceAccountToken: {{ .Values.serviceAccount.automount }}
{{- end }}
Loading