-
Notifications
You must be signed in to change notification settings - Fork 273
/
docker-copy.jenkinsfile
94 lines (92 loc) · 3.87 KB
/
docker-copy.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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
/*
* Copyright OpenSearch Contributors
* 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.
*/
lib = library(identifier: 'jenkins@5.2.0', retriever: modernSCM([
$class: 'GitSCMSource',
remote: 'https://github.com/opensearch-project/opensearch-build-libraries.git',
]))
pipeline {
options {
timeout(time: 30)
}
agent none
parameters {
booleanParam(
name: 'ALL_TAGS',
description: 'If true, will copy all the tags of SOURCE_IMAGE_REGISTRY/SOURCE_IMAGE to DESTINATION_IMAGE_REGISTRY/DESTINATION_IMAGE, while ignoring IMAGE_TAG even if specified, default to false',
defaultValue: false
)
choice(
name: 'SOURCE_IMAGE_REGISTRY',
choices: ['opensearchstaging', 'public.ecr.aws/opensearchstaging', 'opensearchproject', 'public.ecr.aws/opensearchproject', 'public.ecr.aws/t2m2d0w1'],
description: 'Choose the source image registry'
)
string(
name: 'SOURCE_IMAGE',
description: 'Image name and tag <IMAGE_NAME>:<IMAGE_TAG>, Eg: opensearch:1.3.2, tag is ignored when ALL_TAGS=true, since all tags will be copied over',
trim: true
)
choice(
name: 'DESTINATION_IMAGE_REGISTRY',
choices: ['opensearchstaging', 'public.ecr.aws/opensearchstaging', 'opensearchproject', 'public.ecr.aws/opensearchproject'],
description: 'Choose the destination image registry'
)
string(
name: 'DESTINATION_IMAGE',
description: 'Image name and tag <IMAGE_NAME>:<IMAGE_TAG>, Eg: opensearch:1.3.2, tag is ignored when ALL_TAGS=true, since all tags will be copied over',
trim: true
)
}
stages {
stage("Image Copy") {
agent {
docker {
label 'Jenkins-Agent-Ubuntu2004-X64-M52xlarge-Docker-Builder'
image 'opensearchstaging/ci-runner:ubuntu2004-x64-docker-buildx0.9.1-qemu5.0-v1'
args '-u root -v /var/run/docker.sock:/var/run/docker.sock'
registryUrl 'https://public.ecr.aws/'
alwaysPull true
}
}
stages {
stage('Parameters Check') {
steps {
script {
currentBuild.description = """ALL_TAGS: ${ALL_TAGS}<br>Copying: ${SOURCE_IMAGE_REGISTRY}/${SOURCE_IMAGE} to ${DESTINATION_IMAGE_REGISTRY}/${DESTINATION_IMAGE}"""
if( SOURCE_IMAGE.isEmpty() || DESTINATION_IMAGE.isEmpty()) {
currentBuild.result = 'ABORTED'
error('Make sure all the parameters are passed in.')
}
}
}
}
stage('Copy Image to ECR/DockerHub') {
steps {
script {
copyContainer(
allTags: params.ALL_TAGS,
sourceImage: "${SOURCE_IMAGE}",
sourceRegistry: "${SOURCE_IMAGE_REGISTRY}",
destinationImage: "${DESTINATION_IMAGE}",
destinationRegistry: "${DESTINATION_IMAGE_REGISTRY}"
)
}
}
}
}
post() {
always {
script {
postCleanup()
sh "docker logout && docker logout public.ecr.aws && docker image prune -f --all"
}
}
}
}
}
}