Skip to content

Commit 542e3b1

Browse files
Helm Chart (#73)
* Create helm chart * Add CI job for publishing helm chart
1 parent 568c3ca commit 542e3b1

11 files changed

Lines changed: 309 additions & 0 deletions

File tree

.github/workflows/helm.yml

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
name: Helm CI
2+
3+
on:
4+
push:
5+
tags:
6+
- "*"
7+
8+
env:
9+
GCR_IMAGE: ghcr.io/diamondlightsource/blueapi
10+
HELM_VERSION: 3.10.3
11+
12+
jobs:
13+
build:
14+
name: publish gcr
15+
runs-on: ubuntu-latest
16+
environment: prod
17+
steps:
18+
- name: checkout repo
19+
uses: actions/checkout@v3
20+
21+
- name: install helm
22+
uses: Azure/setup-helm@v3
23+
with:
24+
token: ${{ secrets.GITHUB_TOKEN }}
25+
id: install
26+
27+
- name: login to acr using helm
28+
run: |
29+
echo ${{ secrets.GITHUB_TOKEN }} | helm registry login ${{ env.GCR_IMAGE }} --username ${{ github.repository_owner }} --password-stdin
30+
- name: Extract metadata (tags, labels) for Docker
31+
id: meta
32+
uses: docker/metadata-action@57396166ad8aefe6098280995947635806a0e6ea
33+
with:
34+
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
35+
tags: |
36+
type=ref,event=tag
37+
- name: package chart and push it
38+
run: |
39+
sed -i "$ a appVersion: ${GITHUB_REF##*/}" helm/blueapi/Chart.yaml
40+
helm dependencies update helm/blueapi
41+
helm package helm/blueapi --version ${GITHUB_REF##*/} -d /tmp/
42+
helm push /tmp/blueapi-${GITHUB_REF##*/}.tgz oci://ghcr.io/diamondlightsource/charts

.pre-commit-config.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ repos:
44
hooks:
55
- id: check-added-large-files
66
- id: check-yaml
7+
exclude: ^helm\/.*\/templates\/.*
78
- id: check-merge-conflict
89

910
- repo: local

helm/blueapi/.helmignore

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
# Patterns to ignore when building packages.
2+
# This supports shell glob matching, relative path matching, and
3+
# negation (prefixed with !). Only one pattern per line.
4+
.DS_Store
5+
# Common VCS dirs
6+
.git/
7+
.gitignore
8+
.bzr/
9+
.bzrignore
10+
.hg/
11+
.hgignore
12+
.svn/
13+
# Common backup files
14+
*.swp
15+
*.bak
16+
*.tmp
17+
*.orig
18+
*~
19+
# Various IDEs
20+
.project
21+
.idea/
22+
*.tmproj
23+
.vscode/

helm/blueapi/Chart.yaml

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
apiVersion: v2
2+
name: blueapi
3+
description: A helm chart deploying a worker pod that runs Bluesky plans
4+
5+
# A chart can be either an 'application' or a 'library' chart.
6+
#
7+
# Application charts are a collection of templates that can be packaged into versioned archives
8+
# to be deployed.
9+
#
10+
# Library charts provide useful utilities or functions for the chart developer. They're included as
11+
# a dependency of application charts to inject those utilities and functions into the rendering
12+
# pipeline. Library charts do not define any templates and therefore cannot be deployed.
13+
type: application
14+
15+
# This is the chart version. This version number should be incremented each time you make changes
16+
# to the chart and its templates, including the app version.
17+
# Versions are expected to follow Semantic Versioning (https://semver.org/)
18+
# This is updated automatically by CI, the appVersion is automatically inserted by CI
19+
version: 0.1.0

helm/blueapi/templates/NOTES.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
1. Worker will be deployed with the following config:
2+
{{- .Values.worker }}
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
{{/*
2+
Expand the name of the chart.
3+
*/}}
4+
{{- define "blueapi.name" -}}
5+
{{- default .Chart.Name .Values.nameOverride | trunc 63 | trimSuffix "-" }}
6+
{{- end }}
7+
8+
{{/*
9+
Create a default fully qualified app name.
10+
We truncate at 63 chars because some Kubernetes name fields are limited to this (by the DNS naming spec).
11+
If release name contains chart name it will be used as a full name.
12+
*/}}
13+
{{- define "blueapi.fullname" -}}
14+
{{- if .Values.fullnameOverride }}
15+
{{- .Values.fullnameOverride | trunc 63 | trimSuffix "-" }}
16+
{{- else }}
17+
{{- $name := default .Chart.Name .Values.nameOverride }}
18+
{{- if contains $name .Release.Name }}
19+
{{- .Release.Name | trunc 63 | trimSuffix "-" }}
20+
{{- else }}
21+
{{- printf "%s-%s" .Release.Name $name | trunc 63 | trimSuffix "-" }}
22+
{{- end }}
23+
{{- end }}
24+
{{- end }}
25+
26+
{{/*
27+
Create chart name and version as used by the chart label.
28+
*/}}
29+
{{- define "blueapi.chart" -}}
30+
{{- printf "%s-%s" .Chart.Name .Chart.Version | replace "+" "_" | trunc 63 | trimSuffix "-" }}
31+
{{- end }}
32+
33+
{{/*
34+
Common labels
35+
*/}}
36+
{{- define "blueapi.labels" -}}
37+
helm.sh/chart: {{ include "blueapi.chart" . }}
38+
{{ include "blueapi.selectorLabels" . }}
39+
{{- if .Chart.AppVersion }}
40+
app.kubernetes.io/version: {{ .Chart.AppVersion | quote }}
41+
{{- end }}
42+
app.kubernetes.io/managed-by: {{ .Release.Service }}
43+
{{- end }}
44+
45+
{{/*
46+
Selector labels
47+
*/}}
48+
{{- define "blueapi.selectorLabels" -}}
49+
app.kubernetes.io/name: {{ include "blueapi.name" . }}
50+
app.kubernetes.io/instance: {{ .Release.Name }}
51+
{{- end }}
52+
53+
{{/*
54+
Create the name of the service account to use
55+
*/}}
56+
{{- define "blueapi.serviceAccountName" -}}
57+
{{- if .Values.serviceAccount.create }}
58+
{{- default (include "blueapi.fullname" .) .Values.serviceAccount.name }}
59+
{{- else }}
60+
{{- default "default" .Values.serviceAccount.name }}
61+
{{- end }}
62+
{{- end }}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
apiVersion: v1
2+
kind: ConfigMap
3+
metadata:
4+
name: {{ include "blueapi.fullname" . }}-config
5+
data:
6+
config.yaml: |-
7+
{{- toYaml .Values.worker | nindent 4 }}
8+
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
apiVersion: apps/v1
2+
kind: Deployment
3+
metadata:
4+
name: {{ include "blueapi.fullname" . }}
5+
labels:
6+
{{- include "blueapi.labels" . | nindent 4 }}
7+
spec:
8+
replicas: {{ .Values.replicaCount }}
9+
selector:
10+
matchLabels:
11+
{{- include "blueapi.selectorLabels" . | nindent 6 }}
12+
template:
13+
metadata:
14+
{{- with .Values.podAnnotations }}
15+
annotations:
16+
{{- toYaml . | nindent 8 }}
17+
{{- end }}
18+
labels:
19+
{{- include "blueapi.selectorLabels" . | nindent 8 }}
20+
spec:
21+
{{- with .Values.imagePullSecrets }}
22+
imagePullSecrets:
23+
{{- toYaml . | nindent 8 }}
24+
{{- end }}
25+
serviceAccountName: {{ include "blueapi.serviceAccountName" . }}
26+
securityContext:
27+
{{- toYaml .Values.podSecurityContext | nindent 8 }}
28+
volumes:
29+
- name: worker-config
30+
configMap:
31+
name: {{ include "blueapi.fullname" . }}-config
32+
containers:
33+
- name: {{ .Chart.Name }}
34+
securityContext:
35+
{{- toYaml .Values.securityContext | nindent 12 }}
36+
image: "{{ .Values.image.repository }}:{{ .Values.image.tag | default .Chart.AppVersion }}"
37+
imagePullPolicy: {{ .Values.image.pullPolicy }}
38+
resources:
39+
{{- toYaml .Values.resources | nindent 12 }}
40+
volumeMounts:
41+
- name: worker-config
42+
mountPath: "/config"
43+
readOnly: true
44+
command: ["bluesky"]
45+
args: ["worker", "-c", "/config/config.yaml"]
46+
{{- with .Values.nodeSelector }}
47+
nodeSelector:
48+
{{- toYaml . | nindent 8 }}
49+
{{- end }}
50+
{{- with .Values.affinity }}
51+
affinity:
52+
{{- toYaml . | nindent 8 }}
53+
{{- end }}
54+
{{- with .Values.tolerations }}
55+
tolerations:
56+
{{- toYaml . | nindent 8 }}
57+
{{- end }}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
{{- if .Values.serviceAccount.create -}}
2+
apiVersion: v1
3+
kind: ServiceAccount
4+
metadata:
5+
name: {{ include "blueapi.serviceAccountName" . }}
6+
labels:
7+
{{- include "blueapi.labels" . | nindent 4 }}
8+
{{- with .Values.serviceAccount.annotations }}
9+
annotations:
10+
{{- toYaml . | nindent 4 }}
11+
{{- end }}
12+
{{- end }}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
apiVersion: v1
2+
kind: Pod
3+
metadata:
4+
name: "{{ include "blueapi.fullname" . }}-test-ping"
5+
labels:
6+
{{- include "blueapi.labels" . | nindent 4 }}
7+
annotations:
8+
"helm.sh/hook": test
9+
"helm.sh/hook-delete-policy": before-hook-creation,hook-succeeded
10+
spec:
11+
containers:
12+
- name: ping
13+
image: "{{ .Values.image.repository }}:{{ .Values.image.tag | default .Chart.AppVersion }}"
14+
imagePullPolicy: {{ .Values.image.pullPolicy }}
15+
command: ["bluesky"]
16+
args: ["controller", "-h", "{{ .Values.worker.stomp.host }}", "-p", "{{ .Values.worker.stomp.port }}", "plans"]
17+
restartPolicy: Never

0 commit comments

Comments
 (0)