Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions charts/maven-cacher/Chart.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
apiVersion: v1
description: Maven Cache updater for the *.jenkins.io controllers
name: maven-cacher
version: 0.0.1
maintainers:
- email: jenkins-infra-team@googlegroups.com
name: jenkins-infra-team
48 changes: 48 additions & 0 deletions charts/maven-cacher/templates/_helpers.tpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
{{/* vim: set filetype=mustache: */}}
{{/*
Expand the name of the chart.
*/}}
{{- define "maven-cacher.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 "maven-cacher.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 -}}

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

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

{{/*
Common labels
*/}}
{{- define "maven-cacher.labels" -}}
{{ include "maven-cacher.selectorLabels" . }}
helm.sh/chart: {{ include "maven-cacher.chart" . }}
{{- end -}}
44 changes: 44 additions & 0 deletions charts/maven-cacher/templates/configmap-maven-settings.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
{{- if .Values.mavenMirror.enable }}
---
apiVersion: v1
kind: ConfigMap
metadata:
name: {{ include "maven-cacher.fullname" . }}-maven-settings
labels: {{ include "maven-cacher.labels" . | nindent 4 }}
data:
settings.xml: |
<settings xmlns="http://maven.apache.org/SETTINGS/1.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.0.0 http://maven.apache.org/xsd/settings-1.0.0.xsd">
<mirrors>
<mirror>
<id>{{ .Values.mavenMirror.mirrorId }}</id>
<url>{{ .Values.mavenMirror.url }}</url>
<mirrorOf>{{ .Values.mavenMirror.mirrorOf }}</mirrorOf>
</mirror>
</mirrors>
<profiles>
<profile>
<id>jenkins-infra-plugin-repositories</id>
<pluginRepositories>
<pluginRepository>
<id>repo.jenkins-ci.org</id>
<url>https://repo.jenkins-ci.org/public/</url>
</pluginRepository>
<pluginRepository>
<snapshots>
<enabled>false</enabled>
</snapshots>
<id>incrementals</id>
<url>https://repo.jenkins-ci.org/incrementals/</url>
</pluginRepository>
<pluginRepository>
<id>central</id>
<url>https://repo.maven.apache.org/maven2</url>
</pluginRepository>
</pluginRepositories>
</profile>
</profiles>
<activeProfiles>
<activeProfile>jenkins-infra-plugin-repositories</activeProfile>
</activeProfiles>
</settings>
{{- end }}
43 changes: 43 additions & 0 deletions charts/maven-cacher/templates/configmap-scripts.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
apiVersion: v1
kind: ConfigMap
metadata:
name: {{ include "maven-cacher.fullname" . }}-scripts
labels: {{ include "maven-cacher.labels" . | nindent 4 }}
data:
maven-cacher.sh: |
#!/bin/bash

set -eux -o pipefail

mvn_cache_dir="${MVN_CACHE_DIR:-"/tmp"}"
test -d "${mvn_cache_dir}"
mvn_local_repo="${MVN_LOCAL_REPO:-"${HOME}/.m2/repository"}"
mvn_cache_archive="${mvn_cache_dir}/maven-bom-local-repo.tar.gz"

# Set up local working directory with BOM code
test -d ./bom || git clone https://github.com/jenkinsci/bom
pushd ./bom

# TODO: Retrieve this list from Maven
build_lines=("weekly" "2.479.x" "2.492.x")

# Load dependencies in the local Maven repo
for build_line in "${build_lines[@]}"; do
MVN_OPTS=()
if [[ $build_line != "weekly" ]]; then
MVN_OPTS+=("-P $build_line")
fi
time mvn -pl sample-plugin\
dependency:go-offline \
-DincludeScore=runtime,compile,test \
-Dmaven.repo.local="{{ .Values.mavenLocalRepo }}" \
"${MVN_OPTS[@]}"
done

# Generate a new cache archive from the local Maven repository
pushd "${mvn_local_repo}"
df -h .
du -sh .
time tar czf /tmp/maven-bom-local-repo.tar.gz ./
time cp /tmp/maven-bom-local-repo.tar.gz "${mvn_cache_archive}"
du -sh "${mvn_cache_dir}"/*
97 changes: 97 additions & 0 deletions charts/maven-cacher/templates/cronjob.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
---
apiVersion: batch/v1
kind: CronJob
metadata:
name: {{ include "maven-cacher.fullname" . }}
labels:
{{ include "maven-cacher.labels" . | indent 4 }}
spec:
concurrencyPolicy: Forbid
schedule: {{ .Values.cron }}
jobTemplate:
spec:
template:
spec:
automountServiceAccountToken: false
restartPolicy: Never
{{- with .Values.imagePullSecrets }}
imagePullSecrets:
{{- toYaml . | nindent 12 }}
{{- end }}
containers:
- name: maven-cacher
image: "{{ .Values.image.repository }}:{{ .Values.image.tag }}"
imagePullPolicy: {{ .Values.image.pullPolicy }}
{{- with .Values.containerSecurityContext }}
securityContext:
{{- toYaml . | nindent 16 }}
{{- end }}
command:
- "bash"
- "{{ .Values.scriptsDir }}/maven-cacher.sh"
env:
- name: MVN_LOCAL_REPO
value: {{ .Values.mavenLocalRepo }}
- name: MVN_CACHE_DIR
value: {{ .Values.cacheMount }}
- name: JAVA_HOME
value: {{ .Values.javaHome }}
{{- if .Values.mavenMirror.enable }}
- name: MAVEN_ARGS
value: "-s /mavensettings/settings.xml"
{{- end }}
volumeMounts:
- name: tmpdir
mountPath: /tmp
readOnly: false
- name: scripts
mountPath: {{ .Values.scriptsDir }}
readonly: true
- name: mavenrepo
mountPath: {{ .Values.mavenLocalRepo }}
readonly: false
- name: cache
mountPath: {{ .Values.cacheMount }}
readonly: false
{{- if .Values.mavenMirror.enable }}
- name: mavensettings
mountPath: /mavensettings
readonly: true
{{- end }}
workingDir: /tmp
{{- with .Values.resources }}
resources:
{{- toYaml . | nindent 16 }}
{{- end }}
{{- with .Values.nodeSelector }}
nodeSelector:
{{- toYaml . | nindent 12 }}
{{- end }}
{{- with .Values.affinity }}
affinity:
{{- toYaml . | nindent 12 }}
{{- end }}
{{- with .Values.tolerations }}
tolerations:
{{- toYaml . | nindent 12 }}
{{- end }}
volumes:
- name: tmpdir
emptyDir: {}
- name: scripts
configMap:
name: {{ include "maven-cacher.fullname" . }}-scripts
- name: mavenrepo
emptyDir: {}
- name: cache
{{- if .Values.cachePvc }}
persistentVolumeClaim:
claimName: {{ .Values.cachePvc }}
{{- else }}
emptyDir: {}
{{- end -}}
{{- if .Values.mavenMirror.enable }}
- name: mavensettings
configMap:
name: {{ include "maven-cacher.fullname" . }}-maven-settings
{{- end }}
102 changes: 102 additions & 0 deletions charts/maven-cacher/tests/custom_values_test.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
suite: default tests
templates:
- cronjob.yaml
- configmap-scripts.yaml
- configmap-maven-settings.yaml
values:
- ./values/custom.yaml
tests:
- it: should define the default "scripts" configmap
template: configmap-scripts.yaml
asserts:
- hasDocuments:
count: 1
- isKind:
of: ConfigMap
- equal:
path: metadata.name
value: RELEASE-NAME-maven-cacher-scripts
- it: should NOT define the a "maven-settings" configmap
template: configmap-maven-settings.yaml
asserts:
- hasDocuments:
count: 1
- isKind:
of: ConfigMap
- equal:
path: metadata.name
value: RELEASE-NAME-maven-cacher-maven-settings
- it: should define the default "maven-cacher" cronjob with defaults
template: cronjob.yaml
asserts:
- hasDocuments:
count: 1
- documentIndex: 0
isKind:
of: CronJob
- equal:
path: metadata.name
value: RELEASE-NAME-maven-cacher
- equal:
path: metadata.labels["app.kubernetes.io/name"]
value: "maven-cacher"
- equal:
path: metadata.labels["app.kubernetes.io/instance"]
value: "RELEASE-NAME"
- equal:
path: "spec.jobTemplate.spec.template.spec.containers[*].imagePullPolicy"
value: IfNotPresent
- equal:
path: spec.jobTemplate.spec.template.spec.volumes[0].name
value: tmpdir
- exists:
path: spec.jobTemplate.spec.template.spec.volumes[0].emptyDir
- equal:
path: spec.jobTemplate.spec.template.spec.volumes[1].name
value: scripts
- equal:
path: spec.jobTemplate.spec.template.spec.volumes[1].configMap.name
value: RELEASE-NAME-maven-cacher-scripts
- equal:
path: spec.jobTemplate.spec.template.spec.volumes[2].name
value: mavenrepo
- exists:
path: spec.jobTemplate.spec.template.spec.volumes[2].emptyDir
- equal:
path: spec.jobTemplate.spec.template.spec.volumes[3].name
value: cache
- notExists:
path: spec.jobTemplate.spec.template.spec.volumes[3].emptyDir
- equal:
path: spec.jobTemplate.spec.template.spec.volumes[4].name
value: mavensettings
- equal:
path: spec.jobTemplate.spec.template.spec.containers[0].volumeMounts[0].name
value: tmpdir
- equal:
path: spec.jobTemplate.spec.template.spec.containers[0].volumeMounts[0].readOnly
value: false
- equal:
path: spec.jobTemplate.spec.template.spec.containers[0].volumeMounts[1].name
value: scripts
- equal:
path: spec.jobTemplate.spec.template.spec.containers[0].volumeMounts[1].mountPath
value: /scripts
- equal:
path: spec.jobTemplate.spec.template.spec.containers[0].volumeMounts[1].readonly
value: true
- equal:
path: spec.jobTemplate.spec.template.spec.containers[0].volumeMounts[2].name
value: mavenrepo
- equal:
path: spec.jobTemplate.spec.template.spec.containers[0].volumeMounts[2].mountPath
value: /home/jenkins/.m2/repository
- equal:
path: spec.jobTemplate.spec.template.spec.containers[0].volumeMounts[2].readonly
value: false
- equal:
path: spec.jobTemplate.spec.template.spec.containers[0].volumeMounts[4].name
value: mavensettings
- equal:
path: spec.jobTemplate.spec.template.spec.containers[0].env[0].name
value: MVN_LOCAL_REPO
Loading