-
Notifications
You must be signed in to change notification settings - Fork 0
/
Jenkinsfile
98 lines (86 loc) · 2.42 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
pipeline {
agent any
tools {
'org.jenkinsci.plugins.docker.commons.tools.DockerTool' 'docker'
}
environment {
AWS_ACCESS_KEY_ID = credentials("jenkins-aws-secret-key-id")
AWS_SECRET_ACCESS_KEY = credentials("jenkins-aws-secret-access-key")
AWS_REGION = "eu-west-1"
AWS_DEFAULT_REGION = "eu-west-1"
}
stages {
stage("Generate secret templated files") {
agent {
dockerfile {
filename 'Dockerfile.vault'
}
}
environment {
VAULT_TOKEN = credentials("VAULT_TOKEN")
}
steps {
sh '''
set +x
./generate-templates.sh
'''
}
}
stage("Build") {
agent {
dockerfile {
filename 'Dockerfile.build'
}
}
steps {
sh "npm ci"
sh "npm run build"
}
}
stage("Test") {
environment {
REDIS_HOST = "redis"
DB_NAME = "postgres"
DB_HOST = "postgres"
DB_PASSWORD = "password"
DB_USERNAME = "postgres"
NODE_ENV = "test"
VAULT_TOKEN = credentials("VAULT_TOKEN")
}
steps {
script {
docker.build("telephone-rose-vault:${env.BUILD_ID}", "-f Dockerfile.vault ./").inside() {
sh '''
set +x
./generate-templates.sh
'''
}
docker.image("mdillon/postgis").withRun("-e POSTGRES_PASSWORD=${env.DB_PASSWORD} -e POSTGRES_USER=${env.DB_USERNAME} -e POSTGRES_DB=${env.DB_NAME}") { pgContainer ->
docker.image('postgres').inside("--link ${pgContainer.id}:pg") {
/* Wait until mysql service is up */
sh "while ! psql postgres://${env.DB_USERNAME}:${env.DB_PASSWORD}@pg/${env.DB_NAME} -c \"select 1\"; do sleep 1; done"
}
docker.image("redis").withRun("") { redisContainer ->
docker.build("telephone-rose-test:${env.BUILD_ID}", "-f Dockerfile.test ./").inside("--link ${pgContainer.id}:postgres --link ${redisContainer.id}:redis") {
sh "npm ci"
sh "npm run lint"
sh "npm test"
}
}
}
}
}
}
stage("Deploy production") {
when { branch "master" }
agent {
dockerfile {
filename 'Dockerfile.build'
}
}
steps {
sh "npm run deploy"
}
}
}
}