Skip to content

Commit

Permalink
add helm chart (#99)
Browse files Browse the repository at this point in the history
Signed-off-by: cpanato <ctadeu@gmail.com>
  • Loading branch information
cpanato committed May 21, 2023
1 parent 44f7369 commit a2e57a3
Show file tree
Hide file tree
Showing 14 changed files with 515 additions and 0 deletions.
58 changes: 58 additions & 0 deletions .github/workflows/helm-release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
name: Release Charts

on:
push:
branches:
- main
paths:
- "charts/**"

jobs:
release:
permissions:
contents: write

runs-on: ubuntu-latest

steps:
- name: Checkout
uses: actions/checkout@8e5e7e5ab8b370d6c329ec480221332ada57f0ab # v3.5.2
with:
fetch-depth: 0

- name: Configure Git
run: |
git config user.name "$GITHUB_ACTOR"
git config user.email "$GITHUB_ACTOR@users.noreply.github.com"
- name: Set up Helm
uses: azure/setup-helm@5119fcb9089d432beecbf79bb2c7915207344b78 # v3.5
with:
version: v3.12.0

- name: Run chart-releaser
uses: helm/chart-releaser-action@be16258da8010256c6e82849661221415f031968 # v1.5.0
env:
CR_TOKEN: "${{ secrets.GITHUB_TOKEN }}"

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

- name: Install Cosign
uses: sigstore/cosign-installer@204a51a57a74d190b284a0ce69b44bc37201f343 # v3.0.3

- name: Publish and Sign OCI Charts
run: |
for chart in `find .cr-release-packages -name '*.tgz' -print`; do
helm push ${chart} oci://ghcr.io/${GITHUB_REPOSITORY} |& tee helm-push-output.log
file_name=${chart##*/}
chart_name=${file_name%-*}
digest=$(awk -F "[, ]+" '/Digest/{print $NF}' < helm-push-output.log)
cosign sign "ghcr.io/${GITHUB_REPOSITORY}/${chart_name}@${digest}"
done
env:
COSIGN_YES: true
47 changes: 47 additions & 0 deletions .github/workflows/helm-test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
name: helm

on:
pull_request:
paths:
- "charts/**"

jobs:
test-chart:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@8e5e7e5ab8b370d6c329ec480221332ada57f0ab # v3.5.2
with:
fetch-depth: 0

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

- uses: actions/setup-python@57ded4d7d5e986d7296eab16560982c6dd7c923b # v4.6.0
with:
python-version: 3.8

- name: Set up chart-testing
uses: helm/chart-testing-action@e8788873172cb653a90ca2e819d79d65a66d4e76 # v2.4.0

- name: Run chart-testing (list-changed)
id: list-changed
run: |
changed=$(ct list-changed --target-branch ${{ github.event.repository.default_branch }})
if [[ -n "$changed" ]]; then
echo "changed=true" >> "$GITHUB_OUTPUT"
fi
- name: Run chart-testing (lint)
if: steps.list-changed.outputs.changed == 'true'
run: ct lint --target-branch ${{ github.event.repository.default_branch }} --config ct.yaml

- name: Create kind cluster
if: steps.list-changed.outputs.changed == 'true'
uses: helm/kind-action@fa81e57adff234b2908110485695db0f181f3c67 # v1.7.0

- name: Run chart-testing (install)
if: steps.list-changed.outputs.changed == 'true'
run: ct install --target-branch ${{ github.event.repository.default_branch }} --config ct.yaml
22 changes: 22 additions & 0 deletions charts/github-exporter/.helmignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# 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
*~
# Various IDEs
.project
.idea/
*.tmproj
.vscode/
8 changes: 8 additions & 0 deletions charts/github-exporter/Chart.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
apiVersion: v1
description: GitHub exporter
name: github-exporter
version: 0.1.0
appVersion: 0.4.0
home: https://github.com/cpanato/github_actions_exporter
maintainers:
- name: cpanato
6 changes: 6 additions & 0 deletions charts/github-exporter/ci/ci-values.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
config:
org: "fake-honk"

secret:
githubToken: "fake-token"
githubWebhookToken: "fake-token"
5 changes: 5 additions & 0 deletions charts/github-exporter/templates/NOTES.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
1.To see the metrics
{{- if contains "ClusterIP" .Values.service.type }}
kubectl port-forward svc/{{ include "github-exporter.fullname" . }} {{ .Values.service.portMetrics }}
echo "Visit http://127.0.0.1:{{ .Values.service.portMetrics }}/metrics to check the metrics"
{{- end }}
32 changes: 32 additions & 0 deletions charts/github-exporter/templates/_helpers.tpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
{{/* vim: set filetype=mustache: */}}
{{/*
Expand the name of the chart.
*/}}
{{- define "github-exporter.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 "github-exporter.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 "github-exporter.chart" -}}
{{- printf "%s-%s" .Chart.Name .Chart.Version | replace "+" "_" | trunc 63 | trimSuffix "-" -}}
{{- end -}}
86 changes: 86 additions & 0 deletions charts/github-exporter/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 "github-exporter.fullname" . }}
namespace: {{ .Release.Namespace }}
labels:
app.kubernetes.io/name: {{ include "github-exporter.name" . }}
helm.sh/chart: {{ include "github-exporter.chart" . }}
app.kubernetes.io/instance: {{ .Release.Name }}
app.kubernetes.io/managed-by: {{ .Release.Service }}
{{- if .Values.labels -}}
{{ .Values.labels | toYaml | nindent 4 -}}
{{- end }}
spec:
replicas: {{ .Values.deployment.replicaCount }}
selector:
matchLabels:
app.kubernetes.io/name: {{ include "github-exporter.name" . }}
app.kubernetes.io/instance: {{ .Release.Name }}
template:
metadata:
labels:
app.kubernetes.io/name: {{ include "github-exporter.name" . }}
app.kubernetes.io/instance: {{ .Release.Name }}
helm.sh/chart: {{ include "github-exporter.chart" . }}
{{- if .Values.podLabels -}}
{{ .Values.podLabels | toYaml | nindent 8 -}}
{{- end }}
spec:
containers:
- name: github-exporter
image: "{{ .Values.deployment.image.repository }}:{{ .Values.deployment.image.tag }}@{{ .Values.deployment.image.digest }}"
imagePullPolicy: {{ .Values.deployment.image.pullPolicy }}
args:
- --gh.github-api-token=$(GITHUB_TOKEN)
- --gh.github-webhook-token=$(GITHUB_WEBHOOK_TOKEN)
- --gh.github-org={{ .Values.config.org }}
- --gh.billing-poll-seconds={{ .Values.config.pollSeconds }}
envFrom:
- secretRef:
{{- if not .Values.secret.existingSecretName }}
name: {{ include "github-exporter.fullname" . }}
{{- else }}
name: {{ .Values.secret.existingSecretName }}
{{- end }}
ports:
- name: metrics
containerPort: {{ .Values.service.portMetrics }}
protocol: TCP
- name: http
containerPort: {{ .Values.service.portHttp }}
protocol: TCP
livenessProbe:
failureThreshold: 1
httpGet:
path: /healthz
port: http
scheme: HTTP
initialDelaySeconds: 3
periodSeconds: 30
successThreshold: 1
timeoutSeconds: 9
readinessProbe:
failureThreshold: 1
httpGet:
path: /healthz
port: http
scheme: HTTP
initialDelaySeconds: 3
periodSeconds: 15
successThreshold: 1
timeoutSeconds: 9
resources:
{{- toYaml .Values.deployment.resources | nindent 12 }}
{{- with .Values.deployment.nodeSelector }}
nodeSelector:
{{- toYaml . | nindent 8 }}
{{- end }}
{{- with .Values.affinity }}
affinity:
{{- toYaml . | nindent 8 }}
{{- end }}
{{- with .Values.tolerations }}
tolerations:
{{- toYaml . | nindent 8 }}
{{- end }}
31 changes: 31 additions & 0 deletions charts/github-exporter/templates/ingress.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
{{- if .Values.ingress.enabled }}
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
labels:
app.kubernetes.io/name: {{ include "github-exporter.name" . }}
helm.sh/chart: {{ include "github-exporter.chart" . }}
app.kubernetes.io/instance: {{ .Release.Name }}
app.kubernetes.io/managed-by: {{ .Release.Service }}
{{- if .Values.ingress.extraLabels }}
{{ .Values.ingress.extraLabels | toYaml | nindent 4 -}}
{{- end }}
{{- if .Values.ingress.annotations }}
annotations:
{{ .Values.ingress.annotations | toYaml | nindent 4 -}}
{{- end }}
name: {{ include "github-exporter.fullname" . }}
namespace: {{ .Release.Namespace }}
spec:
rules:
- host: {{ .Values.ingress.host }}
http:
paths:
- path: "/"
pathType: Prefix
backend:
service:
name: {{ include "github-exporter.name" . }}-ingress
port:
number: {{ .Values.service.portHttp }}
{{- end }}
19 changes: 19 additions & 0 deletions charts/github-exporter/templates/secret.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
{{- if not .Values.secret.existingSecretName }}
apiVersion: v1
kind: Secret
metadata:
labels:
app.kubernetes.io/name: {{ include "github-exporter.name" . }}
helm.sh/chart: {{ include "github-exporter.chart" . }}
app.kubernetes.io/instance: {{ .Release.Name }}
app.kubernetes.io/managed-by: {{ .Release.Service }}
{{- if .Values.labels }}
{{ .Values.labels | toYaml | nindent 4 -}}
{{- end }}
name: {{ include "github-exporter.fullname" . }}
namespace: {{ .Release.Namespace }}
data:
GITHUB_TOKEN: {{ .Values.secret.githubToken | b64enc }}
GITHUB_WEBHOOK_TOKEN: {{ .Values.secret.githubWebhookToken | b64enc }}
type: Opaque
{{- end }}
57 changes: 57 additions & 0 deletions charts/github-exporter/templates/service.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
apiVersion: v1
kind: Service
metadata:
labels:
app.kubernetes.io/name: {{ include "github-exporter.name" . }}
helm.sh/chart: {{ include "github-exporter.chart" . }}
app.kubernetes.io/instance: {{ .Release.Name }}
app.kubernetes.io/managed-by: {{ .Release.Service }}
{{- if .Values.service.extraLabels -}}
{{ .Values.service.extraLabels | toYaml | nindent 4 -}}
{{- end }}
{{- if .Values.service.annotationsMetrics }}
annotations:
{{ .Values.service.annotationsMetrics | toYaml | nindent 4 -}}
{{- end }}
name: {{ include "github-exporter.name" . }}-metrics
namespace: {{ .Release.Namespace }}
spec:
type: {{ .Values.service.type }}
ports:
- port: {{ .Values.service.portMetrics }}
targetPort: metrics
protocol: TCP
name: metrics
selector:
app.kubernetes.io/name: {{ include "github-exporter.name" . }}
app.kubernetes.io/instance: {{ .Release.Name }}
---
{{- if .Values.ingress.enabled }}
apiVersion: v1
kind: Service
metadata:
labels:
app.kubernetes.io/name: {{ include "github-exporter.name" . }}
helm.sh/chart: {{ include "github-exporter.chart" . }}
app.kubernetes.io/instance: {{ .Release.Name }}
app.kubernetes.io/managed-by: {{ .Release.Service }}
{{- if .Values.service.extraLabels -}}
{{ .Values.service.extraLabels | toYaml | nindent 4 -}}
{{- end }}
{{- if .Values.service.annotationsIngress }}
annotations:
{{ .Values.service.annotationsIngress | toYaml | nindent 4 -}}
{{- end }}
name: {{ include "github-exporter.name" . }}-ingress
namespace: {{ .Release.Namespace }}
spec:
type: {{ .Values.service.type }}
ports:
- port: {{ .Values.service.portHttp }}
targetPort: http
protocol: TCP
name: http
selector:
app.kubernetes.io/name: {{ include "github-exporter.name" . }}
app.kubernetes.io/instance: {{ .Release.Name }}
{{- end }}

0 comments on commit a2e57a3

Please sign in to comment.