-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathJenkinsfile
More file actions
120 lines (99 loc) · 4.73 KB
/
Jenkinsfile
File metadata and controls
120 lines (99 loc) · 4.73 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
#!groovy
@Library([
'pipe-build-lib',
'ces-build-lib',
'dogu-build-lib'
]) _
import com.cloudogu.ces.cesbuildlib.K3d
import com.cloudogu.ces.cesbuildlib.Makefile
def pipe = new com.cloudogu.sos.pipebuildlib.DoguPipe(this, [
doguName : 'ldap',
shellScripts : ['''
resources/scheduled_jobs.sh
resources/send-mail-after-changed-password.sh
resources/startup.sh
resources/srv/openldap/create-sa.sh
resources/srv/openldap/remove-sa.sh
'''],
doBatsTests : true,
defaultBranch : "master"
])
def componentRegistry = "registry.cloudogu.com"
def componentRegistryNamespace = "k8s"
def componentChartTargetDir = "target/k8s/helm"
def componentBuildImageRepository = "registry.cloudogu.com/official/ldap"
def componentReleaseName = "ldap"
def buildToolsVersion = "1.26.0"
pipe.setBuildProperties()
pipe.addDefaultStages()
def runMakeInGoContainer = { target ->
new com.cloudogu.ces.cesbuildlib.Docker(this)
.image("golang:${buildToolsVersion}")
.mountJenkinsUser()
.inside("--volume ${WORKSPACE}:/workdir -w /workdir") {
sh "make ${target}"
}
}
def componentStages = { group ->
group.stage('Component Checkout') {
checkout scm
}
group.stage('Component Build') {
runMakeInGoContainer("install-yq")
docker.withRegistry('https://registry.cloudogu.com/', 'cesmarvin-setup') {
sh "make docker-build"
}
}
group.stage('Component Test') {
runMakeInGoContainer("helm-lint")
}
group.stage('Component Smoke Test (k3d)') {
K3d k3d = new K3d(this, "${WORKSPACE}", "${WORKSPACE}/k3d", env.PATH)
Makefile makefile = new Makefile(this)
String releaseVersion = makefile.getVersion().trim()
try {
echo "[Component k3d] Start cluster"
k3d.startK3d()
echo "[Component k3d] Prepare prerequisites"
k3d.kubectl("delete configmap global-config || true")
k3d.kubectl("create configmap global-config --from-literal=config.yaml='domain: \"ces.test\"'")
k3d.kubectl("delete secret ldap-admin-credentials || true")
k3d.kubectl("create secret generic ldap-admin-credentials --from-literal=password='admin'")
echo "[Component k3d] Generate helm chart"
runMakeInGoContainer("helm-generate")
echo "[Component k3d] Retag image for local smoke test"
sh "docker tag ${componentBuildImageRepository}:${releaseVersion} local-smoke/ldap:${releaseVersion}"
echo "[Component k3d] Import previously built image"
sh "sudo ${WORKSPACE}/k3d/.k3d/bin/k3d image import local-smoke/ldap:${releaseVersion} -c ${k3d.registryName}"
echo "[Component k3d] Deploy component via helm"
k3d.helm("upgrade --install ${componentReleaseName} ${componentChartTargetDir} --namespace default --set fullnameOverride=${componentReleaseName} --set image.registry=local-smoke --set image.repository=ldap --set image.tag=${releaseVersion} --set imagePullPolicy=Never --set migration.enabled=false --wait --timeout 5m")
echo "[Component k3d] Verify component startup"
k3d.kubectl("rollout status statefulset/${componentReleaseName} --timeout=300s")
k3d.kubectl("wait --for=condition=ready pod -l app.kubernetes.io/instance=${componentReleaseName} --timeout=300s")
} catch (Exception e) {
k3d.collectAndArchiveLogs()
throw e
} finally {
k3d.deleteK3d()
}
}
if (pipe.gitflow.isReleaseBranch()) {
group.stage('Push Component Chart to Harbor') {
sh "make helm-package"
def componentChartFile = sh(returnStdout: true, script: "ls -1t ${componentChartTargetDir}/*.tgz 2>/dev/null | head -n 1").trim()
if (!componentChartFile) {
error("No packaged component chart found in ${componentChartTargetDir}")
}
withCredentials([usernamePassword(credentialsId: 'harborhelmchartpush', usernameVariable: 'HARBOR_USERNAME', passwordVariable: 'HARBOR_PASSWORD')]) {
try {
sh ".bin/helm registry login ${componentRegistry} --username '${HARBOR_USERNAME}' --password '${HARBOR_PASSWORD}'"
sh ".bin/helm push ${componentChartFile} oci://${componentRegistry}/${componentRegistryNamespace}/"
} finally {
sh ".bin/helm registry logout ${componentRegistry}"
}
}
}
}
}
pipe.addStageGroup('component', pipe.agentMultinode, componentStages)
pipe.run()