Skip to content

Commit

Permalink
Merge pull request #41 from jujaga/feature/helm
Browse files Browse the repository at this point in the history
Add Helm Chart support for COMS
  • Loading branch information
kamorel authored Jun 20, 2022
2 parents 6cfe50a + 0b85645 commit b684159
Show file tree
Hide file tree
Showing 17 changed files with 668 additions and 2 deletions.
32 changes: 32 additions & 0 deletions .github/workflows/charts-release.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
name: Release Charts

on:
push:
paths:
- 'charts/**'
branches:
- master

jobs:
release:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v3
with:
fetch-depth: 0

- name: Configure Git
run: |
git config user.name "$GITHUB_ACTOR"
git config user.email "[email protected]"
- name: Install Helm
uses: azure/setup-helm@v1
with:
version: v3.8.2

- name: Run chart-releaser
uses: helm/[email protected]
env:
CR_TOKEN: "${{ secrets.GITHUB_TOKEN }}"
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@ node_modules
# Ignore only top-level package-lock.json
/package-lock.json

# Ignore Helm subcharts
charts/**/charts
Chart.lock

# local env files
local.*
local-*.*
Expand Down
23 changes: 23 additions & 0 deletions charts/coms/.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/
48 changes: 48 additions & 0 deletions charts/coms/Chart.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
apiVersion: v2
name: common-object-management-service
# 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.1
kubeVersion: ">= 1.13.0"
description: A microservice for managing access control to S3 Objects
# 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
keywords:
- nodejs
- javascript
- docker
- microservice
- s3
- document-management
- access-control
- object-storage
- domo
home: https://bcgov.github.io/common-object-management-service
sources:
- https://github.com/bcgov/common-object-management-service
dependencies:
- name: patroni
version: ~0.0.2
repository: https://bcgov.github.io/nr-patroni-chart
condition: patroni.enabled
tags:
- patroni
# by default, the object created will be named <your-app>-patroni. You can use an alias to override the -patroni suffix
# alias: postgres
maintainers:
- name: NR Common Service Showcase Team
email: [email protected]
url: https://bcgov.github.io/common-service-showcase/team.html
# 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.1.0"
deprecated: false
annotations: {}
18 changes: 18 additions & 0 deletions charts/coms/templates/NOTES.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
1. Get the application URL by running these commands:
{{- if .Values.route.enabled }}
http{{ if $.Values.route.tls }}s{{ end }}://{{ .Values.route.host }}{{ .Values.route.path }}
{{- else if contains "NodePort" .Values.service.type }}
export NODE_PORT=$(kubectl get --namespace {{ .Release.Namespace }} -o jsonpath="{.spec.ports[0].nodePort}" services {{ include "coms.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 "coms.fullname" . }}'
export SERVICE_IP=$(kubectl get svc --namespace {{ .Release.Namespace }} {{ include "coms.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 "coms.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 }}
77 changes: 77 additions & 0 deletions charts/coms/templates/_helpers.tpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
{{/*
Expand the name of the chart.
*/}}
{{- define "coms.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 "coms.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" $name .Release.Name | trunc 63 | trimSuffix "-" }}
{{- end }}
{{- end }}
{{- end }}

{{/*
Define the config pattern of the chart based on options.
*/}}
{{- define "coms.configname" -}}
{{- if .Values.config.releaseScoped }}
{{- include "coms.fullname" . }}
{{- else }}
{{- include "coms.name" . }}
{{- end }}
{{- end }}

{{/*
Create chart name and version as used by the chart label.
*/}}
{{- define "coms.chart" -}}
{{- printf "%s-%s" .Chart.Name .Chart.Version | replace "+" "_" | trunc 63 | trimSuffix "-" }}
{{- end }}

{{/*
Common labels
*/}}
{{- define "coms.labels" -}}
helm.sh/chart: {{ include "coms.chart" . }}
app: {{ include "coms.fullname" . }}
{{ include "coms.selectorLabels" . }}
{{- if .Chart.AppVersion }}
app.kubernetes.io/version: {{ .Chart.AppVersion | quote }}
{{- end }}
app.kubernetes.io/component: backend
app.kubernetes.io/managed-by: {{ .Release.Service }}
app.kubernetes.io/part-of: {{ .Release.Name }}
app.openshift.io/runtime: nodejs
{{- end }}

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

{{/*
Create the name of the service account to use
*/}}
{{- define "coms.serviceAccountName" -}}
{{- if .Values.serviceAccount.create }}
{{- default (include "coms.fullname" .) .Values.serviceAccount.name }}
{{- else }}
{{- default "default" .Values.serviceAccount.name }}
{{- end }}
{{- end }}
13 changes: 13 additions & 0 deletions charts/coms/templates/configmap.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{{- if .Values.config.enabled -}}
apiVersion: v1
kind: ConfigMap
metadata:
name: {{ include "coms.configname" . }}-config
labels:
{{- include "coms.labels" . | nindent 4 }}
{{- with .Values.route.annotations }}
annotations:
{{- toYaml . | nindent 4 }}
{{- end }}
data: {{ toYaml .Values.config.configMap | nindent 2 }}
{{- end }}
161 changes: 161 additions & 0 deletions charts/coms/templates/deploymentconfig.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,161 @@
{{- define "coms.connectsTo" -}}
apiVersion: apps/v1
kind: StatefulSet
name: {{ include "patroni.fullname" .Subcharts.patroni }}
{{- end }}
---
apiVersion: apps.openshift.io/v1
kind: DeploymentConfig
metadata:
name: {{ include "coms.fullname" . }}
labels:
{{- include "coms.labels" . | nindent 4 }}
{{- if .Values.patroni.enabled }}
annotations:
app.openshift.io/connects-to: '[{{ include "coms.connectsTo" . | fromYaml | toJson }}]'
{{- end }}
spec:
replicas: {{ .Values.replicaCount }}
revisionHistoryLimit: 10
selector:
{{- include "coms.selectorLabels" . | nindent 4 }}
strategy:
resources:
{{- toYaml .Values.resources | nindent 6 }}
rollingParams:
timeoutSeconds: 600
{{- if .Values.config.configMap.DB_ENABLED }}
pre:
failurePolicy: {{ .Values.failurePolicy }}
execNewPod:
command:
- npm
- run
- migrate
containerName: app
env:
- name: NODE_ENV
value: production
- name: DB_DATABASE
valueFrom:
secretKeyRef:
key: app-db-name
name: {{ include "patroni.fullname" .Subcharts.patroni }}
- name: DB_HOST
value: {{ include "patroni.fullname" .Subcharts.patroni }}
- name: DB_USERNAME
valueFrom:
secretKeyRef:
key: app-db-username
name: {{ include "patroni.fullname" .Subcharts.patroni }}
- name: DB_PASSWORD
valueFrom:
secretKeyRef:
key: app-db-password
name: {{ include "patroni.fullname" .Subcharts.patroni }}
{{- end }}
type: Rolling
template:
metadata:
labels: {{ include "coms.selectorLabels" . | nindent 8 }}
spec:
{{- with .Values.imagePullSecrets }}
imagePullSecrets: {{ toYaml . | nindent 8 }}
{{- end }}
{{- if .Values.serviceAccount.create }}
serviceAccountName: {{ include "coms.serviceAccountName" . }}
{{- end }}
{{- with .Values.podSecurityContext }}
securityContext: {{ toYaml . | nindent 8 }}
{{- end }}
containers:
- name: app
{{- with .Values.securityContext }}
securityContext: {{ toYaml . | nindent 12 }}
{{- end }}
image: "{{ .Values.image.repository }}/{{ .Chart.Name }}:{{ .Values.image.tag | default .Chart.AppVersion }}"
imagePullPolicy: {{ .Values.image.pullPolicy }}
ports:
- containerPort: {{ .Values.service.port }}
protocol: TCP
livenessProbe:
failureThreshold: 3
httpGet:
path: {{ .Values.route.path }}
port: {{ .Values.service.port }}
scheme: HTTP
initialDelaySeconds: 10
timeoutSeconds: 1
readinessProbe:
failureThreshold: 3
httpGet:
path: {{ .Values.route.path }}
port: {{ .Values.service.port }}
scheme: HTTP
initialDelaySeconds: 10
timeoutSeconds: 1
resources: {{ toYaml .Values.resources | nindent 12 }}
env:
- name: NODE_ENV
value: production
{{- if .Values.config.configMap.BASICAUTH_ENABLED }}
- name: BASICAUTH_USERNAME
valueFrom:
secretKeyRef:
key: username
name: {{ include "coms.configname" . }}-basicauth
- name: BASICAUTH_PASSWORD
valueFrom:
secretKeyRef:
key: password
name: {{ include "coms.configname" . }}-basicauth
{{- end }}
{{- if .Values.config.configMap.DB_ENABLED }}
- name: DB_DATABASE
valueFrom:
secretKeyRef:
key: app-db-name
name: {{ include "patroni.fullname" .Subcharts.patroni }}
- name: DB_HOST
value: {{ include "patroni.fullname" .Subcharts.patroni }}
- name: DB_USERNAME
valueFrom:
secretKeyRef:
key: app-db-username
name: {{ include "patroni.fullname" .Subcharts.patroni }}
- name: DB_PASSWORD
valueFrom:
secretKeyRef:
key: app-db-password
name: {{ include "patroni.fullname" .Subcharts.patroni }}
{{- end }}
{{- if .Values.config.configMap.KC_ENABLED }}
- name: KC_CLIENTID
valueFrom:
secretKeyRef:
key: username
name: {{ include "coms.configname" . }}-keycloak
- name: KC_CLIENTSECRET
valueFrom:
secretKeyRef:
key: password
name: {{ include "coms.configname" . }}-keycloak
{{- end }}
- name: OBJECTSTORAGE_ACCESSKEYID
valueFrom:
secretKeyRef:
key: username
name: {{ include "coms.configname" . }}-objectstorage
- name: OBJECTSTORAGE_SECRETACCESSKEY
valueFrom:
secretKeyRef:
key: password
name: {{ include "coms.configname" . }}-objectstorage
envFrom:
- configMapRef:
name: {{ include "coms.configname" . }}-config
restartPolicy: Always
terminationGracePeriodSeconds: 30
test: false
triggers:
- type: ConfigChange
Loading

0 comments on commit b684159

Please sign in to comment.