Skip to content

Commit

Permalink
feat: add mailhog helm chart
Browse files Browse the repository at this point in the history
  • Loading branch information
dleard committed Jun 18, 2020
1 parent a28519f commit 2ce1cef
Show file tree
Hide file tree
Showing 15 changed files with 465 additions and 5 deletions.
2 changes: 1 addition & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ repos:
- id: check-json
- id: check-vcs-permalinks
- id: check-yaml
exclude: ^helm/cas-ciip-portal/templates/
exclude: ^helm/.*/templates/
- id: end-of-file-fixer
exclude: current_version\.txt
- id: trailing-whitespace
Expand Down
4 changes: 4 additions & 0 deletions helm/cas-ciip-portal/Chart.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,7 @@ dependencies:
- name: cas-postgres
version: "0.4.0"
repository: https://bcgov.github.io/cas-postgres/
- name: mailhog
version: "3.2.0"
repository: "file://../mailhog"
condition: mailhog.enable
8 changes: 6 additions & 2 deletions helm/cas-ciip-portal/values-wksv3k-dev.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,17 @@ route:
insecure: false # cert has been issued

env:
smtpConnectionString: smtp://apps.smtp.gov.bc.ca/?port=25&ignoreTLS=true&secure=false
smtpConnectionString: smtp://@localhost:1025
senderEmail: no-reply-dev.cas@gov.bc.ca
adminEmail: matthieu@button.is
adminEmail: admin@ciip.dev
appHost: https://ciip-dev.pathfinder.gov.bc.ca # This should be different from the route for the production site (appHost will be https://ciip.gov.bc.ca)

fider:
host: # TODO move fider template in this repo

mailhog:
enable: true

cas-postgres:
patroni:
walE:
Expand Down
8 changes: 6 additions & 2 deletions helm/cas-ciip-portal/values-wksv3k-test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,18 @@ route:
insecure: false # cert has been issued

env:
smtpConnectionString: smtp://example.com
smtpConnectionString: smtp://@localhost:1025
senderEmail: no-reply-dev.cas@gov.bc.ca
adminEmail: matthieu@button.is
adminEmail: admin@ciip.test
appHost: https://ciip-test.pathfinder.gov.bc.ca # This should be different from the route for the production site (appHost will be https://ciip.gov.bc.ca)

fider:
host: https://ciip-portal-wksv3k-test-feedback.pathfinder.gov.bc.ca/
# TODO move fider template in this repo

mailhog:
enable: true

cas-postgres:
patroni:
walE:
Expand Down
3 changes: 3 additions & 0 deletions helm/cas-ciip-portal/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,9 @@ env:
fider:
host: # TODO move fider template in this repo

mailhog:
enable: false

cas-postgres:
patroni:
resources:
Expand Down
22 changes: 22 additions & 0 deletions helm/mailhog/.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/
19 changes: 19 additions & 0 deletions helm/mailhog/Chart.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
apiVersion: v1
description: An e-mail testing tool for developers
name: mailhog
appVersion: 1.0.0
version: 3.2.0
keywords:
- mailhog
- mail
- smtp
- email
- e-mail
- testing
home: http://iankent.uk/project/mailhog/
icon: https://raw.githubusercontent.com/mailhog/MailHog-UI/master/assets/images/hog.png
sources:
- https://github.com/mailhog/MailHog
maintainers:
- name: unguiculus
email: unguiculus@gmail.com
87 changes: 87 additions & 0 deletions helm/mailhog/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
# Mailhog

[Mailhog](http://iankent.uk/project/mailhog/) is an e-mail testing tool for developers.

## TL;DR;

```bash
$ helm install stable/mailhog
```

## Introduction

This chart creates a [Mailhog](http://iankent.uk/project/mailhog/) deployment on a [Kubernetes](http://kubernetes.io)
cluster using the [Helm](https://helm.sh) package manager.

## Prerequisites

- Kubernetes 1.9+ with Beta APIs enabled

## Installing the Chart

To install the chart with the release name `my-release`:

```bash
$ helm install --name my-release codecentric/mailhog
```

The command deploys Mailhog on the Kubernetes cluster in the default configuration. The [configuration](#configuration)
section lists the parameters that can be configured during installation.

## Uninstalling the Chart

To uninstall/delete the `my-release` deployment:

```bash
$ helm delete my-release
```
The command removes all the Kubernetes components associated with the chart and deletes the release.

## Configuration

The following table lists the configurable parameters of the Mailhog chart and their default values.

Parameter | Description | Default
--- | --- | ---
`image.repository` | Docker image repository | `mailhog/mailhog`
`image.tag` | Docker image tag | `v1.0.0`
`image.pullPolicy` | Docker image pull policy | `IfNotPresent`
`auth.enabled` | Specifies whether basic authentication is enabled, see [Auth.md](https://github.com/mailhog/MailHog/blob/master/docs/Auth.md) | `false`
`auth.existingSecret` | If auth is enabled, uses an existing secret with this name; otherwise a secret is created | `""`
`auth.fileName` | The name of the auth file | `auth.txt`
`auth.fileContents` | The contents of the auth file | `""`
`nodeSelector` | Node labels for pod assignment | `{}`
`podAnnotations` | Extra annotations to add to pod | `{}`
`podLabels` | Extra labels to add to pod | `{}`
`resources` | Pod resource requests and limits | `{}`
`tolerations` | Node taints to tolerate | `[]`
`service.annotations` | Annotations for the service | `{}`
`service.clusterIP` | Internal cluster service IP | `""`
`service.externalIPs` | Service external IP addresses | `[]`
`service.loadBalancerIP` | IP address to assign to load balancer (if supported) | `""`
`service.loadBalancerSourceRanges` | List of IP CIDRs allowed access to load balancer (if supported) | `[]`
`service.type` | Type of service to create | `ClusterIP`
`service.node.http` | HTTP port of service | `""`
`service.node.smtp` | SMTP port of service | `""`
`service.nodePort.http` | If `service.type` is `NodePort` and this is non-empty, sets the http node port of the service | `""`
`service.nodePort.smtp` | If `service.type` is `NodePort` and this is non-empty, sets the smtp node port of the service | `""`
`securityContext` | Pod security context | `{ runAsUser: 1000, fsGroup: 1000, runAsNonRoot: true }`
`ingress.enabled` | If `true`, an ingress is created | `false`
`ingress.annotations` | Annotations for the ingress | `{}`
`ingress.hosts` | A list of ingress hosts | `{ host: mailhog.example.com, paths: ["/"] }`
`ingress.tls` | A list of [IngressTLS](https://v1-8.docs.kubernetes.io/docs/api-reference/v1.8/#ingresstls-v1beta1-extensions) items | `[]`
`extraEnv` | Additional environment variables, see [CONFIG.md](https://github.com/mailhog/MailHog/blob/master/docs/CONFIG.md) | `{}`

Specify each parameter using the `--set key=value[,key=value]` argument to `helm install`. For example,

```bash
$ helm install --name my-release \
--set env.MH_UI_WEB_PATH=mailhog \
stable/mailhog
```

Alternatively, a YAML file that specifies the values for the parameters can be provided while installing the chart. For example,

```bash
$ helm install --name my-release -f values.yaml stable/mailhog
```
16 changes: 16 additions & 0 deletions helm/mailhog/templates/NOTES.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
Mailhog can be accessed via ports {{ .Values.service.port.http }} (HTTP) and {{ .Values.service.port.smtp }} (SMTP) on the following DNS name from within your cluster:
{{ template "mailhog.fullname" . }}.{{ .Release.Namespace }}.svc.cluster.local

If you'd like to test your instance, forward the ports locally:

Web UI:
=======

export POD_NAME=$(kubectl get pods --namespace {{ .Release.Namespace }} -l "app={{ template "mailhog.name" . }},release={{ .Release.Name }}" -o jsonpath="{.items[0].metadata.name}")
kubectl port-forward --namespace {{ .Release.Namespace }} $POD_NAME 8025

SMTP Server:
============

export POD_NAME=$(kubectl get pods --namespace {{ .Release.Namespace }} -l "app={{ template "mailhog.name" . }},release={{ .Release.Name }}" -o jsonpath="{.items[0].metadata.name}")
kubectl port-forward --namespace {{ .Release.Namespace }} $POD_NAME 1025
43 changes: 43 additions & 0 deletions helm/mailhog/templates/_helpers.tpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
{{/* vim: set filetype=mustache: */}}
{{/*
Expand the name of the chart.
*/}}
{{- define "mailhog.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 "mailhog.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 "mailhog.chart" -}}
{{- printf "%s-%s" .Chart.Name .Chart.Version | replace "+" "_" | trunc 63 | trimSuffix "-" -}}
{{- end -}}

{{/*
Create the name for the auth secret.
*/}}
{{- define "mailhog.authFileSecret" -}}
{{- if .Values.auth.existingSecret -}}
{{- .Values.auth.existingSecret -}}
{{- else -}}
{{- template "mailhog.fullname" . -}}-auth
{{- end -}}
{{- end -}}
14 changes: 14 additions & 0 deletions helm/mailhog/templates/auth-secret.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{{- if and (.Values.auth.enabled) (not .Values.auth.existingSecret) -}}
apiVersion: v1
kind: Secret
metadata:
labels:
app.kubernetes.io/name: {{ include "mailhog.name" . }}
helm.sh/chart: {{ include "mailhog.chart" . }}
app.kubernetes.io/instance: {{ .Release.Name }}
app.kubernetes.io/managed-by: {{ .Release.Service }}
name: {{ template "mailhog.authFileSecret" . }}
type: Opaque
data:
{{ .Values.auth.fileName }}: {{ .Values.auth.fileContents | b64enc }}
{{- end -}}
88 changes: 88 additions & 0 deletions helm/mailhog/templates/deployment.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
apiVersion: apps/v1
kind: Deployment
metadata:
name: {{ include "mailhog.fullname" . }}
labels:
app.kubernetes.io/name: {{ include "mailhog.name" . }}
helm.sh/chart: {{ include "mailhog.chart" . }}
app.kubernetes.io/instance: {{ .Release.Name }}
app.kubernetes.io/managed-by: {{ .Release.Service }}
spec:
selector:
matchLabels:
app.kubernetes.io/name: {{ include "mailhog.name" . }}
app.kubernetes.io/instance: {{ .Release.Name }}
template:
metadata:
{{- with .Values.podAnnotations }}
annotations:
{{- toYaml . | nindent 8 }}
{{- end }}
labels:
app.kubernetes.io/name: {{ include "mailhog.name" . }}
app.kubernetes.io/instance: {{ .Release.Name }}
{{- with .Values.podLabels }}
{{- toYaml . | nindent 8 }}
{{- end }}
spec:
{{- with .Values.securityContext }}
securityContext:
{{- toYaml . | nindent 8 }}
{{- end }}
containers:
- name: {{ template "mailhog.name" . }}
image: "{{ .Values.image.repository }}:{{ .Values.image.tag }}"
imagePullPolicy: "{{ .Values.image.pullPolicy }}"
env:
- name: MH_HOSTNAME
valueFrom:
fieldRef:
fieldPath: metadata.name
{{- if .Values.auth.enabled }}
- name: MH_AUTH_FILE
value: /authdir/{{ .Values.auth.fileName }}
{{- end }}
{{- with .Values.extraEnv }}
{{- toYaml . | nindent 12 }}
{{- end }}
ports:
- name: http
containerPort: 8025
protocol: TCP
- name: smtp
containerPort: 1025
protocol: TCP
livenessProbe:
tcpSocket:
port: smtp
initialDelaySeconds: 10
timeoutSeconds: 1
readinessProbe:
tcpSocket:
port: smtp
{{- if .Values.auth.enabled }}
volumeMounts:
- name: authdir
mountPath: /authdir
readOnly: true
{{- end }}
resources:
{{- toYaml .Values.resources | nindent 12 }}
{{- with .Values.affinity }}
affinity:
{{- toYaml . | nindent 8 }}
{{- end }}
{{- with .Values.nodeSelector }}
nodeSelector:
{{- toYaml . | nindent 8 }}
{{- end }}
{{- with .Values.tolerations }}
tolerations:
{{- toYaml . | nindent 8 }}
{{- end }}
{{- if .Values.auth.enabled }}
volumes:
- name: authdir
secret:
secretName: {{ template "mailhog.authFileSecret" . }}
{{- end }}
Loading

0 comments on commit 2ce1cef

Please sign in to comment.