-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathJenkinsfile
102 lines (94 loc) · 3.73 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
String registryEndpoint = 'registry.comp.ystv.co.uk'
def vaultConfig = [vaultUrl: 'https://vault.comp.ystv.co.uk',
vaultCredentialId: 'jenkins-vault',
engineVersion: 2]
def branch = env.BRANCH_NAME.replaceAll("/", "_")
def image
String imageName = "ystv/creator-studio:${branch}-${env.BUILD_ID}"
pipeline {
agent {
label 'docker'
}
environment {
DOCKER_BUILDKIT = '1'
}
stages {
stage('Build image') {
steps {
script {
// Checking if it is semantic version release.
String deployEnv = env.TAG_NAME ==~ /v(0|[1-9]\d*)\.(0|[1-9]\d*)\.(0|[1-9]\d*)/ ? 'prod' : 'dev'
def secrets = [
[path: "ci/ystv-creator-studio-${deployEnv}", engineVersion: 2, secretValues: [
[envVar: 'REACT_APP_DEBUG', vaultKey: 'debug'],
[envVar: 'REACT_APP_TITLE', vaultKey: 'title'],
[envVar: 'REACT_APP_SECURITY_BASEURL', vaultKey: 'auth-baseurl'],
[envVar: 'REACT_APP_SECURITY_TYPE', vaultKey: 'auth-type'],
[envVar: 'REACT_APP_PUBLIC_SITE_BASEURL', vaultKey: 'public-site-baseurl'],
[envVar: 'REACT_APP_MYTV_BASEURL', vaultKey: 'mytv-baseurl'],
[envVar: 'REACT_APP_UPLOAD_ENDPOINT', vaultKey: 'upload-endpoint'],
[envVar: 'REACT_APP_API_BASEURL', vaultKey: 'api-baseurl']
]]
]
withVault([configuration: vaultConfig, vaultSecrets: secrets]) {
docker.withRegistry('https://' + registryEndpoint, 'docker-registry') {
// sh 'env > .env.local' // this is bad
image = docker.build(imageName, """ \
--build-arg GIT_REV_ARG=${env.GIT_COMMIT} \
--build-arg BUILD_ID_ARG=${JOB_NAME}:${BUILD_ID} \
--build-arg REACT_APP_DEBUG_ARG=${REACT_APP_DEBUG} \
--build-arg REACT_APP_TITLE_ARG=${REACT_APP_TITLE} \
--build-arg REACT_APP_SECURITY_BASEURL_ARG=${REACT_APP_SECURITY_BASEURL} \
--build-arg REACT_APP_SECURITY_TYPE_ARG=${REACT_APP_SECURITY_TYPE} \
--build-arg REACT_APP_PUBLIC_SITE_BASEURL_ARG=${REACT_APP_PUBLIC_SITE_BASEURL} \
--build-arg REACT_APP_MYTV_BASEURL_ARG=${REACT_APP_MYTV_BASEURL} \
--build-arg REACT_APP_UPLOAD_ENDPOINT_ARG=${REACT_APP_UPLOAD_ENDPOINT} \
--build-arg REACT_APP_API_BASEURL_ARG=${REACT_APP_API_BASEURL} \
-f Dockerfile . \
""")
}
}
}
}
}
stage('Push image to registry') {
steps {
script {
docker.withRegistry('https://' + registryEndpoint, 'docker-registry') {
image.push()
if (env.BRANCH_IS_PRIMARY) {
image.push('latest')
}
}
}
}
}
stage('Deploy') {
stages {
stage('Development') {
when {
expression { env.BRANCH_IS_PRIMARY }
}
steps {
build(job: 'Deploy Nomad Job', parameters: [
string(name: 'JOB_FILE', value: 'creator-studio-dev.nomad'),
text(name: 'TAG_REPLACEMENTS', value: "${registryEndpoint}/${imageName}")
])
}
}
stage('Production') {
when {
// Checking if it is semantic version release.
expression { return env.TAG_NAME ==~ /v(0|[1-9]\d*)\.(0|[1-9]\d*)\.(0|[1-9]\d*)/ }
}
steps {
build(job: 'Deploy Nomad Job', parameters: [
string(name: 'JOB_FILE', value: 'creator-studio-prod.nomad'),
text(name: 'TAG_REPLACEMENTS', value: "${registryEndpoint}/${imageName}")
])
}
}
}
}
}
}