Skip to content

Commit

Permalink
ci(helm): Added a basic helm chart for heureka (#138)
Browse files Browse the repository at this point in the history
* Added a helm chart for heureka

* --amend

* --amend
  • Loading branch information
dimtas authored Aug 14, 2024
1 parent 01f55e2 commit 382725a
Show file tree
Hide file tree
Showing 15 changed files with 502 additions and 1 deletion.
95 changes: 95 additions & 0 deletions .github/workflows/helm-release.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
name: Package Helm Chart and publish to GitHub Packages

on:
workflow_dispatch: {}
push:
branches:
- main
paths:
- .github/workflows/helm-release.yaml
- charts/heureka


permissions:
contents: write
packages: write

env:
REGISTRY: ghcr.io
ACTIONS_RUNNER_DEBUG: false

jobs:
helm-release:
runs-on: [ default ]
strategy:
fail-fast: false
matrix:
include:
- chartDir: charts/heureka
chartName: heureka


steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
token: ${{ secrets.GITHUB_TOKEN }}

- name: Configure Git
run: |
git config user.name "$GITHUB_ACTOR"
git config user.email "[email protected]"
- name: Set up Helm
uses: azure/[email protected]

- uses: actions/setup-python@v5
with:
python-version: 3.9
check-latest: true
token: ${{ secrets.GITHUB_TOKEN }}

- name: Log into registry ${{ env.REGISTRY }}
if: github.event_name != 'pull_request'
uses: docker/login-action@v3
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}

- name: Get changed files
id: changed-files
uses: tj-actions/changed-files@v44
with:
files: |
${{ matrix.chartDir }}/**
- name: Check if Helm chart with same version already exists
id: check-chart
if: steps.changed-files.outputs.all_changed_files != ''
env:
ALL_CHANGED_FILES: ${{ steps.changed-files.outputs.all_changed_files }}
run: |
# List all changed
echo "All changed files: $ALL_CHANGED_FILES"
chartName=$(yq .name "${{ matrix.chartDir }}/Chart.yaml")
chartVersion=$(yq .version "${{ matrix.chartDir }}/Chart.yaml")
echo "chart_version=${chartVersion}" >> "$GITHUB_OUTPUT"
if $(helm pull "oci://${{ env.REGISTRY }}/${{ github.repository }}/charts/${{ matrix.chartName }}" --version $chartVersion); then
echo "bump=true" >> "$GITHUB_OUTPUT"
fi
- name: Chart needs version bump
if: steps.check-chart.outputs.bump == 'true'
env:
CHART_VERSION: ${{ steps.check-chart.outputs.chart_version }}
run: |
echo "Chart ${{ matrix.chartDir }}:${{ env.CHART_VERSION }} already exists in OCI registry. Skipping upload. Please increment the chart version."
exit 1
- name: Push Charts to GHCR
if: steps.changed-files.outputs.all_changed_files != '' && steps.check-chart.outputs.bump != 'true'
run: |
helm package ${{ matrix.chartDir }} -d ${{ matrix.chartDir }}
PKG_NAME=`ls ${{ matrix.chartDir }}/*.tgz`
helm push ${PKG_NAME} oci://${{ env.REGISTRY }}/${{ github.repository }}/charts/
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,5 @@
# Heureka specifics
build/
.db/
.env
.env
*.tgz
23 changes: 23 additions & 0 deletions charts/heureka/.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/heureka/Chart.lock
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
dependencies:
- name: mariadb
repository: https://charts.bitnami.com/bitnami
version: 19.0.3
digest: sha256:7ee2a1a9bea682f5bef8d7847ddd962bc67f76721ed3911f39aef82d1a9f67c4
generated: "2024-08-14T14:08:20.758927+02:00"
29 changes: 29 additions & 0 deletions charts/heureka/Chart.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
apiVersion: v2
name: heureka
description: A Helm chart for heureka

# 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

# 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.3.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: "1.16.0"

dependencies:
- name: mariadb
repository: https://charts.bitnami.com/bitnami
version: 19.0.3
1 change: 1 addition & 0 deletions charts/heureka/files/schema.sql
22 changes: 22 additions & 0 deletions charts/heureka/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 "heureka.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 the status of by running 'kubectl get --namespace {{ .Release.Namespace }} svc -w {{ include "heureka.fullname" . }}'
export SERVICE_IP=$(kubectl get svc --namespace {{ .Release.Namespace }} {{ include "heureka.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 "heureka.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 charts/heureka/templates/_helpers.tpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
{{/*
Expand the name of the chart.
*/}}
{{- define "heureka.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 "heureka.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 "heureka.chart" -}}
{{- printf "%s-%s" .Chart.Name .Chart.Version | replace "+" "_" | trunc 63 | trimSuffix "-" }}
{{- end }}

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

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

{{/*
Create the name of the service account to use
*/}}
{{- define "heureka.serviceAccountName" -}}
{{- if .Values.serviceAccount.create }}
{{- default (include "heureka.fullname" .) .Values.serviceAccount.name }}
{{- else }}
{{- default "default" .Values.serviceAccount.name }}
{{- end }}
{{- end }}
13 changes: 13 additions & 0 deletions charts/heureka/templates/database-schema-configmap.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{{ if .Files.Get "files/schema.sql" }}
apiVersion: v1
kind: ConfigMap
metadata:
name: {{ include "heureka.fullname" . }}-mariadb-schema
labels:
{{- include "heureka.labels" . | nindent 4 }}
data:
schema.sql: |-
{{ .Files.Get "files/schema.sql" | indent 6 }}
{{ else }}
{{ fail "Error: schema.sql file not found in files/ directory" }}
{{ end }}
86 changes: 86 additions & 0 deletions charts/heureka/templates/deployment.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
apiVersion: apps/v1
kind: Deployment
metadata:
name: {{ include "heureka.fullname" . }}
labels:
{{- include "heureka.labels" . | nindent 4 }}
app.kubernetes.io/managed-by: Helm
annotations:
prometheus.io/scrape: "true"
prometheus.io/targets: "kubernetes"
spec:
replicas: {{ .Values.replicaCount }}
selector:
matchLabels:
{{- include "heureka.selectorLabels" . | nindent 6 }}
template:
metadata:
labels:
{{- include "heureka.selectorLabels" . | nindent 8 }}
annotations:
prometheus.io/scrape: "true"
prometheus.io/targets: kubernetes
spec:
{{- with .Values.imagePullSecrets }}
imagePullSecrets:
{{- toYaml . | nindent 8 }}
{{- end }}
serviceAccountName: {{ include "heureka.serviceAccountName" . }}
containers:
- name: {{ .Chart.Name }}
image: "{{ .Values.image.repository }}:{{ .Values.serverTag }}"
imagePullPolicy: {{ .Values.image.pullPolicy }}
volumeMounts:
- name: mariadb-schema-init-volume
mountPath: /app/schema-init/schema.sql
subPath: schema.sql
env:
- name: ENVIRONMENT
valueFrom:
secretKeyRef:
name: {{ include "heureka.fullname" . }}
key: environment
- name: SERVER_PORT
value: ":{{ .Values.service.port }}"
- name: SEED_MODE
value: "{{ .Values.seedMode }}"
- name: DB_NAME
value: "heureka"
- name: DB_PORT
value: "3306"
- name: DB_SCHEMA
value: "/app/schema-init/schema.sql"
- name: DB_USER
value: "my_username"
- name: DB_PASSWORD
valueFrom:
secretKeyRef:
name: {{ include "heureka.fullname" . }}-mariadb
key: mariadb-password
- name: DB_ROOT_PASSWORD
valueFrom:
secretKeyRef:
name: {{ include "heureka.fullname" . }}-mariadb
key: mariadb-root-password
- name: DB_ADDRESS
value: "heureka-mariadb.heureka.svc.cluster.local"
ports:
- name: http
containerPort: {{ .Values.service.port }}
protocol: TCP
- name: metrics
containerPort: {{ .Values.service.port }}
livenessProbe:
httpGet:
path: /status
port: http
readinessProbe:
httpGet:
path: /ready
port: http
resources:
{{- toYaml .Values.resources | nindent 12 }}
volumes:
- name: mariadb-schema-init-volume
configMap:
name: {{ include "heureka.fullname" . }}-mariadb-schema
Loading

0 comments on commit 382725a

Please sign in to comment.