Skip to content

Commit

Permalink
feat: added helm chart
Browse files Browse the repository at this point in the history
Signed-off-by: Armin Schlegel <armin.schlegel@gmx.de>
  • Loading branch information
siredmar committed Jul 31, 2023
1 parent f131bb7 commit d14842c
Show file tree
Hide file tree
Showing 9 changed files with 1,971 additions and 11 deletions.
5 changes: 5 additions & 0 deletions .github/workflows/commitlint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,11 @@ on:
pull_request:
branches:
- "**"
push:
branches:
- main
- beta

jobs:
commitlint:
runs-on: ubuntu-latest
Expand Down
39 changes: 36 additions & 3 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -1,9 +1,17 @@
name: Release

on:
push:
workflow_run:
workflows: ["Lint Commit Messages"]
branches:
- main
- beta
types:
- completed

env:
REGISTRY: ghcr.io
IMAGE_NAME: ${{ github.repository }}

jobs:
release:
Expand All @@ -14,7 +22,32 @@ jobs:
uses: actions/checkout@v2
with:
fetch-depth: 0

- name: Setup Node.js
uses: actions/setup-node@v3
with:
node-version: "lts/*"

- name: Log in to the Container registry
uses: docker/login-action@v2
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.PACKAGES_TOKEN }}

- name: Setup helm
uses: azure/setup-helm@v3
with:
version: "v3.11.1"

- name: Release
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: npx semantic-release
GITHUB_TOKEN: ${{ secrets.PACKAGES_TOKEN }}
REGISTRY_USERNAME: ${{ github.actor }}
REGISTRY_PASSWORD: ${{ secrets.GITHUB_TOKEN }}
run: |-
#!/bin/bash
set -e
# add more plugins: https://semantic-release.gitbook.io/semantic-release/extending/plugins-list
npm install @semantic-release/github @semantic-release/exec @semantic-release/git semantic-release-helm3 -D
npx -c semantic-release
39 changes: 39 additions & 0 deletions .releaserc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
{
"branches": [
{
"name": "main"
},
{
"name": "beta",
"prerelease": true
}
],
"plugins": [
"@semantic-release/commit-analyzer",
"@semantic-release/release-notes-generator",
[
"@semantic-release/exec",
{
"prepareCmd": "cd charts/grafana-dashboards/scripts/ && ./edge_nodes.sh"
}
],
[
"semantic-release-helm3",
{
"chartPath": "./charts/grafana-dashboards",
"registry": "ghcr.io/edgefarm/grafana-dashboards"
}
],
[
"@semantic-release/git",
{
"assets": [
"charts/grafana-dashboards/Chart.yaml",
"charts/grafana-dashboards/templates/dashboard-edge-nodes.yaml"
],
"message": "chore(release): ${nextRelease.version} [skip ci]\n\n${nextRelease.notes}"
}
],
"@semantic-release/github"
]
}
8 changes: 0 additions & 8 deletions .releaserc.yaml

This file was deleted.

15 changes: 15 additions & 0 deletions charts/grafana-dashboards/Chart.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
apiVersion: v2
name: grafana-dashboards
description: This chart contains a bunch of grafana dashboards that are loaded into grafana by the grafana-operator.
type: application
version: 0.1.0
appVersion: 0.1.0
keywords:
- edgefarm.monitor
- grafana
- dashboards
sources:
- https://github.com/edgefarm/grafana-dashboards
maintainers:
- name: Armin Schlegel
email: armin.schlegel@gmx.de
53 changes: 53 additions & 0 deletions charts/grafana-dashboards/scripts/edge_nodes.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
#!/bin/bash
# This script is supposed to be called from the location of the script (charts/grafana-dashboards/scripts)

set -e

function createDashboardTemplate() {
# Parameters
local configmap_name=$1
local file_path=$2
local output_file=$3

# Extract the filename from the file path to use as the key in the ConfigMap
local file_name=$(basename "$file_path")

# Create a temporary yaml file
local temp_file=$(mktemp)

echo "{{- if.Values.dashboards.edgeNodes.enabled }}" >"$temp_file"

# Write the ConfigMap to the temporary file
cat <<EOF >>$temp_file
---
# This file is generated by charts/grafana-dashboards/scripts/edge_nodes.sh
# Do not edit this file manually
apiVersion: v1
kind: ConfigMap
metadata:
name: $configmap_name
namespace: "{{ .Release.Namespace }}"
labels:
grafana_dashboard: ""
{{- include "grafana-dashboards.labels" . | nindent 4 }}
data:
$file_name: |-
EOF

# Append the contents of the file to the ConfigMap
sed 's/^/ /' "$file_path" >>"$temp_file"

echo -e "\n{{- end }}" >>"$temp_file"

## Search and Replace the legendFormat if it contains variables like {{ variable}} to
## make them work with helm (put raw string around them {{ ` raw string ` }})
## example: "legendFormat": "{{chip}}-{{sensor}}" to "legendFormat": {{`"{{chip}}-{{sensor}}",`}}
sed -ri 's#\"legendFormat\": \"(.*)\",#\"legendFormat\": \{\{`\"\1\",`\}\}#g' "$temp_file"

cat "$temp_file" >"$output_file"

# Remove the temporary file
rm "$temp_file"
}

createDashboardTemplate "dashboard-edge-nodes" "../../../dashboards/edge_nodes.json" "../templates/dashboard-edge-nodes.yaml"
62 changes: 62 additions & 0 deletions charts/grafana-dashboards/templates/_helpers.tpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
{{/*
Expand the name of the chart.
*/}}
{{- define "grafana-dashboards.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 "grafana-dashboards.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 "grafana-dashboards.chart" -}}
{{- printf "%s-%s" .Chart.Name .Chart.Version | replace "+" "_" | trunc 63 | trimSuffix "-" }}
{{- end }}

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

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

{{/*
Create the name of the service account to use
*/}}
{{- define "grafana-dashboards.serviceAccountName" -}}
{{- if .Values.serviceAccount.create }}
{{- default (include "grafana-dashboards.fullname" .) .Values.serviceAccount.name }}
{{- else }}
{{- default "default" .Values.serviceAccount.name }}
{{- end }}
{{- end }}
Loading

0 comments on commit d14842c

Please sign in to comment.