Skip to content

Commit

Permalink
Add helm (#827)
Browse files Browse the repository at this point in the history
* Naive output of `helm create tiled`

* Update Chart and values

* Mount API key, config, set default port

* Working example from single_catalog_single_user

* Make use of fastapi healthz endpoint

* Add docs and enforce mounting api key as Secret

* Add github action to publish Helm chart

* Switch Service type to ClusterIP to prevent exposing prematurely

* Whitespace

* Example deployment level configuration

* Linting

* Adjust names of secrets to match RFC requirements

* Whitespace

* Ensure semVer compliance

* Remove leading v on tag if present to ensure semVer compatible

* Ensure Helm chart valid prior to first publish

* Defer SemVer parsing to docker metadata action
  • Loading branch information
DiamondJoseph authored Jan 9, 2025
1 parent 8e9608a commit 8b14aa8
Show file tree
Hide file tree
Showing 17 changed files with 590 additions and 2 deletions.
22 changes: 20 additions & 2 deletions .github/workflows/publish-image.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
# separate terms of service, privacy policy, and support
# documentation.

name: Create and publish image
name: Create and publish image and chart

on:
push:
Expand All @@ -15,7 +15,7 @@ env:
IMAGE_NAME: ${{ github.repository }}

jobs:
build-and-push-image:
build-and-push:
runs-on: ubuntu-latest
permissions:
contents: read
Expand All @@ -39,6 +39,8 @@ jobs:
uses: docker/metadata-action@98669ae865ea3cffbcbaa878cf57c20bbf1c6c38
with:
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
tags: |
type=semver,pattern={{version}}
- name: Build and push Docker image
uses: docker/build-push-action@ad44023a93711e3deb337508980b4b5e9bcdc5dc
Expand All @@ -48,3 +50,19 @@ jobs:
push: true
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}

- name: Install Helm
uses: Azure/setup-helm@v3
with:
token: ${{ secrets.GITHUB_TOKEN }}
id: install

- name: Log in to the Chart registry
run: |
echo ${{ secrets.GITHUB_TOKEN }} | helm registry login ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }} --username ${{ github.repository_owner }} --password-stdin
- name: Package and Push chart
run: |
helm dependencies update helm/tiled
helm package helm/tiled --version ${{ steps.meta.outputs.version }} --app-version ${{ steps.meta.outputs.version }} -d /tmp/
helm push /tmp/tiled-${{ steps.meta.outputs.version }}.tgz oci://ghcr.io/bluesky/charts
2 changes: 2 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ repos:
- id: check-merge-conflict
- id: check-symlinks
- id: check-yaml
# These yaml files output valid yaml only after templating
exclude: ^helm/tiled/templates/
- id: debug-statements

- repo: https://github.com/pycqa/flake8
Expand Down
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ Write the date in place of the "Unreleased" in the case a new version is release
- Fix bug where access policies were not applied to child nodes during request
- Add metadata-based access control to SimpleAccessPolicy
- Add example test of metadata-based allowed_scopes which requires the path to the target node
- Added Helm chart with deployable default configuration

### Fixed

Expand Down
98 changes: 98 additions & 0 deletions docs/source/how-to/helm.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
# Run Tiled Server from the Helm chart

There is an official Tiled helm chart image for use with
[Helm](https://helm.sh/) and [Kubernetes](https://kubernetes.io/).

## Quickstart

This quickstart guide installs the Tiled server configured with a single API key
with permissions to write and access all data. It is not intended for production use,
and is just a useful default with minimal configuration.

Installing the Helm chart with default values:

```
helm install tiled oci://ghcr.io/bluesky/charts/tiled
```

This Helm chart additionally refers to, but does not create, a Secret that contains
the value to use as the API key. It is highly recommended to use a
[SealedSecret](https://github.com/bitnami-labs/sealed-secrets#readme) if kubeseal is
available on the cluster you are installing into.

See the [Docker documentation](./docker.md) for instructions on creating a secure key.

```sh
# This will only decrypt in your namespace, in your cluster, and is safe to commit
$ echo -n <key> | kubeseal --raw --namespace <your namespace> --name tiled-secrets
AgCC...
```

Use the result as the body of a SealedSecret:

```yaml
apiVersion: bitnami.com/v1alpha1
kind: SealedSecret
metadata:
name: tiled-secrets
spec:
encryptedData:
TILED_SINGLE_USER_API_KEY: AgCC...
```
Apply the SealedSecret to the cluster with kubernetes:
```sh
kubectl apply -f secret.yaml
```

## Further Configuration

A common pattern for managing the configuration of a Helm chart is to wrap the config
as another layer of chart, with the bundled instance configuration and the dependent
charts kept under source control.

```
(
| Chart.yaml
| values.yaml
| \templates
| secret.yaml
| .git
```

The dependent chart(s): tiled and any other services that *should live and die with the
tiled instance* can be referenced from the Chart.yaml:

```yaml
apiVersion: v2
name: my-install-of-tiled
description: tiled configured for use at...

version: 0.1.0
appVersion: v0.1.0b12

type: application

dependencies:
# Fetches the tiled Helm chart with version 0.1.0
- name: tiled
version: "0.1.0"
repository: "oci://ghcr.io/bluesky/charts"
```
While overrides for the bundled values.yaml in each dependency chart can be passed
as part of the values.yaml.
Note that the `name` in the `dependencies` in the Chart.yaml give the top-level key
to use in the values.yaml:

```yaml
tiled:
# This is mounted as config.yaml to the tiled container
# Replacing `config` value in the helm/tiled/values.yaml file in this repository
config: {}
```
Additional templates to be deployed alongside the tiled server can be defined- for
example the SealedSecret defined above.
1 change: 1 addition & 0 deletions docs/source/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ how-to/authentication
how-to/profiles
how-to/client-logger
how-to/docker
how-to/helm
how-to/configuration
how-to/read-custom-formats
how-to/custom-export-formats
Expand Down
23 changes: 23 additions & 0 deletions helm/tiled/.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/
19 changes: 19 additions & 0 deletions helm/tiled/Chart.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
apiVersion: v2
name: tiled
description: Tiled is a data access service for data-aware portals and data science tools.

# A chart can be either an 'application' or a 'library' chart.
#
# Application charts are a collection of templates that can be packaged into versioned archives
# to be deployed.
#
# Library charts provide useful utilities or functions for the chart developer. They're included as
# a dependency of application charts to inject those utilities and functions into the rendering
# pipeline. Library charts do not define any templates and therefore cannot be deployed.
type: application

# Chart version, automatically incremented by CI during release
version: 0.0.1

# Container version, automatically incremented by CI during release
appVersion: v0.1.0b12
22 changes: 22 additions & 0 deletions helm/tiled/templates/NOTES.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
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 "tiled.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 its status by running 'kubectl get --namespace {{ .Release.Namespace }} svc -w {{ include "tiled.fullname" . }}'
export SERVICE_IP=$(kubectl get svc --namespace {{ .Release.Namespace }} {{ include "tiled.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 "tiled.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 }}
62 changes: 62 additions & 0 deletions helm/tiled/templates/_helpers.tpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
{{/*
Expand the name of the chart.
*/}}
{{- define "tiled.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 "tiled.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 "tiled.chart" -}}
{{- printf "%s-%s" .Chart.Name .Chart.Version | replace "+" "_" | trunc 63 | trimSuffix "-" }}
{{- end }}

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

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

{{/*
Create the name of the service account to use
*/}}
{{- define "tiled.serviceAccountName" -}}
{{- if .Values.serviceAccount.create }}
{{- default (include "tiled.fullname" .) .Values.serviceAccount.name }}
{{- else }}
{{- default "default" .Values.serviceAccount.name }}
{{- end }}
{{- end }}
7 changes: 7 additions & 0 deletions helm/tiled/templates/configmap.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
apiVersion: v1
kind: ConfigMap
metadata:
name: {{ include "tiled.fullname" . }}-config
data:
config.yaml: |-
{{- toYaml .Values.config | nindent 4 }}
77 changes: 77 additions & 0 deletions helm/tiled/templates/deployment.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
apiVersion: apps/v1
kind: Deployment
metadata:
name: {{ include "tiled.fullname" . }}
labels:
{{- include "tiled.labels" . | nindent 4 }}
spec:
{{- if not .Values.autoscaling.enabled }}
replicas: {{ .Values.replicaCount }}
{{- end }}
selector:
matchLabels:
{{- include "tiled.selectorLabels" . | nindent 6 }}
template:
metadata:
{{- with .Values.podAnnotations }}
annotations:
{{- toYaml . | nindent 8 }}
{{- end }}
labels:
{{- include "tiled.labels" . | nindent 8 }}
{{- with .Values.podLabels }}
{{- toYaml . | nindent 8 }}
{{- end }}
spec:
{{- with .Values.imagePullSecrets }}
imagePullSecrets:
{{- toYaml . | nindent 8 }}
{{- end }}
serviceAccountName: {{ include "tiled.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 }}
ports:
- name: http
containerPort: {{ .Values.service.port }}
protocol: TCP
livenessProbe:
{{- toYaml .Values.livenessProbe | nindent 12 }}
readinessProbe:
{{- toYaml .Values.readinessProbe | nindent 12 }}
resources:
{{- toYaml .Values.resources | nindent 12 }}
volumeMounts:
{{- with .Values.volumeMounts }}
{{- toYaml . | nindent 12 }}
{{- end }}
{{- with .Values.extraEnvVars }}
env:
{{- toYaml . | nindent 12 }}
{{- end }}
volumes:
- name: config
projected:
sources:
- configMap:
name: {{ include "tiled.fullname" . }}-config
{{- 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 }}
Loading

0 comments on commit 8b14aa8

Please sign in to comment.