Skip to content

Commit

Permalink
add documentation and tests
Browse files Browse the repository at this point in the history
  • Loading branch information
jschwarz-eitco-de committed Jul 31, 2024
1 parent b01d519 commit 8f2b4bb
Show file tree
Hide file tree
Showing 24 changed files with 663 additions and 7 deletions.
3 changes: 2 additions & 1 deletion .github/workflows/release.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,11 @@ jobs:
release:
runs-on: ubuntu-latest
steps:
- uses: eitco/[email protected].1
- uses: eitco/[email protected].2
with:
gpg-private-key: ${{ secrets.ARTIFACT_SIGNING_GPG_PRIVATE_KEY }}
gpg-key-name: ${{ secrets.ARTIFACT_SIGNING_GPG_KEY_NAME }}
gpg-passphrase: ${{ secrets.ARTIFACT_SIGNING_GPG_PRIVATE_KEY_PASSWORD }}
deploy-user: ${{ secrets.OSSRH_JIRA_USERNAME }}
deploy-password: ${{ secrets.OSSRH_JIRA_PASSWORD }}
git-ssh-private-key: ${{ secrets.SSH_KEY_EITCO_GITHUB }}
66 changes: 63 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,70 @@

[![License](https://img.shields.io/github/license/eitco/helm-maven-plugin.svg?style=for-the-badge)](https://opensource.org/license/mit)


[![Build status](https://img.shields.io/github/actions/workflow/status/eitco/helm-maven-plugin/deploy.yaml?branch=main&style=for-the-badge&logo=github)](https://github.com/eitco/helm-maven-plugin/actions/workflows/deploy.yaml)
[![Maven Central Version](https://img.shields.io/maven-central/v/de.eitco.cicd/helm-maven-plugin?style=for-the-badge&logo=apachemaven)](https://central.sonatype.com/artifact/de.eitco.cicd/helm-maven-plugin)

# helm maven plugin

This maven plugin builds and deploys helm charts.
This maven plugin provides a build lifecycle for building and deploying helm charts. It is built on top of
[Device Insights helm maven plugin](https://github.com/deviceinsight/helm-maven-plugin).


# usage

In order to make the `helm` build lifecycle available add this plugin to your build activating extensions:

```xml
...
<build>
<plugins>
<plugin>
<groupId>de.eitco.cicd.helm</groupId>
<artifactId>helm-maven-plugin</artifactId>
<version>4.0.1</version>
<extensions>true</extensions>
</plugin>
</plugins>
</build>
```

Now you can activate the `helm` build lifecycle by specifying the packaging `helm`:

```xml
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>

<groupId>your.group.id</groupId>
<artifactId>your-artifact-id</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>helm</packaging>
...
</project>
```

One required parameter needs to be set, though - the version of helm to use:

```xml
...
<build>
<plugins>
<plugin>
<groupId>de.eitco.cicd.helm</groupId>
<artifactId>helm-maven-plugin</artifactId>
<version>4.0.1</version>
<extensions>true</extensions>
<configuration>
<helmVersion>3.15.3</helmVersion>
</configuration>
</plugin>
</plugins>
</build>
```

Now you can add your files in `src/main/helm`. Refer to the [integration test](./src/it/simple) for a simple example.

> 📘 Note that there is no `Chart.yaml` file in this example. The plugin will generate this file by itself from values
> configured in the `pom.xml`

38 changes: 36 additions & 2 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@
<parent>
<groupId>de.eitco.cicd</groupId>
<artifactId>eitco-oss-parent</artifactId>
<version>0.0.14</version>
<version>0.0.15</version>
</parent>


<groupId>de.eitco.cicd</groupId>
<groupId>de.eitco.cicd.helm</groupId>
<artifactId>helm-maven-plugin</artifactId>
<version>4.0.1-SNAPSHOT</version>
<packaging>maven-plugin</packaging>
Expand Down Expand Up @@ -92,6 +92,9 @@
<plugins>
<plugin>
<artifactId>maven-release-plugin</artifactId>
<configuration>
<goals>deploy site site:stage scm-publish:publish-scm</goals>
</configuration>
</plugin>
<plugin>
<artifactId>maven-resources-plugin</artifactId>
Expand All @@ -104,6 +107,21 @@
<groupId>org.codehaus.mojo</groupId>
<artifactId>license-maven-plugin</artifactId>
</plugin>
<plugin>
<groupId>org.jacoco</groupId>
<artifactId>jacoco-maven-plugin</artifactId>
</plugin>
<plugin>
<artifactId>maven-invoker-plugin</artifactId>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-site-plugin</artifactId>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-scm-publish-plugin</artifactId>
</plugin>
</plugins>
</build>

Expand All @@ -118,6 +136,22 @@
</repository>
</repositories>

<reporting>
<excludeDefaults>true</excludeDefaults>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-plugin-report-plugin</artifactId>
</plugin>
</plugins>
</reporting>

<distributionManagement>
<site>
<id>github</id>
<url>scm:git:https://github.com/eitco/eitco.github.io.git</url>
</site>
</distributionManagement>


</project>
39 changes: 39 additions & 0 deletions src/it/settings.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
<?xml version="1.0"?>
<settings>
<profiles>
<profile>
<id>it-repo</id>
<activation>
<activeByDefault>true</activeByDefault>
</activation>
<repositories>
<repository>
<id>local.central</id>
<url>@localRepositoryUrl@</url>
<releases>
<enabled>true</enabled>
<updatePolicy>never</updatePolicy>
</releases>
<snapshots>
<enabled>true</enabled>
<updatePolicy>never</updatePolicy>
</snapshots>
</repository>
</repositories>
<pluginRepositories>
<pluginRepository>
<id>local.central</id>
<url>@localRepositoryUrl@</url>
<releases>
<enabled>true</enabled>
<updatePolicy>never</updatePolicy>
</releases>
<snapshots>
<enabled>true</enabled>
<updatePolicy>never</updatePolicy>
</snapshots>
</pluginRepository>
</pluginRepositories>
</profile>
</profiles>
</settings>
27 changes: 27 additions & 0 deletions src/it/simple/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>

<groupId>de.eitco.cicd.test</groupId>
<artifactId>cicd-helm-simple-test</artifactId>
<version>1.0.0-SNAPSHOT</version>
<packaging>helm</packaging>


<build>
<plugins>
<plugin>
<groupId>@project.groupId@</groupId>
<artifactId>helm-maven-plugin</artifactId>
<version>@project.version@</version>
<extensions>true</extensions>
<configuration>
<helmVersion>3.15.3</helmVersion>
<!-- <helmVersion>3.8.1</helmVersion>-->
</configuration>
</plugin>
</plugins>
</build>

</project>
23 changes: 23 additions & 0 deletions src/it/simple/src/main/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/
22 changes: 22 additions & 0 deletions src/it/simple/src/main/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 "temp.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 its status by running 'kubectl get --namespace {{ .Release.Namespace }} svc -w {{ include "temp.fullname" . }}'
export SERVICE_IP=$(kubectl get svc --namespace {{ .Release.Namespace }} {{ include "temp.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 "temp.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 src/it/simple/src/main/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 "temp.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 "temp.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 "temp.chart" -}}
{{- printf "%s-%s" .Chart.Name .Chart.Version | replace "+" "_" | trunc 63 | trimSuffix "-" }}
{{- end }}

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

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

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

0 comments on commit 8f2b4bb

Please sign in to comment.