forked from Concordium/concordium-node
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathactivate-distribution-image.Jenkinsfile
56 lines (53 loc) · 1.94 KB
/
activate-distribution-image.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
// Parameters:
// - environment
// - image_tag
@Library('concordium-pipelines') _
node('master-node') {
def DISTRIBUTION_IDS = [
stagenet: 'E2Z6VZ10YEWPDX',
testnet: 'E3OE3P6NHHWU0I',
mainnet: 'E1F07594M64NU0',
]
if (!environment?.trim()) {
error "No value for 'environment' provided."
}
def image_name = "${environment}-node"
def file_name = "${image_name}-${image_tag}.tar.gz"
def s3_bucket = "s3://distribution.${concordiumDomain(environment)}"
def s3_version_path = 'image/version.json'
def s3_image_path = "image/${file_name}"
def cf_distribution_id = DISTRIBUTION_IDS[environment]
if (!cf_distribution_id) {
error "No value for 'cf_distribution_id' found."
}
stage('verify') {
try {
sh (script: """\
aws s3 ls "${s3_bucket}/${s3_image_path}"
""".stripIndent())
} catch (e) {
error "Image with tag '${image_tag}' does not exist in bucket '${s3_bucket}' on path '${s3_image_path}'."
}
}
stage('update') {
sh(script: """\
aws s3 cp - "${s3_bucket}/${s3_version_path}" --grants=read=uri=http://acs.amazonaws.com/groups/global/AllUsers <<EOF
{
"image_tag": "${image_tag}",
"file": "${file_name}",
"image_name": "${image_name}"
}
EOF
""".stripIndent())
}
stage('invalidate') {
invalidation_result = sh(script: """\
aws cloudfront create-invalidation --distribution-id="${cf_distribution_id}" --paths="/${s3_version_path}"
""", returnStdout: true)
// Wait for invalidation to complete.
invalidation = readJSON(text: invalidation_result)
sh(script: """\
aws cloudfront wait invalidation-completed --distribution-id="${cf_distribution_id}" --id="${invalidation.Invalidation.Id}"
""".stripIndent())
}
}