Skip to content

Commit

Permalink
Merge pull request #165 from ninjaneers-team/feat/helm-chart
Browse files Browse the repository at this point in the history
feat(helm-chart): add helm chart for kubernetes deployment
  • Loading branch information
marcells authored Feb 21, 2019
2 parents e45ea7d + 0211799 commit 38fb1ce
Show file tree
Hide file tree
Showing 11 changed files with 316 additions and 2 deletions.
11 changes: 9 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,12 @@ Jump to the [configuration documentation](#configuration) and see how the servic

### Quickstart

You have three options:
You have four options:

- Run node-build-monitor [by downloading the standalone version](#run-the-standalone-version-easiest-way) <sub><sup>(easiest way to run it)</sup></sub>
- Run node-build-monitor [manually with node](#run-it-manually-during-development) <sub><sup>(preferred during development)</sup></sub>
- Run node-build-monitor [with Docker Compose](#run-it-with-docker-compose-in-production) <sub><sup>(preferred in production)</sup></sub>
- Run node-build-monitor [in kubernetes](#run-it-in-kubernetes-as-a-helm-chart) <sub><sup>(as a helm chart)</sup></sub>

### Configuration

Expand Down Expand Up @@ -112,7 +113,7 @@ Supports the [Travis CI](https://travis-ci.org/) build service.
|------------------|--------------------------------------------------------------------------------------------
| `slug` | The name of the build (usually your GitHub user name and the project name)
| `url` | The Travis CI server (travis-ci.org, travis-ci.com, travis.enterprise_name.com). Defaults to travis-ci.org.
| `token` | The Travis access token, to access your private builds (can be found on your Accounts page. If this does not work then you must use the access token you get by executing shell commands. More information can be found at https://blog.travis-ci.com/2013-01-28-token-token-token).
| `token` | The Travis access token, to access your private builds (can be found on your Accounts page. If this does not work then you must use the access token you get by executing shell commands. More information can be found at https://blog.travis-ci.com/2013-01-28-token-token-token).
| `is_enterprise` | Set this value to 'true' if you plan to use Travis CI enterprise. Default to false.

#### Jenkins
Expand Down Expand Up @@ -585,6 +586,12 @@ You can take a look at the logs of the build monitor by using this command:
docker-compose logs
```

### Run it in Kubernetes as a helm chart

You can use the helm chart to deploy node-build-monitor in your kubernetes cluster.

__TL;DR:__ Go to the [charts directory](charts/), and deploy it to your cluster with `helm install . --name build-monitor`. To set the configuration you need to modify the values.yaml file. See [Readme](charts/README.md) in chart folder for more informations.

### Theming support

Here you can check out the existing themes. Feel free to [add your own](#creating-a-new-theme) and make a pull request. It can be done very easy.
Expand Down
20 changes: 20 additions & 0 deletions charts/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
| Parameter | Description | Default |
|----------------------------------------|---------------------------------------------|-----------------------------------------------------|
| `image.pullPolicy` | Container pull policy | `IfNotPresent` |
| `image.repository` | Container image to use | `marcells/node-build-monitor` |
| `image.tag` | Container image tag to deploy | `latest` |
| `replicaCount` | k8s replicas | `1` |
| `resources` | Container resource | `{}` |
| `nodeSelector` | Map of node labels for pod assignment | `{}` |
| `tolerations` | List of node taints to tolerate | `[]` |
| `affinity` | Map of node/pod affinities | `{}` |
| `ingress.enabled` | Enable ingress | `false` |
| `ingress.annotations` | Ingress annotations | `{}` |
| `ingress.hosts` | Ingress Hostnames | `["build-monitor.local"]` |
| `ingress.path` | Path within the URL structure | `/` |
| `ingress.tls` | Ingress TLS configuration | `[]` |
| `service.type` | Kubernetes Service type | `ClusterIP` |
| `service.port` | Port | `80` |
| `config` | Json config for node-build-monitor | `{}` |
| `port` | Port of application | `3000` |
| `rejectTls` | reject tls envirnment var | `1` |
21 changes: 21 additions & 0 deletions charts/build-monitor/.helmignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# 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
5 changes: 5 additions & 0 deletions charts/build-monitor/Chart.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
apiVersion: v1
appVersion: "1.0"
description: A Helm chart for Kubernetes
name: build-monitor
version: 0.1.0
19 changes: 19 additions & 0 deletions charts/build-monitor/templates/NOTES.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
1. Get the application URL by running these commands:
{{- if .Values.ingress.enabled }}
{{- range .Values.ingress.hosts }}
http{{ if $.Values.ingress.tls }}s{{ end }}://{{ . }}{{ $.Values.ingress.path }}
{{- end }}
{{- else if contains "NodePort" .Values.service.type }}
export NODE_PORT=$(kubectl get --namespace {{ .Release.Namespace }} -o jsonpath="{.spec.ports[0].nodePort}" services {{ include "build-monitor.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 svc -w {{ include "build-monitor.fullname" . }}'
export SERVICE_IP=$(kubectl get svc --namespace {{ .Release.Namespace }} {{ include "build-monitor.fullname" . }} -o jsonpath='{.status.loadBalancer.ingress[0].ip}')
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 "build-monitor.name" . }},app.kubernetes.io/instance={{ .Release.Name }}" -o jsonpath="{.items[0].metadata.name}")
echo "Visit http://127.0.0.1:8080 to use your application"
kubectl port-forward $POD_NAME 8080:80
{{- end }}
32 changes: 32 additions & 0 deletions charts/build-monitor/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 "build-monitor.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 "build-monitor.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 "build-monitor.chart" -}}
{{- printf "%s-%s" .Chart.Name .Chart.Version | replace "+" "_" | trunc 63 | trimSuffix "-" -}}
{{- end -}}
6 changes: 6 additions & 0 deletions charts/build-monitor/templates/configmap.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
apiVersion: v1
kind: ConfigMap
metadata:
name: config-file
data:
config.json: {{ .Values.config | quote }}
64 changes: 64 additions & 0 deletions charts/build-monitor/templates/deployment.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
apiVersion: apps/v1beta2
kind: Deployment
metadata:
name: {{ include "build-monitor.fullname" . }}
labels:
app.kubernetes.io/name: {{ include "build-monitor.name" . }}
helm.sh/chart: {{ include "build-monitor.chart" . }}
app.kubernetes.io/instance: {{ .Release.Name }}
app.kubernetes.io/managed-by: {{ .Release.Service }}
spec:
replicas: {{ .Values.replicaCount }}
selector:
matchLabels:
app.kubernetes.io/name: {{ include "build-monitor.name" . }}
app.kubernetes.io/instance: {{ .Release.Name }}
template:
metadata:
labels:
app.kubernetes.io/name: {{ include "build-monitor.name" . }}
app.kubernetes.io/instance: {{ .Release.Name }}
spec:
containers:
- name: {{ .Chart.Name }}
image: "{{ .Values.image.repository }}:{{ .Values.image.tag }}"
imagePullPolicy: {{ .Values.image.pullPolicy }}
volumeMounts:
- mountPath: /build-mon/app/config.json
subPath: config.json
name: config-volume
env:
- name: "PORT"
value: {{ .Values.port | quote }}
- name: "NODE_TLS_REJECT_UNAUTHORIZED"
value: {{ .Values.rejectTls | quote }}
ports:
- name: http
containerPort: 3000
protocol: TCP
livenessProbe:
httpGet:
path: /
port: http
readinessProbe:
httpGet:
path: /
port: http
resources:
{{ toYaml .Values.resources | indent 12 }}
volumes:
- name: config-volume
configMap:
name: config-file
{{- with .Values.nodeSelector }}
nodeSelector:
{{ toYaml . | indent 8 }}
{{- end }}
{{- with .Values.affinity }}
affinity:
{{ toYaml . | indent 8 }}
{{- end }}
{{- with .Values.tolerations }}
tolerations:
{{ toYaml . | indent 8 }}
{{- end }}
38 changes: 38 additions & 0 deletions charts/build-monitor/templates/ingress.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
{{- if .Values.ingress.enabled -}}
{{- $fullName := include "build-monitor.fullname" . -}}
{{- $ingressPath := .Values.ingress.path -}}
apiVersion: extensions/v1beta1
kind: Ingress
metadata:
name: {{ $fullName }}
labels:
app.kubernetes.io/name: {{ include "build-monitor.name" . }}
helm.sh/chart: {{ include "build-monitor.chart" . }}
app.kubernetes.io/instance: {{ .Release.Name }}
app.kubernetes.io/managed-by: {{ .Release.Service }}
{{- with .Values.ingress.annotations }}
annotations:
{{ toYaml . | indent 4 }}
{{- end }}
spec:
{{- if .Values.ingress.tls }}
tls:
{{- range .Values.ingress.tls }}
- hosts:
{{- range .hosts }}
- {{ . | quote }}
{{- end }}
secretName: {{ .secretName }}
{{- end }}
{{- end }}
rules:
{{- range .Values.ingress.hosts }}
- host: {{ . | quote }}
http:
paths:
- path: {{ $ingressPath }}
backend:
serviceName: {{ $fullName }}
servicePort: http
{{- end }}
{{- end }}
19 changes: 19 additions & 0 deletions charts/build-monitor/templates/service.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
apiVersion: v1
kind: Service
metadata:
name: {{ include "build-monitor.fullname" . }}
labels:
app.kubernetes.io/name: {{ include "build-monitor.name" . }}
helm.sh/chart: {{ include "build-monitor.chart" . }}
app.kubernetes.io/instance: {{ .Release.Name }}
app.kubernetes.io/managed-by: {{ .Release.Service }}
spec:
type: {{ .Values.service.type }}
ports:
- port: {{ .Values.service.port }}
targetPort: http
protocol: TCP
name: http
selector:
app.kubernetes.io/name: {{ include "build-monitor.name" . }}
app.kubernetes.io/instance: {{ .Release.Name }}
83 changes: 83 additions & 0 deletions charts/build-monitor/values.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
# Default values for build-monitor.
# This is a YAML-formatted file.
# Declare variables to be passed into your templates.

replicaCount: 1

image:
repository: marcells/node-build-monitor
tag: latest
pullPolicy: IfNotPresent

nameOverride:
fullnameOverride:

# env var for port
port: 3000

# env var to reject tls
rejectTls: 1

# json config (config.json in app)
config: |
{
"monitor": {
"interval": 30000,
"numberOfBuilds": 12,
"latestBuildOnly": false,
"sortOrder": "date",
"errorsFirst": false,
"expandEnvironmentVariables": false,
"debug": true
},
"services": [
{
"name": "Travis",
"configuration": {
"slug": "node-build-monitor"
}
},
{
"name": "Travis",
"configuration": {
"slug": "marcells/bloggy",
"latestBuildOnly": true
}
}
]
}
service:
type: ClusterIP
port: 80

ingress:
enabled: false
annotations: {}
# kubernetes.io/ingress.class: nginx
# kubernetes.io/tls-acme: true
path: /
hosts:
- build-monitor.local
tls: []
# - secretName: build-monitor-tls
# hosts:
# - build-monitor.local

resources: {}
# We usually recommend not to specify default resources and to leave this as a conscious
# choice for the user. This also increases chances charts run on environments with little
# resources, such as Minikube. If you do want to specify resources, uncomment the following
# lines, adjust them as necessary, and remove the curly braces after 'resources:'.
# limits:
# cpu: 100m
# memory: 128Mi
# requests:
# cpu: 100m
# memory: 128Mi

nodeSelector: {}

tolerations: []

affinity: {}

0 comments on commit 38fb1ce

Please sign in to comment.