Skip to content

Commit 724002e

Browse files
committed
add helm cart + first try package
1 parent db5be84 commit 724002e

File tree

13 files changed

+461
-0
lines changed

13 files changed

+461
-0
lines changed
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
name: Build helm chart
2+
3+
on:
4+
workflow_dispatch:
5+
push:
6+
branches:
7+
- main
8+
paths:
9+
- "docker-image/**"
10+
- "helm/**"
11+
12+
jobs:
13+
generate_tag:
14+
runs-on: ubuntu-latest
15+
outputs:
16+
output: ${{ steps.tag.outputs.tag }}
17+
steps:
18+
- name: Check out the repo
19+
uses: actions/checkout@v2
20+
with:
21+
ref: main
22+
fetch-depth: 0
23+
- id: tag
24+
shell: bash
25+
run: |
26+
echo "Tag: $(git describe --abbrev=0)"
27+
echo "::set-output name=tag::$(git describe --abbrev=0)"
28+
29+
build-helm-chart:
30+
runs-on: ubuntu-latest
31+
needs: generate_tag
32+
steps:
33+
- name: Check out the repo
34+
uses: actions/checkout@v2
35+
36+
- name: Configure Git
37+
run: |
38+
git config user.name "$GITHUB_ACTOR"
39+
git config user.email "[email protected]"
40+
41+
- name: Update chart application version
42+
run: |
43+
sed -i -e "s/appVersion:.*/appVersion: ${{ needs.generate_tag.outputs.output }}/g" helm/Chart.yaml
44+
45+
- name: Run chart-releaser
46+
uses: helm/[email protected]
47+
with:
48+
charts_dir: helm
49+
config: cr.yaml
50+
charts_repo_url: http://fullstack-devops.github.io/helm-charts/
51+
env:
52+
CR_TOKEN: "${{ secrets.GITHUB_TOKEN }}"
53+
HELM_REPO_TOKEN: "${{ secrets.HELM_REPO_TOKEN }}"
54+
55+
- name: Build and push image
56+
uses: docker/build-push-action@v2
57+
with:
58+
builder: ${{ steps.buildx.outputs.name }}
59+
context: ./docker-image/
60+
platforms: ${{ env.IMAGE_PLATFORMS }}
61+
push: true
62+
tags: |
63+
ghcr.io/${{ github.repository }}:latest
64+
ghcr.io/${{ github.repository }}:${{ needs.generate_tag.outputs.output }}

cr.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
owner: fullstack-devops
2+
git-repo: helm-charts
3+
token: ${HELM_REPO_TOKEN}

helm/.helmignore

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
# Patterns to ignore when building packages.
2+
# This supports shell glob matching, relative path matching, and
3+
# negation (prefixed with !). Only one pattern per line.
4+
.DS_Store
5+
# Common VCS dirs
6+
.git/
7+
.gitignore
8+
.bzr/
9+
.bzrignore
10+
.hg/
11+
.hgignore
12+
.svn/
13+
# Common backup files
14+
*.swp
15+
*.bak
16+
*.tmp
17+
*.orig
18+
*~
19+
# Various IDEs
20+
.project
21+
.idea/
22+
*.tmproj
23+
.vscode/

helm/Chart.yaml

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
apiVersion: v2
2+
name: dns-bind
3+
description: A bind9 Helm chart for Kubernetes
4+
5+
# A chart can be either an 'application' or a 'library' chart.
6+
#
7+
# Application charts are a collection of templates that can be packaged into versioned archives
8+
# to be deployed.
9+
#
10+
# Library charts provide useful utilities or functions for the chart developer. They're included as
11+
# a dependency of application charts to inject those utilities and functions into the rendering
12+
# pipeline. Library charts do not define any templates and therefore cannot be deployed.
13+
type: application
14+
15+
# This is the chart version. This version number should be incremented each time you make changes
16+
# to the chart and its templates, including the app version.
17+
# Versions are expected to follow Semantic Versioning (https://semver.org/)
18+
version: 0.1.0
19+
20+
# This is the version number of the application being deployed. This version number should be
21+
# incremented each time you make changes to the application. Versions are not expected to
22+
# follow Semantic Versioning. They should reflect the version the application is using.
23+
# It is recommended to use it with quotes.
24+
appVersion: "0.0.5"

helm/templates/NOTES.txt

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
1. Get the application URL by running these commands:
2+
{{- if contains "NodePort" .Values.serviceDns.type }}
3+
export NODE_PORT=$(kubectl get --namespace {{ .Release.Namespace }} -o jsonpath="{.spec.ports[0].nodePort}" services {{ include "dns-bind.fullname" . }})
4+
export NODE_IP=$(kubectl get nodes --namespace {{ .Release.Namespace }} -o jsonpath="{.items[0].status.addresses[0].address}")
5+
echo http://$NODE_IP:$NODE_PORT
6+
{{- else if contains "LoadBalancer" .Values.serviceDns.type }}
7+
NOTE: It may take a few minutes for the LoadBalancer IP to be available.
8+
You can watch the status of by running 'kubectl get --namespace {{ .Release.Namespace }} svc -w {{ include "dns-bind.fullname" . }}'
9+
export SERVICE_IP=$(kubectl get svc --namespace {{ .Release.Namespace }} {{ include "dns-bind.fullname" . }} --template "{{"{{ range (index .status.loadBalancer.ingress 0) }}{{.}}{{ end }}"}}")
10+
echo http://$SERVICE_IP:53
11+
{{- else if contains "ClusterIP" .Values.serviceDns.type }}
12+
export POD_NAME=$(kubectl get pods --namespace {{ .Release.Namespace }} -l "app.kubernetes.io/name={{ include "dns-bind.name" . }},app.kubernetes.io/instance={{ .Release.Name }}" -o jsonpath="{.items[0].metadata.name}")
13+
export CONTAINER_PORT=$(kubectl get pod --namespace {{ .Release.Namespace }} $POD_NAME -o jsonpath="{.spec.containers[0].ports[0].containerPort}")
14+
echo "Visit http://127.0.0.1:8080 to use your application"
15+
kubectl --namespace {{ .Release.Namespace }} port-forward $POD_NAME 8080:$CONTAINER_PORT
16+
{{- end }}

helm/templates/_helpers.tpl

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
{{/*
2+
Expand the name of the chart.
3+
*/}}
4+
{{- define "dns-bind.name" -}}
5+
{{- default .Chart.Name .Values.nameOverride | trunc 63 | trimSuffix "-" }}
6+
{{- end }}
7+
8+
{{/*
9+
Create a default fully qualified app name.
10+
We truncate at 63 chars because some Kubernetes name fields are limited to this (by the DNS naming spec).
11+
If release name contains chart name it will be used as a full name.
12+
*/}}
13+
{{- define "dns-bind.fullname" -}}
14+
{{- if .Values.fullnameOverride }}
15+
{{- .Values.fullnameOverride | trunc 63 | trimSuffix "-" }}
16+
{{- else }}
17+
{{- $name := default .Chart.Name .Values.nameOverride }}
18+
{{- if contains $name .Release.Name }}
19+
{{- .Release.Name | trunc 63 | trimSuffix "-" }}
20+
{{- else }}
21+
{{- printf "%s-%s" .Release.Name $name | trunc 63 | trimSuffix "-" }}
22+
{{- end }}
23+
{{- end }}
24+
{{- end }}
25+
26+
{{/*
27+
Create chart name and version as used by the chart label.
28+
*/}}
29+
{{- define "dns-bind.chart" -}}
30+
{{- printf "%s-%s" .Chart.Name .Chart.Version | replace "+" "_" | trunc 63 | trimSuffix "-" }}
31+
{{- end }}
32+
33+
{{/*
34+
Common labels
35+
*/}}
36+
{{- define "dns-bind.labels" -}}
37+
helm.sh/chart: {{ include "dns-bind.chart" . }}
38+
{{ include "dns-bind.selectorLabels" . }}
39+
{{- if .Chart.AppVersion }}
40+
app.kubernetes.io/version: {{ .Chart.AppVersion | quote }}
41+
{{- end }}
42+
app.kubernetes.io/managed-by: {{ .Release.Service }}
43+
{{- end }}
44+
45+
{{/*
46+
Selector labels
47+
*/}}
48+
{{- define "dns-bind.selectorLabels" -}}
49+
app.kubernetes.io/name: {{ include "dns-bind.name" . }}
50+
app.kubernetes.io/instance: {{ .Release.Name }}
51+
{{- end }}
52+
53+
{{/*
54+
Create the name of the service account to use
55+
*/}}
56+
{{- define "dns-bind.serviceAccountName" -}}
57+
{{- if .Values.serviceAccount.create }}
58+
{{- default (include "dns-bind.fullname" .) .Values.serviceAccount.name }}
59+
{{- else }}
60+
{{- default "default" .Values.serviceAccount.name }}
61+
{{- end }}
62+
{{- end }}

helm/templates/configmap.yaml

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
apiVersion: v1
2+
kind: ConfigMap
3+
metadata:
4+
name: {{ include "dns-bind.fullname" . }}
5+
labels:
6+
{{- include "dns-bind.labels" . | nindent 4 }}
7+
data:
8+
DEBUG_ENTRYPOINT: {{ .Values.envValues.debug_entrypoint | quote }}
9+
DOCKER_LOGS: {{ .Values.envValues.docker_logs | quote }}
10+
{{- if .Values.envValues.wildcard_dns }}
11+
WILDCARD_DNS: {{ .Values.envValues.wildcard_dns | quote }}
12+
{{- end }}
13+
{{- if .Values.envValues.extra_hosts }}
14+
EXTRA_HOSTS: {{ .Values.envValues.extra_hosts | quote }}
15+
{{- end }}
16+
DNSSEC_VALIDATE: {{ .Values.envValues.dnssec_validate | quote }}
17+
{{- if .Values.envValues.dns_forwarder }}
18+
DNS_FORWARDER: {{ .Values.envValues.dns_forwarder | quote }}
19+
{{- end }}
20+
TTL_TIME: {{ .Values.envValues.ttl_time | quote }}
21+
REFRESH_TIME: {{ .Values.envValues.refresh_time | quote }}
22+
RETRY_TIME: {{ .Values.envValues.retry_time | quote }}
23+
EXPIRY_TIME: {{ .Values.envValues.expiry_time | quote }}
24+
MAX_CACHE_TIME: {{ .Values.envValues.max_cache_time | quote }}
25+
{{- if .Values.envValues.allow_query }}
26+
ALLOW_QUERY: {{ .Values.envValues.allow_query | quote }}
27+
{{- end }}
28+
{{- if .Values.envValues.allow_recursion }}
29+
ALLOW_RECURSION: {{ .Values.envValues.allow_recursion | quote }}
30+
{{- end }}

helm/templates/deployment.yaml

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
apiVersion: apps/v1
2+
kind: Deployment
3+
metadata:
4+
name: {{ include "dns-bind.fullname" . }}
5+
labels:
6+
{{- include "dns-bind.labels" . | nindent 4 }}
7+
spec:
8+
{{- if not .Values.autoscaling.enabled }}
9+
replicas: {{ .Values.replicaCount }}
10+
{{- end }}
11+
selector:
12+
matchLabels:
13+
{{- include "dns-bind.selectorLabels" . | nindent 6 }}
14+
template:
15+
metadata:
16+
{{- with .Values.podAnnotations }}
17+
annotations:
18+
{{- toYaml . | nindent 8 }}
19+
{{- end }}
20+
labels:
21+
{{- include "dns-bind.selectorLabels" . | nindent 8 }}
22+
spec:
23+
{{- with .Values.imagePullSecrets }}
24+
imagePullSecrets:
25+
{{- toYaml . | nindent 8 }}
26+
{{- end }}
27+
serviceAccountName: {{ include "dns-bind.serviceAccountName" . }}
28+
securityContext:
29+
{{- toYaml .Values.podSecurityContext | nindent 8 }}
30+
containers:
31+
- name: {{ .Chart.Name }}
32+
securityContext:
33+
{{- toYaml .Values.securityContext | nindent 12 }}
34+
image: "{{ .Values.image.repository }}:{{ .Values.image.tag | default .Chart.AppVersion }}"
35+
imagePullPolicy: {{ .Values.image.pullPolicy }}
36+
ports:
37+
- containerPort: 53
38+
name: dns
39+
protocol: TCP
40+
- containerPort: 53
41+
name: dns-udp
42+
protocol: UDP
43+
# TODO: health checks!
44+
# livenessProbe:
45+
# httpGet:
46+
# path: /
47+
# port: http
48+
# readinessProbe:
49+
# httpGet:
50+
# path: /
51+
# port: http
52+
envFrom:
53+
- configMapRef:
54+
name: {{ .Release.Name }}-dns-bind
55+
resources:
56+
{{- toYaml .Values.resources | nindent 12 }}
57+
{{- with .Values.nodeSelector }}
58+
nodeSelector:
59+
{{- toYaml . | nindent 8 }}
60+
{{- end }}
61+
{{- with .Values.affinity }}
62+
affinity:
63+
{{- toYaml . | nindent 8 }}
64+
{{- end }}
65+
{{- with .Values.tolerations }}
66+
tolerations:
67+
{{- toYaml . | nindent 8 }}
68+
{{- end }}

helm/templates/hpa.yaml

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
{{- if .Values.autoscaling.enabled }}
2+
apiVersion: autoscaling/v2beta1
3+
kind: HorizontalPodAutoscaler
4+
metadata:
5+
name: {{ include "dns-bind.fullname" . }}
6+
labels:
7+
{{- include "dns-bind.labels" . | nindent 4 }}
8+
spec:
9+
scaleTargetRef:
10+
apiVersion: apps/v1
11+
kind: Deployment
12+
name: {{ include "dns-bind.fullname" . }}
13+
minReplicas: {{ .Values.autoscaling.minReplicas }}
14+
maxReplicas: {{ .Values.autoscaling.maxReplicas }}
15+
metrics:
16+
{{- if .Values.autoscaling.targetCPUUtilizationPercentage }}
17+
- type: Resource
18+
resource:
19+
name: cpu
20+
targetAverageUtilization: {{ .Values.autoscaling.targetCPUUtilizationPercentage }}
21+
{{- end }}
22+
{{- if .Values.autoscaling.targetMemoryUtilizationPercentage }}
23+
- type: Resource
24+
resource:
25+
name: memory
26+
targetAverageUtilization: {{ .Values.autoscaling.targetMemoryUtilizationPercentage }}
27+
{{- end }}
28+
{{- end }}

helm/templates/service.yaml

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
apiVersion: v1
2+
kind: Service
3+
metadata:
4+
name: {{ include "dns-bind.fullname" . }}
5+
labels:
6+
{{- include "dns-bind.labels" . | nindent 4 }}
7+
spec:
8+
type: {{ .Values.serviceDns.type }}
9+
{{- if .Values.serviceDns.loadBalancerIP }}
10+
loadBalancerIP: {{ .Values.serviceDns.loadBalancerIP }}
11+
{{- end }}
12+
{{- if or (eq .Values.serviceDns.type "NodePort") (eq .Values.serviceDns.type "LoadBalancer") }}
13+
externalTrafficPolicy: {{ .Values.serviceDns.externalTrafficPolicy }}
14+
{{- end }}
15+
ports:
16+
- port: 53
17+
targetPort: dns
18+
{{- if .Values.serviceDns.nodePort }}
19+
nodePort: {{ .Values.serviceDns.nodePort }}
20+
{{- end }}
21+
protocol: TCP
22+
name: dns
23+
- port: 53
24+
targetPort: dns-udp
25+
{{- if and (.Values.serviceDns.nodePort) (eq .Values.serviceDns.type "NodePort") }}
26+
nodePort: {{ .Values.serviceDns.nodePort }}
27+
{{- end }}
28+
protocol: UDP
29+
name: dns-udp
30+
selector:
31+
{{- include "dns-bind.selectorLabels" . | nindent 4 }}

0 commit comments

Comments
 (0)