Skip to content

Commit

Permalink
feat: add helm chart
Browse files Browse the repository at this point in the history
  • Loading branch information
moshloop committed Dec 5, 2024
1 parent 42ef19d commit e75137f
Show file tree
Hide file tree
Showing 6 changed files with 182 additions and 0 deletions.
47 changes: 47 additions & 0 deletions .github/workflows/release.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -62,3 +62,50 @@ jobs:
dockerfile: Dockerfile
tags: "latest,v${{ needs.semantic-release.outputs.release-version }}"


helm:
runs-on: ubuntu-latest
needs: [semantic-release, docker]
if: needs.semantic-release.outputs.new-release-published == 'true'
steps:
- uses: actions/checkout@ee0669bd1cc54295c223e0bb666b733df41de1c5 # v2.7.0
- name: Download yq
run: |
wget -nv -nc -O yq https://github.com/mikefarah/yq/releases/download/v4.20.2/yq_linux_amd64
chmod +x yq
- name: Set version
# Always use git tags as semantic release can fail due to rate limit
run: |
git fetch --prune --unshallow
echo "RELEASE_VERSION=$(git describe --abbrev=0 --tags | sed -e 's/^v//')" >> $GITHUB_ENV
- name: Update chart version
run: ./yq -i e '.version = "${{ env.RELEASE_VERSION }}"' chart/Chart.yaml
- name: Update app version
run: ./yq -i e '.appVersion = "${{ env.RELEASE_VERSION }}"' chart/Chart.yaml
- name: Update image tags
run: ./yq -i e '.image.tag = "v${{ env.RELEASE_VERSION }}"' chart/values.yaml
- name: Set up Helm
uses: azure/setup-helm@18bc76811624f360dbd7f18c2d4ecb32c7b87bab # v1.1
with:
version: v3.8.0
- name: Package Helm chart
run: |
helm package ./chart
- name: Clone charts repo
uses: actions/checkout@8e5e7e5ab8b370d6c329ec480221332ada57f0ab # v3.5.2
with:
repository: "${{ github.repository_owner }}/charts"
path: charts
token: "${{ secrets.FLANKBOT }}"
- name: Update chart repo
run: |
cd charts
cp ../batch-runner-*.tgz ./
helm repo index --merge index.yaml .
- name: Push changes to chart repo
uses: stefanzweifel/git-auto-commit-action@3ea6ae190baf489ba007f7c92608f33ce20ef04a # v4.16.0
with:
commit_message: "Release ${{ needs.semantic-release.outputs.release-version }} of ${{ github.repository }}"
branch: gh-pages
repository: ./charts

6 changes: 6 additions & 0 deletions chart/Chart.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
apiVersion: v2
name: batch-runner
description: A Helm chart for creating pods or jobs for every message in a queue
type: application
version: 0.1.0
appVersion: "1.0.0"
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 "batch-runner.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 "batch-runner.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 "batch-runner.chart" -}}
{{- printf "%s-%s" .Chart.Name .Chart.Version | replace "+" "_" | trunc 63 | trimSuffix "-" }}
{{- end }}

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

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

{{/*
Create the name of the service account to use
*/}}
{{- define "batch-runner.serviceAccountName" -}}
{{- if .Values.serviceAccount.create }}
{{- default (include "batch-runner.fullname" .) .Values.serviceAccount.name }}
{{- else }}
{{- default "default" .Values.serviceAccount.name }}
{{- end }}
{{- end }}
21 changes: 21 additions & 0 deletions chart/templates/deployment.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
apiVersion: apps/v1
kind: Deployment
metadata:
name: {{ include "batch-runner.fullname" . }}
labels:
{{- include "batch-runner.labels" . | nindent 4 }}
spec:
replicas: {{ .Values.replicaCount }}
selector:
matchLabels:
{{- include "batch-runner.selectorLabels" . | nindent 6 }}
template:
metadata:
labels:
{{- include "batch-runner.selectorLabels" . | nindent 8 }}
spec:
serviceAccountName: {{ include "batch-runner.serviceAccountName" . }}
containers:
- name: {{ .Chart.Name }}
image: "{{ .Values.image.repository }}:{{ .Values.image.tag | default .Chart.AppVersion }}"
imagePullPolicy: {{ .Values.image.pullPolicy }}
37 changes: 37 additions & 0 deletions chart/templates/serviceaccount.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
{{- if .Values.serviceAccount.create -}}
apiVersion: v1
kind: ServiceAccount
metadata:
name: {{ include "batch-runner.serviceAccountName" . }}
labels:
{{- include "batch-runner.labels" . | nindent 4 }}
---
apiVersion: rbac.authorization.k8s.io/v1
kind: Role
metadata:
name: batch-runner-role
labels:
{{- include "batch-runner.labels" . | nindent 4 }}
rules:
- apiGroups: [""]
resources: ["pods"]
verbs: ["*"]
- apiGroups: ["batch/v1"]
resources: ["jobs"]
verbs: ["*"]
---
apiVersion: rbac.authorization.k8s.io/v1
kind: RoleBinding
metadata:
name: batch-runner-binding
labels:
{{- include "batch-runner.labels" . | nindent 4 }}
roleRef:
apiGroup: rbac.authorization.k8s.io
kind: Role
name: batch-runner-role
subjects:
- kind: ServiceAccount
name: {{ include "batch-runner.serviceAccountName" . }}
namespace: {{ .Release.Namespace }}
{{- end }}
9 changes: 9 additions & 0 deletions chart/values.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
replicaCount: 1
image:
repository: flanksource/batch-runner
tag: latest
pullPolicy: IfNotPresent

serviceAccount:
create: true
name: batch-runner-sa

0 comments on commit e75137f

Please sign in to comment.