-
Notifications
You must be signed in to change notification settings - Fork 0
/
Jenkinsfile
120 lines (101 loc) · 4.72 KB
/
Jenkinsfile
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('github.com/cloudogu/[email protected]')
import com.cloudogu.ces.cesbuildlib.*
git = new Git(this, "cesmarvin")
git.committerName = 'cesmarvin'
git.committerEmail = '[email protected]'
gitflow = new GitFlow(this, git)
github = new GitHub(this, git)
changelog = new Changelog(this)
repositoryName = "k8s-loki"
productionReleaseBranch = "main"
registryNamespace = "k8s"
registryUrl = "registry.cloudogu.com"
goVersion = "1.23"
helmTargetDir = "target/k8s"
helmChartDir = "${helmTargetDir}/helm"
node('docker') {
timestamps {
catchError {
timeout(activity: false, time: 60, unit: 'MINUTES') {
stage('Checkout') {
checkout scm
make 'clean'
}
new Docker(this)
.image("golang:${goVersion}")
.mountJenkinsUser()
.inside("--volume ${WORKSPACE}:/${repositoryName} -w /${repositoryName}")
{
stage('Generate k8s Resources') {
make 'helm-update-dependencies'
make 'helm-generate'
archiveArtifacts "${helmTargetDir}/**/*"
}
stage("Lint helm") {
make 'helm-lint'
}
}
K3d k3d = new K3d(this, "${WORKSPACE}", "${WORKSPACE}/k3d", env.PATH)
try {
stage('Set up k3d cluster') {
k3d.startK3d()
}
stage('Deploy minio') {
withCredentials([[$class: 'UsernamePasswordMultiBinding', credentialsId: 'harborhelmchartpush', usernameVariable: 'HARBOR_USERNAME', passwordVariable: 'HARBOR_PASSWORD']]) {
k3d.helm("registry login ${registryUrl} --username '${HARBOR_USERNAME}' --password '${HARBOR_PASSWORD}'")
k3d.helm("install k8s-minio oci://${registryUrl}/${registryNamespace}/k8s-minio --version 2023.9.23-6")
}
}
stage('Deploy k8s-loki') {
k3d.helm("install ${repositoryName} ${helmChartDir}")
}
stage('Test k8s-loki') {
// Sleep because it takes time for the controller to create the resource. Without it would end up
// in error "no matching resource found when run the wait command"
sleep(20)
k3d.kubectl("wait --for=condition=ready pod -l app.kubernetes.io/instance=k8s-loki --timeout=300s")
}
} catch(Exception e) {
k3d.collectAndArchiveLogs()
throw e as java.lang.Throwable
} finally {
stage('Remove k3d cluster') {
k3d.deleteK3d()
}
}
}
}
stageAutomaticRelease()
}
}
void stageAutomaticRelease() {
if (gitflow.isReleaseBranch()) {
Makefile makefile = new Makefile(this)
String releaseVersion = makefile.getVersion()
String changelogVersion = git.getSimpleBranchName()
stage('Push Helm chart to Harbor') {
new Docker(this)
.image("golang:${goVersion}")
.mountJenkinsUser()
.inside("--volume ${WORKSPACE}:/${repositoryName} -w /${repositoryName}")
{
make 'helm-package'
archiveArtifacts "${helmTargetDir}/**/*"
withCredentials([[$class: 'UsernamePasswordMultiBinding', credentialsId: 'harborhelmchartpush', usernameVariable: 'HARBOR_USERNAME', passwordVariable: 'HARBOR_PASSWORD']]) {
sh ".bin/helm registry login ${registryUrl} --username '${HARBOR_USERNAME}' --password '${HARBOR_PASSWORD}'"
sh ".bin/helm push ${helmChartDir}/${repositoryName}-${releaseVersion}.tgz oci://${registryUrl}/${registryNamespace}"
}
}
}
stage('Finish Release') {
gitflow.finishRelease(changelogVersion, productionReleaseBranch)
}
stage('Add Github-Release') {
releaseId = github.createReleaseWithChangelog(changelogVersion, changelog, productionReleaseBranch)
}
}
}
void make(String makeArgs) {
sh "make ${makeArgs}"
}