forked from mariusv/opentaxii-k8s
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Jenkinsfile
107 lines (89 loc) · 3.28 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
#!/usr/bin/groovy
/*
Pipeline to deploy opentaxii to Kubernetes cluster using Helm packages (CI/CDish)
1. definition of pod template ( docker, helm)
2. clone the source code
3. build packages
4. build dockerimage
5. build helm chart
6. push image and chart to artifactory
7. deploy on k8s cluster
TODO:
added tests here
*/
//this has to change <--
def tag_image (branch){
if (branch.contains("master")){
tag = "latest"
version = "0.0.0-latest"
} else {
tag = branch.minus("release-")
version = tag
}
return [tag, version]
}
def label = "pod_Build_${BUILD_NUMBER}"
podTemplate(label: label, containers: [
containerTemplate(name: 'docker', image: 'docker:latest', command: 'cat', ttyEnabled: true),
containerTemplate(name: 'helm', image: "lachlanevenson/k8s-helm:${params.HELM_VERSION}", command: 'cat', ttyEnabled: true)
],
volumes: [
hostPathVolume(mountPath: '/var/run/docker.sock', hostPath: '/var/run/docker.sock')
]) {
properties(
[
parameters(
[ string(name: 'HELM_VERSION', description: 'Version of helm docker image', defaultValue: "")])]
)
node(label) {
def PACKAGE = "opentaxii"
def ARTIFACTORY_URL = "artifactory.app.eiq.sh"
stage('Create packages') {
container('docker') {
sh "apk add --update make"
def repo = git url: "https://github.com/eclecticiq/opentaxii-k8s.git", branch: 'master', credentialsId: 'f886c899-82f1-4f2f-9837-d50d4fa423c7'
def branch = repo.GIT_BRANCH
def version, tag = tag_image (branch)
stash name: "git-source"
//sh "make build-packages IMAGE_TAG=${version} version=${version} ITERATION=1"
//archiveArtifacts(artifacts: 'dist/*', fingerprint: true)
}
}
stage('Docker image') {
withCredentials([usernamePassword(credentialsId: '63b8cd21-edfc-4ba0-ba4d-f733b625bb68',
passwordVariable: 'password',
usernameVariable: 'username')]) {
container('docker') {
sh """
docker login -u ${username} -p ${password} ${ARTIFACTORY_URL}
docker build -t artifactory.app.eiq.sh/docker/eiq-opentaxii:${tag} .
docker push ${ARTIFACTORY_URL}/docker/eiq-opentaxii:${tag}
"""
}
}
}
stage ('Helm chart') {
withCredentials([usernamePassword(credentialsId: '63b8cd21-edfc-4ba0-ba4d-f733b625bb68',
passwordVariable: 'password',
usernameVariable: 'username')]) {
container('helm') {
unstash "git-source"
sh "apk add --update curl"
sh """
helm init
helm repo update
helm repo add helm https://${ARTIFACTORY_URL}/artifactory/helm --username ${username} --password ${password}
cd helm/opentaxii ; helm template --set image.tag=${tag} -f Chart.yaml -f values.yaml .
pwd ; helm package --version ${version} .
curl -u${username}:${password} -T ${PACKAGE}-${version}.tgz https://${ARTIFACTORY_URL}/artifactory/helm/${PACKAGE}-${version}.tgz
"""
}
}
}
stage ('Deploy chart on k8s'){
container ('helm'){
sh " cd helm/opentaxii ; helm upgrade --set image.tag=${tag} --install ${PACKAGE}-release ./${PACKAGE}-${version}.tgz"
}
}
}//node
}