forked from ONSdigital/dp-map-renderer
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathJenkinsfile
More file actions
62 lines (52 loc) · 2.27 KB
/
Jenkinsfile
File metadata and controls
62 lines (52 loc) · 2.27 KB
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
#!groovy
node {
def gopath = pwd()
ws("${gopath}/src/github.com/ONSdigital/dp-map-renderer") {
stage('Checkout') {
checkout scm
sh 'git clean -dfx'
sh 'git rev-parse --short HEAD > git-commit'
sh 'set +e && (git describe --exact-match HEAD || true) > git-tag'
}
def branch = env.JOB_NAME.replaceFirst('.+/', '')
def revision = revisionFrom(readFile('git-tag').trim(), readFile('git-commit').trim())
stage('Build') {
sh "GOPATH=${gopath} BIN_DIR=build make build"
}
stage('Test') {
sh "GOPATH=${gopath} make test"
}
stage('Image') {
docker.withRegistry("https://${env.ECR_REPOSITORY_URI}", { ->
docker.build('dp-map-renderer', '--no-cache --pull --rm .').push(revision)
})
}
stage('Bundle') {
sh sprintf('sed -i -e %s -e %s -e %s -e %s -e %s appspec.yml scripts/codedeploy/*', [
"s/\\\${CODEDEPLOY_USER}/${env.CODEDEPLOY_USER}/g",
"s/^CONFIG_BUCKET=.*/CONFIG_BUCKET=${env.S3_CONFIGURATIONS_BUCKET}/",
"s/^ECR_REPOSITORY_URI=.*/ECR_REPOSITORY_URI=${env.ECR_REPOSITORY_URI}/",
"s/^GIT_COMMIT=.*/GIT_COMMIT=${revision}/",
"s/^AWS_REGION=.*/AWS_REGION=${env.AWS_DEFAULT_REGION}/",
])
sh "tar -cvzf dp-map-renderer-${revision}.tar.gz appspec.yml scripts/codedeploy"
sh "aws s3 cp dp-map-renderer-${revision}.tar.gz s3://${env.S3_REVISIONS_BUCKET}/"
}
if (branch != 'develop') return
stage('Deploy') {
for (group in [env.CODEDEPLOY_FRONTEND_DEPLOYMENT_GROUP, env.CODEDEPLOY_PUBLISHING_DEPLOYMENT_GROUP]) {
sh sprintf('aws deploy create-deployment %s %s %s,bundleType=tgz,key=%s', [
"--application-name dp-map-renderer",
"--deployment-group-name ${group}",
"--s3-location bucket=${env.S3_REVISIONS_BUCKET}",
"dp-map-renderer-${revision}.tar.gz",
])
}
}
}
}
@NonCPS
def revisionFrom(tag, commit) {
def matcher = (tag =~ /^release\/(\d+\.\d+\.\d+(?:-rc\d+)?)$/)
matcher.matches() ? matcher[0][1] : commit
}