Skip to content

Commit f8b96ea

Browse files
authored
Merge pull request #1608 from dduportal/feat/maven-cacher
feat: init the maven-cacher chart
2 parents fceba6c + 39fc1f2 commit f8b96ea

File tree

9 files changed

+523
-0
lines changed

9 files changed

+523
-0
lines changed

charts/maven-cacher/Chart.yaml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
apiVersion: v1
2+
description: Maven Cache updater for the *.jenkins.io controllers
3+
name: maven-cacher
4+
version: 0.0.1
5+
maintainers:
6+
- email: jenkins-infra-team@googlegroups.com
7+
name: jenkins-infra-team
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
{{/* vim: set filetype=mustache: */}}
2+
{{/*
3+
Expand the name of the chart.
4+
*/}}
5+
{{- define "maven-cacher.name" -}}
6+
{{- default .Chart.Name .Values.nameOverride | trunc 63 | trimSuffix "-" -}}
7+
{{- end -}}
8+
9+
{{/*
10+
Create a default fully qualified app name.
11+
We truncate at 63 chars because some Kubernetes name fields are limited to this (by the DNS naming spec).
12+
If release name contains chart name it will be used as a full name.
13+
*/}}
14+
{{- define "maven-cacher.fullname" -}}
15+
{{- if .Values.fullnameOverride -}}
16+
{{- .Values.fullnameOverride | trunc 63 | trimSuffix "-" -}}
17+
{{- else -}}
18+
{{- $name := default .Chart.Name .Values.nameOverride -}}
19+
{{- if contains $name .Release.Name -}}
20+
{{- .Release.Name | trunc 63 | trimSuffix "-" -}}
21+
{{- else -}}
22+
{{- printf "%s-%s" .Release.Name $name | trunc 63 | trimSuffix "-" -}}
23+
{{- end -}}
24+
{{- end -}}
25+
{{- end -}}
26+
27+
{{/*
28+
Selector labels
29+
*/}}
30+
{{- define "maven-cacher.selectorLabels" -}}
31+
app.kubernetes.io/name: maven-cacher
32+
app.kubernetes.io/instance: {{ .Release.Name }}
33+
{{- end }}
34+
35+
{{/*
36+
Create chart name and version as used by the chart label.
37+
*/}}
38+
{{- define "maven-cacher.chart" -}}
39+
{{- printf "%s-%s" .Chart.Name .Chart.Version | replace "+" "_" | trunc 63 | trimSuffix "-" -}}
40+
{{- end -}}
41+
42+
{{/*
43+
Common labels
44+
*/}}
45+
{{- define "maven-cacher.labels" -}}
46+
{{ include "maven-cacher.selectorLabels" . }}
47+
helm.sh/chart: {{ include "maven-cacher.chart" . }}
48+
{{- end -}}
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
{{- if .Values.mavenMirror.enable }}
2+
---
3+
apiVersion: v1
4+
kind: ConfigMap
5+
metadata:
6+
name: {{ include "maven-cacher.fullname" . }}-maven-settings
7+
labels: {{ include "maven-cacher.labels" . | nindent 4 }}
8+
data:
9+
settings.xml: |
10+
<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">
11+
<mirrors>
12+
<mirror>
13+
<id>{{ .Values.mavenMirror.mirrorId }}</id>
14+
<url>{{ .Values.mavenMirror.url }}</url>
15+
<mirrorOf>{{ .Values.mavenMirror.mirrorOf }}</mirrorOf>
16+
</mirror>
17+
</mirrors>
18+
<profiles>
19+
<profile>
20+
<id>jenkins-infra-plugin-repositories</id>
21+
<pluginRepositories>
22+
<pluginRepository>
23+
<id>repo.jenkins-ci.org</id>
24+
<url>https://repo.jenkins-ci.org/public/</url>
25+
</pluginRepository>
26+
<pluginRepository>
27+
<snapshots>
28+
<enabled>false</enabled>
29+
</snapshots>
30+
<id>incrementals</id>
31+
<url>https://repo.jenkins-ci.org/incrementals/</url>
32+
</pluginRepository>
33+
<pluginRepository>
34+
<id>central</id>
35+
<url>https://repo.maven.apache.org/maven2</url>
36+
</pluginRepository>
37+
</pluginRepositories>
38+
</profile>
39+
</profiles>
40+
<activeProfiles>
41+
<activeProfile>jenkins-infra-plugin-repositories</activeProfile>
42+
</activeProfiles>
43+
</settings>
44+
{{- end }}
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
apiVersion: v1
2+
kind: ConfigMap
3+
metadata:
4+
name: {{ include "maven-cacher.fullname" . }}-scripts
5+
labels: {{ include "maven-cacher.labels" . | nindent 4 }}
6+
data:
7+
maven-cacher.sh: |
8+
#!/bin/bash
9+
10+
set -eux -o pipefail
11+
12+
mvn_cache_dir="${MVN_CACHE_DIR:-"/tmp"}"
13+
test -d "${mvn_cache_dir}"
14+
mvn_local_repo="${MVN_LOCAL_REPO:-"${HOME}/.m2/repository"}"
15+
mvn_cache_archive="${mvn_cache_dir}/maven-bom-local-repo.tar.gz"
16+
17+
# Set up local working directory with BOM code
18+
test -d ./bom || git clone https://github.com/jenkinsci/bom
19+
pushd ./bom
20+
21+
# TODO: Retrieve this list from Maven
22+
build_lines=("weekly" "2.479.x" "2.492.x")
23+
24+
# Load dependencies in the local Maven repo
25+
for build_line in "${build_lines[@]}"; do
26+
MVN_OPTS=()
27+
if [[ $build_line != "weekly" ]]; then
28+
MVN_OPTS+=("-P $build_line")
29+
fi
30+
time mvn -pl sample-plugin\
31+
dependency:go-offline \
32+
-DincludeScore=runtime,compile,test \
33+
-Dmaven.repo.local="{{ .Values.mavenLocalRepo }}" \
34+
"${MVN_OPTS[@]}"
35+
done
36+
37+
# Generate a new cache archive from the local Maven repository
38+
pushd "${mvn_local_repo}"
39+
df -h .
40+
du -sh .
41+
time tar czf /tmp/maven-bom-local-repo.tar.gz ./
42+
time cp /tmp/maven-bom-local-repo.tar.gz "${mvn_cache_archive}"
43+
du -sh "${mvn_cache_dir}"/*
Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
1+
---
2+
apiVersion: batch/v1
3+
kind: CronJob
4+
metadata:
5+
name: {{ include "maven-cacher.fullname" . }}
6+
labels:
7+
{{ include "maven-cacher.labels" . | indent 4 }}
8+
spec:
9+
concurrencyPolicy: Forbid
10+
schedule: {{ .Values.cron }}
11+
jobTemplate:
12+
spec:
13+
template:
14+
spec:
15+
automountServiceAccountToken: false
16+
restartPolicy: Never
17+
{{- with .Values.imagePullSecrets }}
18+
imagePullSecrets:
19+
{{- toYaml . | nindent 12 }}
20+
{{- end }}
21+
containers:
22+
- name: maven-cacher
23+
image: "{{ .Values.image.repository }}:{{ .Values.image.tag }}"
24+
imagePullPolicy: {{ .Values.image.pullPolicy }}
25+
{{- with .Values.containerSecurityContext }}
26+
securityContext:
27+
{{- toYaml . | nindent 16 }}
28+
{{- end }}
29+
command:
30+
- "bash"
31+
- "{{ .Values.scriptsDir }}/maven-cacher.sh"
32+
env:
33+
- name: MVN_LOCAL_REPO
34+
value: {{ .Values.mavenLocalRepo }}
35+
- name: MVN_CACHE_DIR
36+
value: {{ .Values.cacheMount }}
37+
- name: JAVA_HOME
38+
value: {{ .Values.javaHome }}
39+
{{- if .Values.mavenMirror.enable }}
40+
- name: MAVEN_ARGS
41+
value: "-s /mavensettings/settings.xml"
42+
{{- end }}
43+
volumeMounts:
44+
- name: tmpdir
45+
mountPath: /tmp
46+
readOnly: false
47+
- name: scripts
48+
mountPath: {{ .Values.scriptsDir }}
49+
readonly: true
50+
- name: mavenrepo
51+
mountPath: {{ .Values.mavenLocalRepo }}
52+
readonly: false
53+
- name: cache
54+
mountPath: {{ .Values.cacheMount }}
55+
readonly: false
56+
{{- if .Values.mavenMirror.enable }}
57+
- name: mavensettings
58+
mountPath: /mavensettings
59+
readonly: true
60+
{{- end }}
61+
workingDir: /tmp
62+
{{- with .Values.resources }}
63+
resources:
64+
{{- toYaml . | nindent 16 }}
65+
{{- end }}
66+
{{- with .Values.nodeSelector }}
67+
nodeSelector:
68+
{{- toYaml . | nindent 12 }}
69+
{{- end }}
70+
{{- with .Values.affinity }}
71+
affinity:
72+
{{- toYaml . | nindent 12 }}
73+
{{- end }}
74+
{{- with .Values.tolerations }}
75+
tolerations:
76+
{{- toYaml . | nindent 12 }}
77+
{{- end }}
78+
volumes:
79+
- name: tmpdir
80+
emptyDir: {}
81+
- name: scripts
82+
configMap:
83+
name: {{ include "maven-cacher.fullname" . }}-scripts
84+
- name: mavenrepo
85+
emptyDir: {}
86+
- name: cache
87+
{{- if .Values.cachePvc }}
88+
persistentVolumeClaim:
89+
claimName: {{ .Values.cachePvc }}
90+
{{- else }}
91+
emptyDir: {}
92+
{{- end -}}
93+
{{- if .Values.mavenMirror.enable }}
94+
- name: mavensettings
95+
configMap:
96+
name: {{ include "maven-cacher.fullname" . }}-maven-settings
97+
{{- end }}
Lines changed: 102 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,102 @@
1+
suite: default tests
2+
templates:
3+
- cronjob.yaml
4+
- configmap-scripts.yaml
5+
- configmap-maven-settings.yaml
6+
values:
7+
- ./values/custom.yaml
8+
tests:
9+
- it: should define the default "scripts" configmap
10+
template: configmap-scripts.yaml
11+
asserts:
12+
- hasDocuments:
13+
count: 1
14+
- isKind:
15+
of: ConfigMap
16+
- equal:
17+
path: metadata.name
18+
value: RELEASE-NAME-maven-cacher-scripts
19+
- it: should NOT define the a "maven-settings" configmap
20+
template: configmap-maven-settings.yaml
21+
asserts:
22+
- hasDocuments:
23+
count: 1
24+
- isKind:
25+
of: ConfigMap
26+
- equal:
27+
path: metadata.name
28+
value: RELEASE-NAME-maven-cacher-maven-settings
29+
- it: should define the default "maven-cacher" cronjob with defaults
30+
template: cronjob.yaml
31+
asserts:
32+
- hasDocuments:
33+
count: 1
34+
- documentIndex: 0
35+
isKind:
36+
of: CronJob
37+
- equal:
38+
path: metadata.name
39+
value: RELEASE-NAME-maven-cacher
40+
- equal:
41+
path: metadata.labels["app.kubernetes.io/name"]
42+
value: "maven-cacher"
43+
- equal:
44+
path: metadata.labels["app.kubernetes.io/instance"]
45+
value: "RELEASE-NAME"
46+
- equal:
47+
path: "spec.jobTemplate.spec.template.spec.containers[*].imagePullPolicy"
48+
value: IfNotPresent
49+
- equal:
50+
path: spec.jobTemplate.spec.template.spec.volumes[0].name
51+
value: tmpdir
52+
- exists:
53+
path: spec.jobTemplate.spec.template.spec.volumes[0].emptyDir
54+
- equal:
55+
path: spec.jobTemplate.spec.template.spec.volumes[1].name
56+
value: scripts
57+
- equal:
58+
path: spec.jobTemplate.spec.template.spec.volumes[1].configMap.name
59+
value: RELEASE-NAME-maven-cacher-scripts
60+
- equal:
61+
path: spec.jobTemplate.spec.template.spec.volumes[2].name
62+
value: mavenrepo
63+
- exists:
64+
path: spec.jobTemplate.spec.template.spec.volumes[2].emptyDir
65+
- equal:
66+
path: spec.jobTemplate.spec.template.spec.volumes[3].name
67+
value: cache
68+
- notExists:
69+
path: spec.jobTemplate.spec.template.spec.volumes[3].emptyDir
70+
- equal:
71+
path: spec.jobTemplate.spec.template.spec.volumes[4].name
72+
value: mavensettings
73+
- equal:
74+
path: spec.jobTemplate.spec.template.spec.containers[0].volumeMounts[0].name
75+
value: tmpdir
76+
- equal:
77+
path: spec.jobTemplate.spec.template.spec.containers[0].volumeMounts[0].readOnly
78+
value: false
79+
- equal:
80+
path: spec.jobTemplate.spec.template.spec.containers[0].volumeMounts[1].name
81+
value: scripts
82+
- equal:
83+
path: spec.jobTemplate.spec.template.spec.containers[0].volumeMounts[1].mountPath
84+
value: /scripts
85+
- equal:
86+
path: spec.jobTemplate.spec.template.spec.containers[0].volumeMounts[1].readonly
87+
value: true
88+
- equal:
89+
path: spec.jobTemplate.spec.template.spec.containers[0].volumeMounts[2].name
90+
value: mavenrepo
91+
- equal:
92+
path: spec.jobTemplate.spec.template.spec.containers[0].volumeMounts[2].mountPath
93+
value: /home/jenkins/.m2/repository
94+
- equal:
95+
path: spec.jobTemplate.spec.template.spec.containers[0].volumeMounts[2].readonly
96+
value: false
97+
- equal:
98+
path: spec.jobTemplate.spec.template.spec.containers[0].volumeMounts[4].name
99+
value: mavensettings
100+
- equal:
101+
path: spec.jobTemplate.spec.template.spec.containers[0].env[0].name
102+
value: MVN_LOCAL_REPO

0 commit comments

Comments
 (0)