forked from raster-foundry/raster-foundry
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Jenkinsfile.release
102 lines (90 loc) · 4.43 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
92
93
94
95
96
97
98
99
100
101
102
#!groovy
def retagImage(String image_url, String source_tag, String dest_tag) {
// Pulls down image with source_tag and re-tags with dest_tag
// before pushing back to repository
sh "docker pull ${image_url}:${source_tag}"
sh "docker tag ${image_url}:${source_tag} ${image_url}:${dest_tag}"
sh "docker push ${image_url}:${dest_tag}"
}
node {
properties([
parameters([
string(defaultValue: 'develop', description: 'First 7 characters of the SHA for the commit you wish to deploy.', name: 'GIT_COMMIT', trim: false),
[$class: 'ValidatingStringParameterDefinition',
defaultValue: '',
description: 'The tag of the current release.',
failedValidationMessage: 'Invalid SemVer.',
name: 'RELEASE_TAG',
regex: /^\d+\.\d+\.\d+$/],
string(defaultValue: 'rasterfoundry-production-config-us-east-1', description: 'Location of Terraform state & vars files.', name: 'RF_SETTINGS_BUCKET', trim: false),
string(defaultValue: 'rasterfoundry-production-docs-site-us-east-1', description: 'Location of API documentation & specs.', name: 'RF_DOCS_BUCKET', trim: false),
string(defaultValue: 'Production', description: 'Environment name, used to target Batch Compute Environments.', name: 'RF_DEPLOYMENT_ENVIRONMENT', trim: false),
string(defaultValue: 'master', description: 'Branch of azavea/raster-foundry-deployment used for deployment.', name: 'RF_DEPLOYMENT_BRANCH', trim: false)
])
])
try {
env.AWS_DEFAULT_REGION = "us-east-1"
// validate release tag ref
stage('checkout') {
checkout([$class: 'GitSCM',
branches: [[name: params.RELEASE_TAG ]],
extensions: [[$class: 'PruneStaleBranch']],
userRemoteConfigs: [[credentialsId: '3bc1e878-814a-43d1-864e-2e378ebddb0f',
url: 'https://github.com/raster-foundry/raster-foundry']]
])
}
stage('re-tag images'){
sh 'eval $(aws ecr get-login --no-include-email)'
withCredentials([[$class: 'StringBinding',
credentialsId: 'AWS_ECR_ENDPOINT',
variable: 'AWS_ECR_ENDPOINT']]) {
wrap([$class: 'AnsiColorBuildWrapper']) {
// Retag images with release tag and push to ECR
[
"raster-foundry-nginx-api",
"raster-foundry-nginx-backsplash",
"raster-foundry-api-server",
"raster-foundry-backsplash",
"raster-foundry-batch",
"raster-foundry-migrations"
].each { image_url ->
retagImage(env.AWS_ECR_ENDPOINT + "/${image_url}", params.GIT_COMMIT, params.RELEASE_TAG)
}
}
}
}
stage('publish-specs') {
sh """#!/bin/bash
aws s3 sync docs/swagger/ s3://${params.RF_DOCS_BUCKET}/spec/${params.RELEASE_TAG}/
aws s3 sync docs/swagger/ s3://${params.RF_DOCS_BUCKET}/spec/
"""
}
stage('infra') {
checkout scm: [$class: 'GitSCM',
branches: [[name: params.RF_DEPLOYMENT_BRANCH]],
extensions: [[$class: 'RelativeTargetDirectory',
relativeTargetDir: 'raster-foundry-deployment']],
userRemoteConfigs: [[credentialsId: '3bc1e878-814a-43d1-864e-2e378ebddb0f',
url: 'https://github.com/azavea/raster-foundry-deployment.git']]]
def slackMessage = ":rasterfoundry: production deployment in progress"
slackSend color: 'warning', message: slackMessage
dir('raster-foundry-deployment') {
wrap([$class: 'AnsiColorBuildWrapper']) {
sh 'docker-compose -f docker-compose.yml -f docker-compose.ci.yml run --rm terraform ./scripts/infra plan'
withCredentials([[$class: 'StringBinding',
credentialsId: 'ROLLBAR_ACCESS_TOKEN',
variable: 'ROLLBAR_ACCESS_TOKEN']]) {
sh 'docker-compose -f docker-compose.yml -f docker-compose.ci.yml run --rm terraform ./scripts/infra apply'
}
}
}
slackMessage = ":rasterfoundry: production deployment is complete"
slackSend color: 'warning', message: slackMessage
}
} catch(err) {
def slackMessage = ":jenkins-angry: *Deployment #${env.BUILD_NUMBER} of release/hotfix ${params.RELEASE_TAG} has failed*"
slackMessage += "\n<${env.BUILD_URL}|View Build>"
slackSend color: 'danger', message: slackMessage
throw err
}
}