-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathJenkinsfile
68 lines (58 loc) · 3.32 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
#!groovy
node('') {
def gitCommitId = null // filled in Compile & test stage
def buildTimestamp = null
// locationserviceworkshop must match a valid docker hub account
def dockerImageId = "locationserviceworkshop/location-service"
def mavenImage = docker.image('maven:3.5.2-jdk-8')
def postgresImage = docker.image('postgres:9.6')
def locationServiceImage = null
stage('compile & unit-test') {
gitCommitId = checkout(scm).GIT_COMMIT.substring(0, 7)
// Workaround to shut up stupid script security, would've rather used: ZonedDateTime.now(ZoneOffset.UTC).toString()
buildTimestamp = sh(script: 'date -u +%Y-%m-%dT%H:%M:%S%Z | head -c 22', returnStdout: true)
dir('location-service') {
mavenImage.inside("--entrypoint=''") {
// disable the entrypoint in the maven container, we run our own command
sh "mvn clean verify"
}
junit '**/target/surefire-reports/*.xml'
}
}
stage('build docker image') {
locationServiceImage = docker.build "${dockerImageId}:${gitCommitId}", "--build-arg git_commit_id=${gitCommitId} --build-arg build_timestamp=${buildTimestamp} -f location-service/Dockerfile location-service"
}
stage('system tests') {
postgresImage.withRun("-e POSTGRES_DATABASE=locationservice " +
" -e POSTGRES_USER=locationservice " +
" -e POSTGRES_PASSWORD=locationservice") { db ->
locationServiceImage.withRun("--link ${db.id}:db" +
" -e DB_URL=jdbc:postgresql://db/locationservice") { service ->
// --link adds an entry into the /etc/hosts file and maps *db* to the IP address of the postgres container
mavenImage.inside("--link ${service.id}:service" +
" -e LOCATION_SERVICE_ADDRESS=service:8080" +
" --entrypoint='' ") {
// --link adds an entry into the /etc/hosts file and maps *service* to the IP address of the postgres container
sh "cd location-service-system-test && mvn clean verify"
}
}
}
junit '**/target/surefire-reports/*.xml'
}
if (env.BRANCH_NAME == 'master') {
stage('push image to docker hub') {
locationServiceImage.push()
// also tag and push as latest. so we have an easy handle on the latest produced image
locationServiceImage.push("latest")
}
stage('deploy to accept') {
workspace = pwd()
// the repo in /home/ubuntu has be configured with Amazon EC2 access keys, therefore we use this path here
// normally this is stored in a separate repository called /platform, to which all deploy scripts have access.
// eval \$(ssh-agent -s) && ssh-add are required to configure the ssh agent and add the ~jenkins/.ssh/id_rsa identity,
// this identiy is automatically configured by our provisioning scripts to give Jenkins access.
sh "eval \$(ssh-agent -s) && ssh-add ~jenkins/.ssh/workshop_ansiblecc_key && " +
" ansible-playbook -i /home/ubuntu/location-service-workshop/aws/ansible/staging -e service_version=${gitCommitId} location-service-deployment/deploy-app-with-database.yml"
}
}
}