-
Notifications
You must be signed in to change notification settings - Fork 21
/
Jenkinsfile
74 lines (66 loc) · 2.59 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
@Library('podTemplateLib')
import net.santiment.utils.podTemplates
properties([
buildDiscarder(
logRotator(artifactDaysToKeepStr: '30',
artifactNumToKeepStr: '',
daysToKeepStr: '30',
numToKeepStr: ''))
])
slaveTemplates = new podTemplates()
slaveTemplates.dockerTemplate { label ->
node(label) {
stage('Run Tests') {
container('docker') {
def scmVars = checkout scm
def gitHead = scmVars.GIT_COMMIT.substring(0, 7)
sh "docker build \
-t sanbase-test:${scmVars.GIT_COMMIT}-${env.BUILD_ID}-${env.BRANCH_NAME}-${env.CHANGE_ID} \
-f Dockerfile-test . \
--progress plain"
sh "docker run \
--rm --name test-postgres-${scmVars.GIT_COMMIT}-${env.BUILD_ID}-${env.BRANCH_NAME}-${env.CHANGE_ID} \
-e POSTGRES_PASSWORD=password \
-d postgres:12.7-alpine"
try {
sh "docker run --rm \
--link test-postgres-${scmVars.GIT_COMMIT}-${env.BUILD_ID}-${env.BRANCH_NAME}-${env.CHANGE_ID}:test-db \
--env DATABASE_URL=postgres://postgres:password@test-db:5432/postgres \
-t sanbase-test:${scmVars.GIT_COMMIT}-${env.BUILD_ID}-${env.BRANCH_NAME}-${env.CHANGE_ID}"
} finally {
sh "docker kill test-postgres-${scmVars.GIT_COMMIT}-${env.BUILD_ID}-${env.BRANCH_NAME}-${env.CHANGE_ID}"
}
if (env.BRANCH_NAME == 'master') {
withCredentials([
string(
credentialsId: 'SECRET_KEY_BASE',
variable: 'SECRET_KEY_BASE'
),
string(
credentialsId: 'PARITY_URL',
variable: 'PARITY_URL'
),
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 \
-t ${awsRegistry}/sanbase:${env.BRANCH_NAME} \
-t ${awsRegistry}/sanbase:${scmVars.GIT_COMMIT} \
--build-arg SECRET_KEY_BASE=${env.SECRET_KEY_BASE} \
--build-arg PARITY_URL=${env.PARITY_URL} \
--build-arg GIT_HEAD=${gitHead} \
--build-arg GIT_COMMIT=${scmVars.GIT_COMMIT} . \
--progress plain"
sh "docker push ${awsRegistry}/sanbase:${env.BRANCH_NAME}"
sh "docker push ${awsRegistry}/sanbase:${scmVars.GIT_COMMIT}"
}
}
}
}
}
}
}