Skip to content

Commit

Permalink
Merge pull request #41 from DanielFran/wiremock-chart-1.0.0
Browse files Browse the repository at this point in the history
Support wiremock v3
  • Loading branch information
leeturner authored Jul 15, 2024
2 parents fdac540 + 53202e1 commit 224fd4f
Show file tree
Hide file tree
Showing 18 changed files with 354 additions and 140 deletions.
10 changes: 5 additions & 5 deletions .github/workflows/cd.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ jobs:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v2
uses: actions/checkout@v3
with:
fetch-depth: 0

Expand All @@ -20,11 +20,11 @@ jobs:
git config user.email "[email protected]"
- name: Install Helm
uses: azure/setup-helm@v1
with:
version: v3.8.1
uses: azure/setup-helm@v4
env:
GITHUB_TOKEN: "${{ secrets.GITHUB_TOKEN }}"

- name: Run chart-releaser
uses: helm/chart-releaser-action@v1.4.0
uses: helm/chart-releaser-action@v1.6.0
env:
CR_TOKEN: "${{ secrets.GITHUB_TOKEN }}"
23 changes: 13 additions & 10 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -19,36 +19,39 @@ jobs:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v2
uses: actions/checkout@v3
with:
fetch-depth: 0

- name: Set up Helm
uses: azure/setup-helm@v1
uses: azure/setup-helm@v3
with:
version: v3.8.1
version: v3.14.0

- uses: actions/setup-python@v2
- uses: actions/setup-python@v4
with:
python-version: 3.7
python-version: '3.12'
check-latest: true

- name: Set up chart-testing
uses: helm/chart-testing-action@v2.2.1
uses: helm/chart-testing-action@v2.6.1

- name: Run chart-testing (list-changed)
id: list-changed
run: |
changed=$(ct list-changed --target-branch ${{ github.event.repository.default_branch }})
if [[ -n "$changed" ]]; then
echo "::set-output name=changed::true"
echo "changed=true" >> "$GITHUB_OUTPUT"
fi
- name: Run chart-testing (lint)
run: ct lint
if: steps.list-changed.outputs.changed == 'true'
run: ct lint --target-branch ${{ github.event.repository.default_branch }}

- name: Create kind cluster
uses: helm/[email protected]
if: steps.list-changed.outputs.changed == 'true'
uses: helm/[email protected]

- name: Run chart-testing (install)
run: ct install
if: steps.list-changed.outputs.changed == 'true'
run: ct install --target-branch ${{ github.event.repository.default_branch }}
10 changes: 10 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,16 @@ and the chart remains partially compatible with it.

## Install WireMock

Once Helm is installed, you can either add this repository with `helm repo add`:

```bash
helm repo add wiremock https://wiremock.github.io/helm-charts
```

You can then run `helm upgrade --install <release name> wiremock/wiremock` to install it through the repository.

Alternatively, you can clone the helm repo and then install it with a local reference:

```bash
helm upgrade --install <release_name> ./charts/<chart_name>
```
Expand Down
2 changes: 2 additions & 0 deletions charts/wiremock/.helmignore
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,10 @@
*.swp
*.bak
*.tmp
*.orig
*~
# Various IDEs
.project
.idea/
*.tmproj
.vscode/
28 changes: 24 additions & 4 deletions charts/wiremock/Chart.yaml
Original file line number Diff line number Diff line change
@@ -1,8 +1,28 @@
apiVersion: v1
appVersion: "3.0.0.1"
description: A Helm chart for WireMock deployment on Kubernetes
apiVersion: v2
name: wiremock
version: 0.2.0
description: A Helm chart for WireMock deployment on 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: 1.0.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: "3.8.0"

maintainers:
- name: "gitkent"
url: "https://github.com/gitkent"
Expand Down
6 changes: 4 additions & 2 deletions charts/wiremock/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,14 @@ Setup port forwarding
```bash
$ export POD_NAME=$(kubectl get pods --namespace {{ .Release.Namespace }} -l "app.kubernetes.io/name={{ include "wiremock.name" . }},app.kubernetes.io/instance={{ .Release.Name }}" -o jsonpath="{.items[0].metadata.name}")

$ kubectl port-forward $POD_NAME 8080:{{ .Values.service.internalPort}}
$ export CONTAINER_PORT=$(kubectl get pod --namespace {{ .Release.Namespace }} $POD_NAME -o jsonpath="{.spec.containers[0].ports[0].containerPort}")

$ kubectl --namespace {{ .Release.Namespace }} port-forward $POD_NAME 8080:$CONTAINER_PORT
```

## Verify Wiremock deployment

To verify erifying a response using Wiremock, run
To verify a response using Wiremock, run

```bash
$ curl -X POST http://127.0.0.1:8080/v1/hello
Expand Down
15 changes: 9 additions & 6 deletions charts/wiremock/templates/NOTES.txt
Original file line number Diff line number Diff line change
@@ -1,20 +1,23 @@
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 }}
{{- 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 "wiremock.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 "wiremock.fullname" . }}'
export SERVICE_IP=$(kubectl get svc --namespace {{ .Release.Namespace }} {{ include "wiremock.fullname" . }} -o jsonpath='{.status.loadBalancer.ingress[0].ip}')
You can watch the status of by running 'kubectl get --namespace {{ .Release.Namespace }} svc -w {{ include "wiremock.fullname" . }}'
export SERVICE_IP=$(kubectl get svc --namespace {{ .Release.Namespace }} {{ include "wiremock.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 "wiremock.name" . }},app.kubernetes.io/instance={{ .Release.Name }}" -o jsonpath="{.items[0].metadata.name}")
kubectl port-forward $POD_NAME 8080:{{ .Values.service.internalPort}}
export CONTAINER_PORT=$(kubectl get pod --namespace {{ .Release.Namespace }} $POD_NAME -o jsonpath="{.spec.containers[0].ports[0].containerPort}")
kubectl --namespace {{ .Release.Namespace }} port-forward $POD_NAME 8080:$CONTAINER_PORT
echo "Visit http://127.0.0.1:8080/__admin/mappings to use your application"
run "curl -X POST http://127.0.0.1:8080/v1/hello"
{{- end }}
{{- end }}
74 changes: 58 additions & 16 deletions charts/wiremock/templates/_helpers.tpl
Original file line number Diff line number Diff line change
@@ -1,32 +1,74 @@
{{/* vim: set filetype=mustache: */}}
{{/*
Expand the name of the chart.
*/}}
{{- define "wiremock.name" -}}
{{- default .Chart.Name .Values.nameOverride | trunc 63 | trimSuffix "-" -}}
{{- end -}}
{{- 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 "wiremock.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 -}}
{{- 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 "wiremock.chart" -}}
{{- printf "%s-%s" .Chart.Name .Chart.Version | replace "+" "_" | trunc 63 | trimSuffix "-" -}}
{{- end -}}
{{- printf "%s-%s" .Chart.Name .Chart.Version | replace "+" "_" | trunc 63 | trimSuffix "-" }}
{{- end }}

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

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

{{/*
Create the name of the service account to use
*/}}
{{- define "wiremock.serviceAccountName" -}}
{{- if .Values.serviceAccount.create }}
{{- default (include "wiremock.fullname" .) .Values.serviceAccount.name }}
{{- else }}
{{- default "default" .Values.serviceAccount.name }}
{{- end }}
{{- end }}

{{/*
Pod annotations
*/}}
{{- define "wiremock.podAnnotations" -}}
checksum/configMappings: {{ include (print $.Template.BasePath "/configmap-mappings.yaml") . | sha256sum }}
checksum/configResponses: {{ include (print $.Template.BasePath "/configmap-responses.yaml") . | sha256sum }}
{{- if .Values.podAnnotations }}
{{ .Values.podAnnotations }}
{{- end }}
{{- end }}

6 changes: 1 addition & 5 deletions charts/wiremock/templates/configmap-mappings.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,8 @@ apiVersion: v1
kind: ConfigMap
metadata:
name: {{ include "wiremock.fullname" . }}-mappings-configs
namespace: {{ .Release.Namespace | quote }}
labels:
app.kubernetes.io/name: {{ include "wiremock.name" . }}
helm.sh/chart: {{ include "wiremock.chart" . }}
app.kubernetes.io/instance: {{ .Release.Name }}
app.kubernetes.io/managed-by: {{ .Release.Service }}
{{- include "wiremock.labels" . | nindent 4 }}
data:
{{- $files := .Files }}
{{- range $key, $value := .Files }}
Expand Down
6 changes: 1 addition & 5 deletions charts/wiremock/templates/configmap-responses.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,8 @@ apiVersion: v1
kind: ConfigMap
metadata:
name: {{ include "wiremock.fullname" . }}-responses-configs
namespace: {{ .Release.Namespace | quote }}
labels:
app.kubernetes.io/name: {{ include "wiremock.name" . }}
helm.sh/chart: {{ include "wiremock.chart" . }}
app.kubernetes.io/instance: {{ .Release.Name }}
app.kubernetes.io/managed-by: {{ .Release.Service }}
{{- include "wiremock.labels" . | nindent 4 }}
data:
{{- $files := .Files }}
{{- range $key, $value := .Files }}
Expand Down
Loading

0 comments on commit 224fd4f

Please sign in to comment.