-
Notifications
You must be signed in to change notification settings - Fork 12
/
Jenkinsfile
59 lines (56 loc) · 2.36 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
podTemplate(label: 'app-builder', containers: [
containerTemplate(name: 'docker', image: 'docker', ttyEnabled: true, command: 'cat', envVars: [
envVar(key: 'DOCKER_HOST', value: 'tcp://docker-host-docker-host:2375')
])
]) {
node('app-builder') {
stage('Run Tests') {
container('docker') {
def scmVars = checkout scm
def gitHead = scmVars.GIT_COMMIT.substring(0,7)
sh "docker build --target dev -t app-frontend-test:${scmVars.GIT_COMMIT}-${env.BUILD_ID}-${env.CHANGE_ID} ."
try {
sh "docker run --rm -t app-frontend-test:${scmVars.GIT_COMMIT}-${env.BUILD_ID}-${env.CHANGE_ID} npm run test"
} finally {
}
if (env.BRANCH_NAME == "master") {
withCredentials([
string(
credentialsId: 'SECRET_KEY_BASE',
variable: 'SECRET_KEY_BASE'
),
string(
credentialsId: 'aws_account_id',
variable: 'aws_account_id'
)
]) {
def awsRegistry = "${env.aws_account_id}.dkr.ecr.eu-central-1.amazonaws.com"
docker.withRegistry("https://${awsRegistry}", "ecr:eu-central-1:ecr-credentials") {
sh "docker build --target prod -t ${awsRegistry}/app:${env.BRANCH_NAME} -t ${awsRegistry}/app:${scmVars.GIT_COMMIT} --build-arg SECRET_KEY_BASE=${env.SECRET_KEY_BASE} --build-arg GIT_HEAD=${gitHead} ."
sh "docker push ${awsRegistry}/app:${env.BRANCH_NAME}"
sh "docker push ${awsRegistry}/app:${scmVars.GIT_COMMIT}"
}
}
}
if (env.BRANCH_NAME == "production") {
withCredentials([
string(
credentialsId: 'SECRET_KEY_BASE',
variable: 'SECRET_KEY_BASE'
),
string(
credentialsId: 'aws_account_id',
variable: 'aws_account_id'
)
]) {
def awsRegistry = "${env.aws_account_id}.dkr.ecr.eu-central-1.amazonaws.com"
docker.withRegistry("https://${awsRegistry}", "ecr:eu-central-1:ecr-credentials") {
sh "docker build --target prod -t ${awsRegistry}/app:${env.BRANCH_NAME}-build --build-arg SECRET_KEY_BASE=${env.SECRET_KEY_BASE} --build-arg GIT_HEAD=${gitHead} ."
sh "docker push ${awsRegistry}/app:${env.BRANCH_NAME}-build"
}
}
}
}
}
}
}