Skip to content

Commit 8ce1b48

Browse files
committed
Use Harbor Proxy service on CI.
For Testcontainers-based images, we need to extend usage of our built-in proxy service with a custom ImageNameSubstitutor. See #2724
1 parent a7da66d commit 8ce1b48

File tree

2 files changed

+97
-23
lines changed

2 files changed

+97
-23
lines changed

Jenkinsfile

Lines changed: 14 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
def p = [:]
22
node {
3-
checkout scm
4-
p = readProperties interpolate: true, file: 'ci/pipeline.properties'
3+
checkout scm
4+
p = readProperties interpolate: true, file: 'ci/pipeline.properties'
55
}
66

77
pipeline {
@@ -32,18 +32,15 @@ pipeline {
3232
options { timeout(time: 60, unit: 'MINUTES') }
3333

3434
environment {
35-
DOCKER_HUB = credentials("${p['docker.credentials']}")
3635
ARTIFACTORY = credentials("${p['artifactory.credentials']}")
36+
TESTCONTAINERS_IMAGE_SUBSTITUTOR = 'org.springframework.data.neo4j.support.ProxyImageNameSubstitutor'
3737
}
3838

3939
steps {
4040
script {
41-
docker.withRegistry(p['docker.registry'], p['docker.credentials']) {
42-
docker.image(p['docker.java.main.image']).inside(p['docker.java.inside.docker']) {
43-
sh "docker login --username ${DOCKER_HUB_USR} --password ${DOCKER_HUB_PSW}"
44-
sh "PROFILE=none ci/test.sh"
45-
sh "ci/clean.sh"
46-
}
41+
docker.image(p['docker.java.main.image']).inside(p['docker.java.inside.docker']) {
42+
sh "PROFILE=none ci/test.sh"
43+
sh "ci/clean.sh"
4744
}
4845
}
4946
}
@@ -65,18 +62,15 @@ pipeline {
6562
options { timeout(time: 60, unit: 'MINUTES') }
6663

6764
environment {
68-
DOCKER_HUB = credentials("${p['docker.credentials']}")
6965
ARTIFACTORY = credentials("${p['artifactory.credentials']}")
66+
TESTCONTAINERS_IMAGE_SUBSTITUTOR = 'org.springframework.data.neo4j.support.ProxyImageNameSubstitutor'
7067
}
7168

7269
steps {
7370
script {
74-
docker.withRegistry(p['docker.registry'], p['docker.credentials']) {
75-
docker.image(p['docker.java.next.image']).inside(p['docker.java.inside.docker']) {
76-
sh "docker login --username ${DOCKER_HUB_USR} --password ${DOCKER_HUB_PSW}"
77-
sh "PROFILE=none ci/test.sh"
78-
sh "ci/clean.sh"
79-
}
71+
docker.image(p['docker.java.next.image']).inside(p['docker.java.inside.docker']) {
72+
sh "PROFILE=none ci/test.sh"
73+
sh "ci/clean.sh"
8074
}
8175
}
8276
}
@@ -89,18 +83,15 @@ pipeline {
8983
options { timeout(time: 60, unit: 'MINUTES') }
9084

9185
environment {
92-
DOCKER_HUB = credentials("${p['docker.credentials']}")
9386
ARTIFACTORY = credentials("${p['artifactory.credentials']}")
87+
TESTCONTAINERS_IMAGE_SUBSTITUTOR = 'org.springframework.data.neo4j.support.ProxyImageNameSubstitutor'
9488
}
9589

9690
steps {
9791
script {
98-
docker.withRegistry(p['docker.registry'], p['docker.credentials']) {
99-
docker.image(p['docker.java.lts.image']).inside(p['docker.java.inside.docker']) {
100-
sh "docker login --username ${DOCKER_HUB_USR} --password ${DOCKER_HUB_PSW}"
101-
sh "PROFILE=none ci/test.sh"
102-
sh "ci/clean.sh"
103-
}
92+
docker.image(p['docker.java.lts.image']).inside(p['docker.java.inside.docker']) {
93+
sh "PROFILE=none ci/test.sh"
94+
sh "ci/clean.sh"
10495
}
10596
}
10697
}
Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
/*
2+
* Copyright 2011-2023 the original author or authors.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* https://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
package org.springframework.data.neo4j.support;
17+
18+
import ch.qos.logback.classic.Logger;
19+
20+
import java.util.Arrays;
21+
import java.util.List;
22+
23+
import org.testcontainers.utility.DockerImageName;
24+
import org.testcontainers.utility.ImageNameSubstitutor;
25+
26+
/**
27+
* An {@link ImageNameSubstitutor} only used on CI servers to leverage internal proxy solution, that needs to vary the
28+
* prefix based on which container image is needed.
29+
*
30+
* @author Greg Turnquist
31+
*/
32+
public class ProxyImageNameSubstitutor extends ImageNameSubstitutor {
33+
34+
private static final Logger LOG = (Logger) org.slf4j.LoggerFactory.getLogger(ProxyImageNameSubstitutor.class);
35+
36+
private static final List<String> NAMES_TO_PROXY_PREFIX = Arrays.asList("ryuk");
37+
38+
private static final List<String> NAMES_TO_LIBRARY_PROXY_PREFIX = Arrays.asList("neo4j");
39+
40+
private static final String PROXY_PREFIX = "harbor-repo.vmware.com/dockerhub-proxy-cache/";
41+
42+
private static final String LIBRARY_PROXY_PREFIX = PROXY_PREFIX + "library/";
43+
44+
@Override
45+
public DockerImageName apply(DockerImageName dockerImageName) {
46+
47+
if (NAMES_TO_PROXY_PREFIX.stream().anyMatch(s -> dockerImageName.asCanonicalNameString().contains(s))) {
48+
49+
String transformedName = applyProxyPrefix(dockerImageName.asCanonicalNameString());
50+
LOG.info("Converting " + dockerImageName.asCanonicalNameString() + " to " + transformedName);
51+
return DockerImageName.parse(transformedName);
52+
}
53+
54+
if (NAMES_TO_LIBRARY_PROXY_PREFIX.stream().anyMatch(s -> dockerImageName.asCanonicalNameString().contains(s))) {
55+
56+
String transformedName = applyProxyAndLibraryPrefix(dockerImageName.asCanonicalNameString());
57+
LOG.info("Converting " + dockerImageName.asCanonicalNameString() + " to " + transformedName);
58+
return DockerImageName.parse(transformedName);
59+
}
60+
61+
LOG.info("Not changing " + dockerImageName.asCanonicalNameString() + "...");
62+
return dockerImageName;
63+
}
64+
65+
@Override
66+
protected String getDescription() {
67+
return "Spring Data Proxy Image Name Substitutor";
68+
}
69+
70+
/**
71+
* Apply a non-library-based prefix.
72+
*/
73+
private static String applyProxyPrefix(String imageName) {
74+
return PROXY_PREFIX + imageName;
75+
}
76+
77+
/**
78+
* Apply a library based prefix.
79+
*/
80+
private static String applyProxyAndLibraryPrefix(String imageName) {
81+
return LIBRARY_PROXY_PREFIX + imageName;
82+
}
83+
}

0 commit comments

Comments
 (0)