forked from opensupplyhub/open-apparel-registry
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Jenkinsfile.release
91 lines (76 loc) · 3.5 KB
/
Jenkinsfile.release
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
#!groovy
node {
properties([
parameters([
[
$class: 'ValidatingStringParameterDefinition',
defaultValue: '',
description: 'First 7 characters of the SHA for the commit you wish to deploy.',
failedValidationMessage: 'Invalid SHA.',
name: 'GIT_COMMIT',
regex: /^[a-z0-9]{7}$/
]
])
])
// Notify Slack that we're starting a production deploy.
def startedMessage =
":jenkins: deploying revision <https://github.com/open-apparel-registry/open-apparel-registry/tree/${params.GIT_COMMIT}|${params.GIT_COMMIT}> to *production*"
startedMessage += "\n<${env.BUILD_URL}|View Build>"
slackSend channel: '#oar', color: 'warning', message: startedMessage
try {
// Checkout the proper revision into the workspace.
stage('checkout') {
checkout([
$class: 'GitSCM',
branches: [[name: params.GIT_COMMIT]],
extensions: [[$class: 'PruneStaleBranch']],
userRemoteConfigs: [[
credentialsId: 'azaveaci',
url: '[email protected]:open-apparel-registry/open-apparel-registry.git'
]]
])
}
env.AWS_PROFILE = 'open-apparel-registry'
env.AWS_DEFAULT_REGION = 'eu-west-1'
env.OAR_SETTINGS_BUCKET = 'openapparelregistry-testing-config-eu-west-1'
// If we don't do this, the showmigrations stage will throw
// django.core.exceptions.ImproperlyConfigured
stage('setup') {
wrap([$class: 'AnsiColorBuildWrapper']) {
sh './scripts/bootstrap'
}
}
env.OAR_SETTINGS_BUCKET = 'openapparelregistry-production-config-eu-west-1'
// Plan and apply the current state of the production infrastructure
// as outlined by whatever SHA is passed through as a build parameter.
stage('infra') {
// Environment used in Rollbar deploy notifications.
// https://docs.rollbar.com/reference#post-deploy
env.OAR_DEPLOYMENT_ENVIRONMENT = 'production'
wrap([$class: 'AnsiColorBuildWrapper']) {
sh 'docker-compose -f docker-compose.ci.yml run --rm terraform ./scripts/infra plan'
withCredentials([[$class: 'StringBinding',
credentialsId: 'OAR_ROLLBAR_ACCESS_TOKEN',
variable: 'OAR_ROLLBAR_ACCESS_TOKEN']]) {
sh 'docker-compose -f docker-compose.ci.yml run --rm terraform ./scripts/infra apply'
}
}
}
// Kick off an ECS task to display any outstanding migrations.
stage('showmigrations') {
wrap([$class: 'AnsiColorBuildWrapper']) {
sh './scripts/manage ecsmanage -e production showmigrations'
}
}
} catch (err) {
// Some exception was raised in the `try` block above. Assemble
// an appropirate error message for Slack.
def failedMessage =
":jenkins-angry: failed to deploy revision <https://github.com/open-apparel-registry/open-apparel-registry/tree/${params.GIT_COMMIT}|${params.GIT_COMMIT}> to *production*"
failedMessage += "\n<${env.BUILD_URL}|View Build>"
slackSend channel: '#oar', color: 'danger', message: failedMessage
// Re-raise the exception so that the failure is propagated to
// Jenkins.
throw err
}
}