-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathJenkinsfile
73 lines (73 loc) · 3.31 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
podTemplate(
name: 'simple-api-build-pod',
label: 'simple-api-build-pod',
containers: [
containerTemplate(name: 'shell', image: 'ubuntu', command: 'sleep', args: 'infinity'),
containerTemplate(name: 'helm', image: 'alpine/helm:3.3.0', ttyEnabled: true, command: 'cat'),
containerTemplate(name: 'kubectl', image: 'bitnami/kubectl:1.18.8-debian-10-r5', command: 'sleep', args: 'infinity', runAsUser: "1000"),
containerTemplate(name: 'docker', image: 'docker:19.03.12', command: 'sleep', args: 'infinity'),
],
volumes: [hostPathVolume(hostPath: '/var/run/docker.sock', mountPath: '/var/run/docker.sock')],
{
node('simple-api-build-pod'){
withCredentials([
usernamePassword(
credentialsId: 'docker-registry-cred',
usernameVariable: 'DOCKER_REGISTRY_USER',
passwordVariable: 'DOCKER_REGISTRY_PASSWORD',
),
string(credentialsId: 'docker-registry-address', variable: 'DOCKER_REGISTRY'),
string(credentialsId: 'cluster-domain', variable: 'CLUSTER_DOMAIN'),
]) {
stage('Checkout') {
checkout scm
}
stage('Build') {
sh '''
mkdir -p builder/target
builder/tag.sh > builder/target/tag.sh
'''
container('docker') {
sh '''
. builder/target/tag.sh
docker build -t "${DOCKER_REGISTRY}/kublr/simple-api:${TAG}" simple-api
'''
}
}
stage('Release') {
container('shell') {
sh 'hostname'
sh 'uname -a'
}
container('kubectl') {
sh 'kubectl get nodes'
}
container('helm') {
sh 'helm version'
}
container('docker') {
sh '''
. builder/target/tag.sh
docker login "${DOCKER_REGISTRY}" -u "${DOCKER_REGISTRY_USER}" -p "${DOCKER_REGISTRY_PASSWORD}"
docker push "${DOCKER_REGISTRY}/kublr/simple-api:${TAG}"
'''
}
}
stage('Deploy') {
container('helm') {
sh '''
. builder/target/tag.sh
helm upgrade -i --create-namespace -n ${GIT_BRANCH_ID} simple-api simple-api/helm/simple-api \
--set image.repository="${DOCKER_REGISTRY}/kublr/simple-api" \
--set image.tag="${TAG}" \
--set ingress.enabled=true \
--set ingress.hosts[0].host=simple-api.${GIT_BRANCH_ID}.${CLUSTER_DOMAIN} \
--set ingress.hosts[0].paths[0]=/ \
--set ingress.hosts[0].paths[1]=/${GIT_BRANCH_ID}
'''
}
}
}
}
}
)