Skip to content

Commit

Permalink
feat: [#20] Add Helm package.
Browse files Browse the repository at this point in the history
  • Loading branch information
030 committed Jan 1, 2023
1 parent c0b13eb commit 3889635
Show file tree
Hide file tree
Showing 17 changed files with 393 additions and 5 deletions.
4 changes: 1 addition & 3 deletions .github/workflows/yamllint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,9 @@ jobs:
runs-on: ubuntu-latest
container:
image: pipelinecomponents/yamllint:0.22.0
env:
YAMLLINT_CONFIG_FILE: /code/configs/.yamllint.yaml
options: --cpus 1
steps:
- name: Checkout code
uses: actions/checkout@v2
- name: run yamllint
run: yamllint .
run: yamllint -c configs/.yamllint.yaml .
1 change: 1 addition & 0 deletions configs/.yamllint.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,5 @@
extends: default

ignore: |
deployments/helm/
test/npm/demo/node_modules/
23 changes: 23 additions & 0 deletions deployments/helm/.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/
24 changes: 24 additions & 0 deletions deployments/helm/Chart.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
apiVersion: v2
name: yaam
description: A Helm chart for Kubernetes

# 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.1.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: "v0.5.3"
22 changes: 22 additions & 0 deletions deployments/helm/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 "yaam.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 "yaam.fullname" . }}'
export SERVICE_IP=$(kubectl get svc --namespace {{ .Release.Namespace }} {{ include "yaam.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 "yaam.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 deployments/helm/templates/_helpers.tpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
{{/*
Expand the name of the chart.
*/}}
{{- define "yaam.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 "yaam.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 "yaam.chart" -}}
{{- printf "%s-%s" .Chart.Name .Chart.Version | replace "+" "_" | trunc 63 | trimSuffix "-" }}
{{- end }}

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

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

{{/*
Create the name of the service account to use
*/}}
{{- define "yaam.serviceAccountName" -}}
{{- if .Values.serviceAccount.create }}
{{- default (include "yaam.fullname" .) .Values.serviceAccount.name }}
{{- else }}
{{- default "default" .Values.serviceAccount.name }}
{{- end }}
{{- end }}
24 changes: 24 additions & 0 deletions deployments/helm/templates/hpa.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
{{- if .Values.autoscaling.enabled }}
---
apiVersion: autoscaling/v2
kind: HorizontalPodAutoscaler
metadata:
name: yaam
spec:
behavior:
scaleDown:
stabilizationWindowSeconds: {{ .Values.autoscaling.stabilizationWindowSeconds }}
metrics:
- resource:
name: cpu
target:
averageUtilization: {{ .Values.autoscaling.averageCpuUtilization }}
type: Utilization
type: Resource
minReplicas: {{ .Values.autoscaling.minReplicas }}
maxReplicas: {{ .Values.autoscaling.maxReplicas }}
scaleTargetRef:
apiVersion: apps/v1
kind: StatefulSet
name: yaam
{{- end }}
24 changes: 24 additions & 0 deletions deployments/helm/templates/ingress.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
{{- if .Values.ingress.enabled -}}
{{- $svcPort := .Values.service.port -}}
---
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
name: yaam
spec:
rules:
{{- range .Values.ingress.hosts }}
- host: {{ .host | quote }}
http:
paths:
{{- range .paths }}
- pathType: {{ .pathType }}
path: {{ .path }}
backend:
service:
name: yaam
port:
number: {{ $svcPort }}
{{- end }}
{{- end }}
{{- end }}
13 changes: 13 additions & 0 deletions deployments/helm/templates/persistentvolume.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
---
apiVersion: v1
kind: PersistentVolume
metadata:
name: repositories
spec:
storageClassName: standard
accessModes:
- ReadWriteOnce
capacity:
storage: 2Gi
hostPath:
path: /opt/yaam/repositories/
13 changes: 13 additions & 0 deletions deployments/helm/templates/persistentvolumeclaim.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
---
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
name: repositories
spec:
volumeName: repositories
storageClassName: standard
accessModes:
- ReadWriteOnce
resources:
requests:
storage: 1Gi
19 changes: 19 additions & 0 deletions deployments/helm/templates/secret.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
{{- if .Values.secret.enabled }}
---
apiVersion: v1
data:
pass: {{ .Values.secret.pass }}
user: {{ .Values.secret.user }}
kind: Secret
metadata:
name: creds
---
apiVersion: v1
kind: Secret
metadata:
name: conf
type: Opaque
stringData:
config.yaml: |
{{ .Values.secret.conf }}
{{- end }}
15 changes: 15 additions & 0 deletions deployments/helm/templates/service.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{{- if .Values.service.enabled }}
---
apiVersion: v1
kind: Service
metadata:
name: yaam
labels:
app: yaam
spec:
ports:
- port: {{ .Values.service.port }}
name: yaam
selector:
app: yaam
{{- end }}
71 changes: 71 additions & 0 deletions deployments/helm/templates/statefulset.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
---
apiVersion: apps/v1
kind: StatefulSet
metadata:
name: yaam
labels:
app: yaam
spec:
serviceName: yaam
selector:
matchLabels:
app: yaam
replicas: 2
template:
metadata:
labels:
app: yaam
spec:
containers:
- name: yaam
env:
- name: YAAM_LOG_LEVEL
value: info
- name: YAAM_HOST
value: yaam.some-domain
- name: YAAM_USER
valueFrom:
secretKeyRef:
name: creds
key: user
- name: YAAM_PASS
valueFrom:
secretKeyRef:
name: creds
key: pass
image: utrecht/yaam:v0.5.3
livenessProbe:
httpGet:
path: /status
port: 25213
readinessProbe:
httpGet:
path: /status
port: 25213
resources:
limits:
cpu: 480m
memory: 30Mi
requests:
cpu: 96m
memory: 5Mi
ports:
- containerPort: 25213
name: yaam
volumeMounts:
- name: conf
mountPath: /opt/yaam/.yaam
- name: repositories
mountPath: /opt/yaam/.yaam/repositories
- mountPath: /opt/yaam/.yaam/logs
name: logs
volumes:
- name: conf
secret:
secretName: conf
- name: repositories
persistentVolumeClaim:
claimName: repositories
- name: logs
emptyDir:
sizeLimit: 50Mi
Loading

0 comments on commit 3889635

Please sign in to comment.