Skip to content

Commit

Permalink
devel
Browse files Browse the repository at this point in the history
  • Loading branch information
theshell76 committed Oct 2, 2024
1 parent 351a83b commit f826861
Show file tree
Hide file tree
Showing 15 changed files with 374 additions and 1 deletion.
68 changes: 68 additions & 0 deletions .github/workflows/publish-chart.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
name: Publish helm chart
run-name: Publish helm chart

on:
push:
tags: ["chart-*"]
branches: ['main', 'devel']
paths: ['chart/**']

env:
CHART_PATH: chart
UPDATE_DEPS: 'false'
# GitHub Container registry
GHCR_NAME: ${{ github.repository_owner }}/helm
# Docker Hub
# DHUB_NAME: insios-helm
# DHUB_USERNAME: ${{ secrets.INSIOS_DOCKER_USERNAME }}
# DHUB_PASSWORD: ${{ secrets.INSIOS_DOCKER_PASSWORD }}

jobs:
build-and-push-image:
runs-on: ubuntu-latest
permissions:
contents: read
packages: write
attestations: write
id-token: write

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

- name: Install Helm
uses: azure/setup-helm@v4

- name: Extract metadata (chart name, tag)
id: meta
run: |
echo "name=$(helm show chart ${{ env.CHART_PATH }} | grep 'name:' | awk '{print $2}')" >> "$GITHUB_OUTPUT"
if [[ "${{ github.ref_type }}" == "tag" ]]; then
echo "tag=$(echo '${{ github.ref_name }}' | awk -F '-' '{print $2}')" >> "$GITHUB_OUTPUT"
else
echo "tag=0.0.0-${{ github.ref_name }}" >> "$GITHUB_OUTPUT"
fi
- name: Build and push Helm chart to Container registry
uses: appany/helm-oci-chart-releaser@v0.4.2
with:
path: ${{ env.CHART_PATH }}
update_dependencies: '${{ env.UPDATE_DEPS }}'
name: ${{ steps.meta.outputs.name }}
tag: ${{ steps.meta.outputs.tag }}
registry: ghcr.io
registry_username: ${{ github.actor }}
registry_password: ${{ secrets.GITHUB_TOKEN }}
repository: ${{ env.GHCR_NAME }}

# - name: Build and push Helm chart to Docker Hub
# uses: appany/helm-oci-chart-releaser@v0.4.2
# with:
# path: ${{ env.CHART_PATH }}
# update_dependencies: '${{ env.UPDATE_DEPS }}'
# name: ${{ steps.meta.outputs.name }}
# tag: ${{ steps.meta.outputs.tag }}
# registry: registry-1.docker.io
# registry_username: ${{ env.DHUB_USERNAME }}
# registry_password: ${{ env.DHUB_PASSWORD }}
# repository: ${{ env.DHUB_NAME }}
10 changes: 10 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# Visual Studio Code
.vscode/
.history/
*.vsix

# Chart autogenerated README
chart/README-hd.md

# Local development
devel/local/
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
# generic-chart
# INSIOS/generic-chart

Generic Helm chart for various applications.
23 changes: 23 additions & 0 deletions chart/.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/
33 changes: 33 additions & 0 deletions chart/Chart.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
apiVersion: v2
name: generic
description: Generic Helm chart for various applications

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

keywords:
- generic
- application

home: https://github.com/insios/generic-chart

sources:
- https://github.com/insios/generic-chart
5 changes: 5 additions & 0 deletions chart/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# INSIOS/generic-chart

Generic Helm chart for various applications.

See [https://github.com/insios/generic-chart](https://github.com/insios/generic-chart)
83 changes: 83 additions & 0 deletions chart/templates/_helpers.tpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
{{/*
Create chart name and version as used by the chart label.
*/}}
{{- define "generic.fullChartName" -}}
{{- printf "%s-%s" .Chart.Name .Chart.Version | replace "+" "_" | trunc 63 | trimSuffix "-" }}
{{- end }}

{{/*
Expand the name of the app.
*/}}
{{- define "generic.appName" -}}
{{- default .Release.Name (.Values.app).name }}
{{- end }}

{{/*
Expand the instance of the app.
*/}}
{{- define "generic.appInstance" -}}
{{- default .Release.Name (.Values.app).instance }}
{{- end }}

{{/*
Expand the full name of the component.
*/}}
{{- define "generic.fullComponentName" }}
{{- include "generic.appName" . }}
{{- if and .generic.componentName (ne .generic.componentName "_") -}}
-{{ .generic.componentName }}
{{- end }}
{{- end }}

{{/*
Expand the full name of the resource.
*/}}
{{- define "generic.fullResourceName" }}
{{- include "generic.fullComponentName" . }}
{{- if and .generic.resourceName (ne .generic.resourceName "_") -}}
-{{ .generic.resourceName }}
{{- end }}
{{- end }}

{{/*
Selector labels
*/}}
{{- define "generic.selectorLabels" -}}
app.kubernetes.io/name: {{ include "generic.appName" . }}
app.kubernetes.io/instance: {{ include "generic.appInstance" . }}
{{- if and .generic.componentName (ne .generic.componentName "_") }}
app.kubernetes.io/component: {{ .generic.componentName }}
{{- end }}
{{- if and .generic.resourceName (ne .generic.resourceName "_") }}
component.resource: {{ .generic.resourceName }}
{{- end }}
{{- end }}

{{/*
Resource labels
*/}}
{{- define "generic.resourceLabels" -}}
app.kubernetes.io/managed-by: {{ .Release.Service }}
helm.sh/chart: {{ include "generic.fullChartName" . }}
{{ include "generic.selectorLabels" . }}
{{- if (.Values.app).partOf }}
app.kubernetes.io/part-of: {{ (.Values.app).partOf }}
{{- end }}
{{- if (.Values.app).version }}
app.kubernetes.io/version: {{ (.Values.app).version }}
{{- end }}
{{- if (.Values.app).environment }}
app.environment: {{ (.Values.app).environment }}
{{- end }}
{{- end }}

{{/*
Merge templates from "useTemplates"
*/}}
{{- define "generic.useTemplates" -}}
{{- if .resource.useTemplates }}
{{- range $templateName := reverse .resource.useTemplates }}
{{- $_ := merge $.resource (deepCopy (get $.root.Values.templates $templateName)) }}
{{- end }}
{{- end }}
{{- end }}
38 changes: 38 additions & 0 deletions chart/templates/components.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
{{- $_ := set $ "generic" (dict) }}

{{- range $componentName, $component := .Values.components }}
{{- if or $component.enabled (not (hasKey $component "enabled")) }}

{{- $_ := set $.generic "componentName" $componentName }}
{{- $_ := set $.generic "component" $component }}

{{- if $component.resources }}
{{- range $resourceName, $resource := $component.resources }}
{{- if or $resource.enabled (not (hasKey $resource "enabled")) }}

{{/*- $resource := deepCopy $resource */}}
{{- if $resource.useTemplates }}
{{- range $templateName := reverse $resource.useTemplates }}
{{- $resource := merge $resource (deepCopy (get $.Values.templates $templateName)) }}
{{- end }}
{{- end }}

{{- $_ := set $.generic "resourceName" $resourceName }}
{{- $_ := set $.generic "resource" $resource }}

{{- include (print "generic.resources." $resource.type) $ }}

{{- $_ := unset $.generic "resourceName" }}
{{- $_ := unset $.generic "resource" }}

{{- end }}
{{- end }}
{{- end }}

{{- $_ := unset $.generic "componentName" }}
{{- $_ := unset $.generic "component" }}

{{- end }}
{{- end }}

{{- $_ := unset $ "generic" }}
35 changes: 35 additions & 0 deletions chart/templates/resources/_deployment.tpl.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
{{/*
Deployment
https://kubernetes.io/docs/reference/kubernetes-api/workload-resources/deployment-v1/
*/}}
{{- define "generic.resources.deployment" -}}

{{- $deployment := .generic.resource }}

{{/*- $podTemplate := deepCopy $deployment.podTemplate */}}
{{- $podTemplate := $deployment.podTemplate }}
{{- include "generic.useTemplates" (dict "resource" $podTemplate "root" $) }}
{{- $_ := set .generic "podTemplate" $podTemplate }}

---
apiVersion: apps/v1
kind: Deployment
metadata:
name: {{ include "generic.fullResourceName" . }}
{{- with $deployment.annotations }}
annotations:
{{- toYaml . | nindent 4 }}
{{- end }}
labels:
{{- include "generic.resourceLabels" . | nindent 4 }}
spec:
replicas: {{ $deployment.replicas | default 1 }}
selector:
matchLabels:
{{- include "generic.selectorLabels" . | nindent 6 }}
{{- include "generic.resources.inc.podTemplate" . | nindent 2 }}
{{- with $deployment.rawSpec }}{{ toYaml . | nindent 2 }}{{ end }}

{{- $_ := unset .generic "podTemplate" }}

{{- end }}
23 changes: 23 additions & 0 deletions chart/templates/resources/_raw.tpl.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
{{/*
Raw Manifest
https://kubernetes.io/docs/reference/kubernetes-api/
*/}}
{{- define "generic.resources.raw" -}}

{{- $manifest := default (dict) .generic.resource.manifest }}
{{- $metadata := default (dict) $manifest.metadata }}
{{- $labels := default (dict) $metadata.labels }}

{{- if not $metadata.name }}
{{- $_ := set $metadata "name" (include "generic.fullResourceName" .) }}
{{- end }}

{{- $labels := merge $labels (fromYaml (include "generic.resourceLabels" .)) }}

{{- $_ := set $metadata "labels" $labels }}
{{- $_ := set $manifest "metadata" $metadata }}

---
{{- toYaml $manifest }}

{{- end }}
20 changes: 20 additions & 0 deletions chart/templates/resources/inc/_pod-template.tpl.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
{{/*
PodTemplate
https://kubernetes.io/docs/reference/kubernetes-api/workload-resources/pod-template-v1/
*/}}
{{- define "generic.resources.inc.podTemplate" -}}

{{- $podTemplate := .generic.podTemplate -}}

template:
metadata:
{{- with $podTemplate.annotations }}
annotations:
{{- toYaml . | nindent 6 }}
{{- end }}
labels:
{{- include "generic.selectorLabels" . | nindent 6 }}
spec:
{{- with $podTemplate.rawSpec }}{{ toYaml . | nindent 4 }}{{ end }}

{{- end }}
Empty file added chart/values.yaml
Empty file.
19 changes: 19 additions & 0 deletions devel/bin/config.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
if [ -f "./devel/local/bin-config/common.sh" ]; then
. ./devel/local/bin-config/common.sh
fi
if [ -f "./devel/local/bin-config/$1.sh" ]; then
. ./devel/local/bin-config/$1.sh
fi

if [ -z "$HELM_CHART" ]; then
HELM_CHART="./chart"
fi
if [ -z "$HELM_NS" ]; then
HELM_NS="default"
fi
if [ -z "$HELM_APP" ]; then
HELM_APP="testapp"
fi
if [ -z "$HELM_VALUES" ]; then
HELM_VALUES="-f ./devel/local/app1/values.yaml"
fi
9 changes: 9 additions & 0 deletions devel/bin/helm-install
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#!/bin/bash

. ./devel/bin/config.sh helm

echo "Installing to app.$HELM_NS..."
helm upgrade --install --atomic --cleanup-on-fail \
--namespace "$HELM_NS" --create-namespace \
$HELM_VALUES \
$HELM_APP $HELM_CHART
5 changes: 5 additions & 0 deletions devel/bin/helm-template
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#!/bin/bash

. ./devel/bin/config.sh helm

helm template $HELM_APP $HELM_CHART $HELM_VALUES

0 comments on commit f826861

Please sign in to comment.