Skip to content

Commit

Permalink
chore: add helm chart
Browse files Browse the repository at this point in the history
  • Loading branch information
c0rydoras committed Feb 16, 2024
1 parent f4dc8bb commit 2eb14bf
Show file tree
Hide file tree
Showing 18 changed files with 751 additions and 42 deletions.
75 changes: 75 additions & 0 deletions .github/workflows/charts.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
name: Charts

on:
push:
branches:
- main
pull_request:
branches:
- main

jobs:
lint:
name: "Lint"
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4

- name: Set up Helm
uses: azure/setup-helm@v3.5
with:
version: v3.12.0

# Python is required because `ct lint` runs Yamale (https://github.com/23andMe/Yamale) and
# yamllint (https://github.com/adrienverge/yamllint) which require Python
- name: Set up Python
uses: actions/setup-python@v4
with:
python-version: 3.x

- name: Set up chart-testing
uses: helm/chart-testing-action@v2

- name: Run chart-testing (lint)
run: ct lint --config ct.yaml
test:
name: "Test"
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4

- name: Set up Helm
uses: azure/setup-helm@v3.5
with:
version: v3.12.0

- name: Set up chart-testing
uses: helm/chart-testing-action@v2

- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3

- name: Build API Docker Image
uses: docker/build-push-action@v5
with:
context: ./api/
load: true
tags: ghcr.io/${{ github.repository_owner }}/outdated/api:latest

- name: Build Ember Docker Image
uses: docker/build-push-action@v5
with:
context: ./ember/
load: true
tags: ghcr.io/${{ github.repository_owner }}/outdated/ember:latest

- name: Create kind cluster
uses: helm/kind-action@v1

- name: Load dev images into k8s
run: kind load docker-image ghcr.io/${{ github.repository_owner }}/outdated/api ghcr.io/${{ github.repository_owner }}/outdated/ember --name chart-testing

- name: Run chart-testing (install)
run: ct --config=ct.yaml install
41 changes: 0 additions & 41 deletions .github/workflows/docker-push.yml

This file was deleted.

83 changes: 83 additions & 0 deletions .github/workflows/publish.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
name: Publish

on:
push:
branches:
- main

jobs:
build-and-publish:
runs-on: ubuntu-latest
permissions:
contents: read
packages: write

steps:
- name: Checkout Repository
uses: actions/checkout@v4

- name: Login to GitHub Container Registry
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}

- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3

- name: Build and Push API Docker Image
uses: docker/build-push-action@v5
with:
context: ./api/
push: true
tags: ghcr.io/${{ github.repository_owner }}/outdated/api:latest

- name: Build and Push Ember Docker Image
uses: docker/build-push-action@v5
with:
context: ./ember/
push: true
tags: ghcr.io/${{ github.repository_owner }}/outdated/ember:latest

helm-chart:
runs-on: ubuntu-latest
needs:
build-and-publish
permissions:
actions: none
checks: none
contents: none
deployments: none
issues: none
packages: write
pull-requests: none
repository-projects: none
security-events: none
statuses: none
id-token: none
steps:
- name: Checkout
uses: actions/checkout@v4

- name: Prepare Chart Metadata
id: chartmeta
run: echo version=0.0.0+$(git rev-parse --short HEAD) >> $GITHUB_OUTPUT

- name: Set up Helm
uses: azure/setup-helm@v3.5
with:
version: v3.12.0

- name: Package Chart
run: helm package --version ${{ steps.chartmeta.outputs.version }} --app-version ${{ steps.chartmeta.outputs.version }} --destination=dist charts/outdated

- name: Login to GitHub Container Registry
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}

- name: Push Chart
run: helm push dist/*.tgz oci://ghcr.io/adfinis/outdated/helm
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,5 @@ __pycache__
.pytest_cache
.vscode
.coverage
rest_framework
rest_framework
charts/*/charts
23 changes: 23 additions & 0 deletions charts/outdated/.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/
6 changes: 6 additions & 0 deletions charts/outdated/Chart.lock
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
dependencies:
- name: postgresql
repository: https://charts.bitnami.com/bitnami
version: 14.0.5
digest: sha256:f9bfcbfaea579dd2cb446c9ef96a960ea042e22ab47e55405b56fb5e57341a92
generated: "2024-02-14T09:14:59.288031462+01:00"
29 changes: 29 additions & 0 deletions charts/outdated/Chart.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
apiVersion: v2
name: outdated
description: A Helm chart for Kubernetes

type: application

home: https://github.com/adfinis/outdated

maintainers:
- name: adfinis
email: support@adfinis.com
url: https://adfinis.com

# This is the chart version. This version number should be incremented each time you make changes
# to the chart and its templates, including the app version.
# Versions are expected to follow Semantic Versioning (https://semver.org/)
version: 0.0.0

# This is the version number of the application being deployed. This version number should be
# incremented each time you make changes to the application. Versions are not expected to
# follow Semantic Versioning. They should reflect the version the application is using.
# It is recommended to use it with quotes.
appVersion: "latest"

dependencies:
- name: postgresql
version: ~14.0.5
repository: https://charts.bitnami.com/bitnami
condition: postgresql.enabled
7 changes: 7 additions & 0 deletions charts/outdated/ci/default-values.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
postgresql:
enabled: true
auth:
password: outdated
ingress:
enabled: true
Empty file.
62 changes: 62 additions & 0 deletions charts/outdated/templates/_helpers.tpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
{{/*
Expand the name of the chart.
*/}}
{{- define "outdated.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 "outdated.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 "outdated.chart" -}}
{{- printf "%s-%s" .Chart.Name .Chart.Version | replace "+" "_" | trunc 63 | trimSuffix "-" }}
{{- end }}

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

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

{{/*
Create the name of the service account to use
*/}}
{{- define "outdated.serviceAccountName" -}}
{{- if .Values.serviceAccount.create }}
{{- default (include "outdated.fullname" .) .Values.serviceAccount.name }}
{{- else }}
{{- default "default" .Values.serviceAccount.name }}
{{- end }}
{{- end }}
17 changes: 17 additions & 0 deletions charts/outdated/templates/configmap.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
apiVersion: v1
kind: ConfigMap
metadata:
name: {{ template "outdated.fullname" . }}
labels:
{{- include "outdated.labels" . | nindent 4 }}
data:
OIDC_OP_BASE_ENDPOINT: {{ cat .Values.oidc.host "/realms/" .Values.oidc.realm "/protocol/openid-connect" | replace " " "" | quote }}
ALLOWED_HOSTS: {{ .Values.django.allowedHosts | quote }}
DEBUG: "false"
{{- if .Values.postgresql.enabled }}
DATABASE_HOST: "{{ template "outdated.fullname" . }}-postgresql.{{ .Release.Namespace }}"
DATABASE_NAME: {{ .Values.postgresql.auth.database }}
DATABASE_USER: {{ .Values.postgresql.auth.username }}
{{- end }}
OIDC_GROUPS_CLAIM: "groups"
SECRET_KEY: {{ randAscii 20 | quote }}
Loading

0 comments on commit 2eb14bf

Please sign in to comment.