forked from opensearch-project/opensearch-build
-
Notifications
You must be signed in to change notification settings - Fork 0
/
promoteContainer.groovy
109 lines (106 loc) · 5.31 KB
/
promoteContainer.groovy
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
103
104
105
106
107
108
109
/*
* SPDX-License-Identifier: Apache-2.0
*
* The OpenSearch Contributors require contributions made to
* this file be licensed under the Apache-2.0 license or a
* compatible open source license.
*/
/**@
* Promote image from staging docker to production docker hub or ECR repository.
*
* @param args A map of the following parameters
* @param args.imageRepository The repository of staging image. E.g.: opensearch:2.0.1.3910, opensearch-dashboards:2.0.1, data-prepper:2.0.1-1234
* @param args.version The official version for release. E.g.: 2.0.1
* @param args.dockerPromote The boolean argument if promote containers from staging to production docker repo.
* @param args.ecrPromote The boolean argument if promote containers from staging to production ECR repo.
* @param args.latestTag The boolean argument if promote containers from staging to production with latest tag.
* @param args.majorVersionTag The boolean argument if promote containers from staging to production with its major version tag.
*/
void call(Map args = [:]) {
def imageRepo = args.imageRepository
def version = args.version
def imageProduct = imageRepo.split(':').first()
def sourceTag = imageRepo.split(':').last()
def dockerPromote = args.dockerPromote
def ecrPromote = args.ecrPromote
def latestBoolean = args.latestTag
def majorVersionBoolean = args.majorVersionTag
def majorVersion = version.split("\\.").first()
def sourceReg = (imageProduct == 'data-prepper') ? "${DATA_PREPPER_STAGING_CONTAINER_REPOSITORY}" : "opensearchstaging"
def dockerProduction = "opensearchproject"
def ecrProduction = "public.ecr.aws/opensearchproject"
//Promoting docker images
if (dockerPromote.toBoolean()) {
println("Promoting $imageProduct to production docker hub with with $version tag.")
dockerCopy: {
build job: 'docker-copy',
parameters: [
string(name: 'SOURCE_IMAGE_REGISTRY', value: sourceReg),
string(name: 'SOURCE_IMAGE', value: "${imageProduct}:${sourceTag}"),
string(name: 'DESTINATION_IMAGE_REGISTRY', value: dockerProduction),
string(name: 'DESTINATION_IMAGE', value: "${imageProduct}:${version}")
]
}
if (majorVersionBoolean.toBoolean()) {
println("Promoting to production docker hub with with $majorVersion tag.")
dockerCopy: {
build job: 'docker-copy',
parameters: [
string(name: 'SOURCE_IMAGE_REGISTRY', value: sourceReg),
string(name: 'SOURCE_IMAGE', value: "${imageProduct}:${sourceTag}"),
string(name: 'DESTINATION_IMAGE_REGISTRY', value: dockerProduction),
string(name: 'DESTINATION_IMAGE', value: "${imageProduct}:${majorVersion}")
]
}
}
if (latestBoolean.toBoolean()) {
println("Promoting to production docker hub with with latest tag.")
dockerCopy: {
build job: 'docker-copy',
parameters: [
string(name: 'SOURCE_IMAGE_REGISTRY', value: sourceReg),
string(name: 'SOURCE_IMAGE', value: "${imageProduct}:${sourceTag}"),
string(name: 'DESTINATION_IMAGE_REGISTRY', value: dockerProduction),
string(name: 'DESTINATION_IMAGE', value: "${imageProduct}:latest")
]
}
}
}
//Promoting image to ECR
if (ecrPromote.toBoolean()) {
println("Promoting to production ECR with with $version tag.")
dockerCopy: {
build job: 'docker-copy',
parameters: [
string(name: 'SOURCE_IMAGE_REGISTRY', value: sourceReg),
string(name: 'SOURCE_IMAGE', value: "${imageProduct}:${sourceTag}"),
string(name: 'DESTINATION_IMAGE_REGISTRY', value: ecrProduction),
string(name: 'DESTINATION_IMAGE', value: "${imageProduct}:${version}")
]
}
if (majorVersionBoolean.toBoolean()) {
println("Promoting to production ECR with with $majorVersion tag.")
dockerCopy: {
build job: 'docker-copy',
parameters: [
string(name: 'SOURCE_IMAGE_REGISTRY', value: sourceReg),
string(name: 'SOURCE_IMAGE', value: "${imageProduct}:${sourceTag}"),
string(name: 'DESTINATION_IMAGE_REGISTRY', value: ecrProduction),
string(name: 'DESTINATION_IMAGE', value: "${imageProduct}:${majorVersion}")
]
}
}
if (latestBoolean.toBoolean()) {
println("Promoting to production ECR with with latest tag.")
dockerCopy: {
build job: 'docker-copy',
parameters: [
string(name: 'SOURCE_IMAGE_REGISTRY', value: sourceReg),
string(name: 'SOURCE_IMAGE', value: "${imageProduct}:${sourceTag}"),
string(name: 'DESTINATION_IMAGE_REGISTRY', value: ecrProduction),
string(name: 'DESTINATION_IMAGE', value: "${imageProduct}:latest")
]
}
}
}
}