-
Notifications
You must be signed in to change notification settings - Fork 0
/
Jenkinsfile
130 lines (128 loc) · 3.92 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
121
122
123
124
125
126
127
128
129
130
pipeline {
agent {
kubernetes {
label 'wordsmith-api'
yaml """
spec:
containers:
- name: jnlp
- name: jdk
image: openjdk:8-jdk
command:
- cat
tty: true
- name: docker
image: docker:stable-dind
command:
- cat
tty: true
volumeMounts:
- mountPath: /var/run/docker.sock
name: docker-sock
- name: helm
image: devth/helm:v2.10.0
command:
- cat
tty: true
- name: kubectl
image: lachlanevenson/k8s-kubectl:v1.10.7
command:
- cat
tty: true
- name: curl
image: appropriate/curl
command:
- cat
tty: true
volumes:
- name: docker-sock
hostPath:
path: /var/run/docker.sock
type: File
"""
}
}
options {
buildDiscarder(logRotator(numToKeepStr: '5'))
disableConcurrentBuilds()
}
stages {
stage('Build Java App') {
environment {
SONAR_CREDS = credentials('sonar')
}
steps {
container('jdk') {
withMaven(mavenOpts: '-Dorg.slf4j.simpleLogger.log.org.apache.maven.cli.transfer.Slf4jMavenTransferListener=warn') {
sh './mvnw clean verify sonar:sonar deploy -Dsonar.login=${SONAR_CREDS_USR} -Dsonar.password=${SONAR_CREDS_PSW}'
}
}
}
}
stage('Build Docker Image') {
environment {
DOCKER_HUB_CREDS = credentials('hub.docker.com')
}
steps {
container('docker') {
script {
APPLICATION_VERSION = readFile("target/VERSION")
}
sh """
docker login --username ${DOCKER_HUB_CREDS_USR} --password ${DOCKER_HUB_CREDS_PSW}
docker build -t ${DOCKER_HUB_CREDS_USR}/wordsmith-api:${APPLICATION_VERSION} .
docker push ${DOCKER_HUB_CREDS_USR}/wordsmith-api:${APPLICATION_VERSION}
"""
}
}
}
stage('Build Helm Chart') {
steps {
container('helm') {
script {
APPLICATION_VERSION = readFile("target/VERSION")
}
sh """
# create helm chart version
helm package target/charts/wordsmith-api
# upload helm chart
curl --data-binary "@wordsmith-api-${APPLICATION_VERSION}.tgz" http://chartmuseum-chartmuseum.core.svc.cluster.local:8080/api/charts
"""
archiveArtifacts artifacts: "wordsmith-api-${APPLICATION_VERSION}.tgz", fingerprint: true
}
}
}
stage('Deploy to Preview Environment') {
environment {
PG_SQL_CREDS = credentials('postgresql.preview')
PG_SQL_JDBC_URL = 'jdbc:postgresql://wordsmith-preview.ca3tifbqfpuf.us-east-1.rds.amazonaws.com:5432/wordsmith'
APP_HOST = 'api.preview.wordsmith.beescloud.com'
}
steps {
container('helm') {
script {
APPLICATION_VERSION = readFile("target/VERSION")
}
sh """
helm init --client-only
helm repo add wordsmith http://chartmuseum-chartmuseum.core.svc.cluster.local:8080
helm repo update
helm upgrade wordsmith-api-preview wordsmith/wordsmith-api --version ${APPLICATION_VERSION} --install --force --namespace preview --wait \
--set ingress.hosts[0]=${APP_HOST},database.username=${PG_SQL_CREDS_USR},database.password=${PG_SQL_CREDS_PSW},database.url=${PG_SQL_JDBC_URL},image.pullPolicy=Always
"""
} // container
container('kubectl') {
sh """
kubectl describe deployment wordsmith-api-preview-wordsmith-api --namespace preview
kubectl get ingress wordsmith-api-preview-wordsmith-api --namespace preview
"""
} // container
container('curl') {
sh """
curl -v https://api.preview.wordsmith.beescloud.com/actuator/health
"""
} // container
} // steps
} // stage
} // stages
}