Skip to content

Commit 4dbbb0b

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 8d9c761 commit 4dbbb0b

File tree

2 files changed

+84
-0
lines changed

2 files changed

+84
-0
lines changed

Jenkinsfile

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ pipeline {
3333

3434
environment {
3535
ARTIFACTORY = credentials("${p['artifactory.credentials']}")
36+
TESTCONTAINERS_IMAGE_SUBSTITUTOR = 'org.springframework.data.neo4j.support.ProxyImageNameSubstitutor'
3637
}
3738

3839
steps {
@@ -61,6 +62,7 @@ pipeline {
6162
options { timeout(time: 30, unit: 'MINUTES') }
6263
environment {
6364
ARTIFACTORY = credentials("${p['artifactory.credentials']}")
65+
TESTCONTAINERS_IMAGE_SUBSTITUTOR = 'org.springframework.data.neo4j.support.ProxyImageNameSubstitutor'
6466
}
6567
steps {
6668
script {
Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
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.List;
21+
22+
import org.testcontainers.utility.DockerImageName;
23+
import org.testcontainers.utility.ImageNameSubstitutor;
24+
25+
/**
26+
* An {@link ImageNameSubstitutor} only used on CI servers to leverage internal proxy solution, that needs to vary the
27+
* prefix based on which container image is needed.
28+
*
29+
* @author Greg Turnquist
30+
*/
31+
public class ProxyImageNameSubstitutor extends ImageNameSubstitutor {
32+
33+
private static final Logger LOG = (Logger) org.slf4j.LoggerFactory.getLogger(ProxyImageNameSubstitutor.class);
34+
35+
private static final List<String> NAMES_TO_PROXY_PREFIX = List.of("ryuk");
36+
37+
private static final List<String> NAMES_TO_LIBRARY_PROXY_PREFIX = List.of("neo4j");
38+
39+
private static final String PROXY_PREFIX = "harbor-repo.vmware.com/dockerhub-proxy-cache/";
40+
41+
private static final String LIBRARY_PROXY_PREFIX = PROXY_PREFIX + "library/";
42+
43+
@Override
44+
public DockerImageName apply(DockerImageName dockerImageName) {
45+
46+
if (NAMES_TO_PROXY_PREFIX.stream().anyMatch(s -> dockerImageName.asCanonicalNameString().contains(s))) {
47+
48+
String transformedName = applyProxyPrefix(dockerImageName.asCanonicalNameString());
49+
LOG.info("Converting " + dockerImageName.asCanonicalNameString() + " to " + transformedName);
50+
return DockerImageName.parse(transformedName);
51+
}
52+
53+
if (NAMES_TO_LIBRARY_PROXY_PREFIX.stream().anyMatch(s -> dockerImageName.asCanonicalNameString().contains(s))) {
54+
55+
String transformedName = applyProxyAndLibraryPrefix(dockerImageName.asCanonicalNameString());
56+
LOG.info("Converting " + dockerImageName.asCanonicalNameString() + " to " + transformedName);
57+
return DockerImageName.parse(transformedName);
58+
}
59+
60+
LOG.info("Not changing " + dockerImageName.asCanonicalNameString() + "...");
61+
return dockerImageName;
62+
}
63+
64+
@Override
65+
protected String getDescription() {
66+
return "Spring Data Proxy Image Name Substitutor";
67+
}
68+
69+
/**
70+
* Apply a non-library-based prefix.
71+
*/
72+
private static String applyProxyPrefix(String imageName) {
73+
return PROXY_PREFIX + imageName;
74+
}
75+
76+
/**
77+
* Apply a library based prefix.
78+
*/
79+
private static String applyProxyAndLibraryPrefix(String imageName) {
80+
return LIBRARY_PROXY_PREFIX + imageName;
81+
}
82+
}

0 commit comments

Comments
 (0)