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
This commit is contained in:
Greg L. Turnquist
2023-05-17 11:28:14 -05:00
parent bde49f0b10
commit 34c9a2c350
2 changed files with 99 additions and 25 deletions

41
Jenkinsfile vendored
View File

@@ -1,7 +1,7 @@
def p = [:]
node {
checkout scm
p = readProperties interpolate: true, file: 'ci/pipeline.properties'
checkout scm
p = readProperties interpolate: true, file: 'ci/pipeline.properties'
}
pipeline {
@@ -32,18 +32,15 @@ pipeline {
options { timeout(time: 60, unit: 'MINUTES') }
environment {
DOCKER_HUB = credentials("${p['docker.credentials']}")
ARTIFACTORY = credentials("${p['artifactory.credentials']}")
TESTCONTAINERS_IMAGE_SUBSTITUTOR = 'org.springframework.data.neo4j.support.ProxyImageNameSubstitutor'
}
steps {
script {
docker.withRegistry(p['docker.registry'], p['docker.credentials']) {
docker.image(p['docker.java.main.image']).inside(p['docker.java.inside.docker']) {
sh "docker login --username ${DOCKER_HUB_USR} --password ${DOCKER_HUB_PSW}"
sh "PROFILE=none ci/test.sh"
sh "ci/clean.sh"
}
docker.image(p['docker.java.main.image']).inside(p['docker.java.inside.docker']) {
sh "PROFILE=none ci/test.sh"
sh "ci/clean.sh"
}
}
}
@@ -52,7 +49,7 @@ pipeline {
stage("Test other configurations") {
when {
allOf {
branch 'main'
branch(pattern: "main|(\\d\\.\\d\\.x)", comparator: "REGEXP")
not { triggeredBy 'UpstreamCause' }
}
}
@@ -64,18 +61,15 @@ pipeline {
options { timeout(time: 60, unit: 'MINUTES') }
environment {
DOCKER_HUB = credentials("${p['docker.credentials']}")
ARTIFACTORY = credentials("${p['artifactory.credentials']}")
TESTCONTAINERS_IMAGE_SUBSTITUTOR = 'org.springframework.data.neo4j.support.ProxyImageNameSubstitutor'
}
steps {
script {
docker.withRegistry(p['docker.registry'], p['docker.credentials']) {
docker.image(p['docker.java.next.image']).inside(p['docker.java.inside.docker']) {
sh "docker login --username ${DOCKER_HUB_USR} --password ${DOCKER_HUB_PSW}"
sh "PROFILE=none ci/test.sh"
sh "ci/clean.sh"
}
docker.image(p['docker.java.next.image']).inside(p['docker.java.inside.docker']) {
sh "PROFILE=none ci/test.sh"
sh "ci/clean.sh"
}
}
}
@@ -88,18 +82,15 @@ pipeline {
options { timeout(time: 60, unit: 'MINUTES') }
environment {
DOCKER_HUB = credentials("${p['docker.credentials']}")
ARTIFACTORY = credentials("${p['artifactory.credentials']}")
TESTCONTAINERS_IMAGE_SUBSTITUTOR = 'org.springframework.data.neo4j.support.ProxyImageNameSubstitutor'
}
steps {
script {
docker.withRegistry(p['docker.registry'], p['docker.credentials']) {
docker.image(p['docker.java.lts.image']).inside(p['docker.java.inside.docker']) {
sh "docker login --username ${DOCKER_HUB_USR} --password ${DOCKER_HUB_PSW}"
sh "PROFILE=none ci/test.sh"
sh "ci/clean.sh"
}
docker.image(p['docker.java.lts.image']).inside(p['docker.java.inside.docker']) {
sh "PROFILE=none ci/test.sh"
sh "ci/clean.sh"
}
}
}
@@ -144,7 +135,7 @@ pipeline {
stage('Publish documentation') {
when {
branch 'main'
branch(pattern: "main|(\\d\\.\\d\\.x)", comparator: "REGEXP")
}
agent {
label 'data'

View File

@@ -0,0 +1,83 @@
/*
* Copyright 2011-2023 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.data.neo4j.support;
import ch.qos.logback.classic.Logger;
import java.util.Arrays;
import java.util.List;
import org.testcontainers.utility.DockerImageName;
import org.testcontainers.utility.ImageNameSubstitutor;
/**
* An {@link ImageNameSubstitutor} only used on CI servers to leverage internal proxy solution, that needs to vary the
* prefix based on which container image is needed.
*
* @author Greg Turnquist
*/
public class ProxyImageNameSubstitutor extends ImageNameSubstitutor {
private static final Logger LOG = (Logger) org.slf4j.LoggerFactory.getLogger(ProxyImageNameSubstitutor.class);
private static final List<String> NAMES_TO_PROXY_PREFIX = Arrays.asList("ryuk");
private static final List<String> NAMES_TO_LIBRARY_PROXY_PREFIX = Arrays.asList("neo4j");
private static final String PROXY_PREFIX = "harbor-repo.vmware.com/dockerhub-proxy-cache/";
private static final String LIBRARY_PROXY_PREFIX = PROXY_PREFIX + "library/";
@Override
public DockerImageName apply(DockerImageName dockerImageName) {
if (NAMES_TO_PROXY_PREFIX.stream().anyMatch(s -> dockerImageName.asCanonicalNameString().contains(s))) {
String transformedName = applyProxyPrefix(dockerImageName.asCanonicalNameString());
LOG.info("Converting " + dockerImageName.asCanonicalNameString() + " to " + transformedName);
return DockerImageName.parse(transformedName);
}
if (NAMES_TO_LIBRARY_PROXY_PREFIX.stream().anyMatch(s -> dockerImageName.asCanonicalNameString().contains(s))) {
String transformedName = applyProxyAndLibraryPrefix(dockerImageName.asCanonicalNameString());
LOG.info("Converting " + dockerImageName.asCanonicalNameString() + " to " + transformedName);
return DockerImageName.parse(transformedName);
}
LOG.info("Not changing " + dockerImageName.asCanonicalNameString() + "...");
return dockerImageName;
}
@Override
protected String getDescription() {
return "Spring Data Proxy Image Name Substitutor";
}
/**
* Apply a non-library-based prefix.
*/
private static String applyProxyPrefix(String imageName) {
return PROXY_PREFIX + imageName;
}
/**
* Apply a library based prefix.
*/
private static String applyProxyAndLibraryPrefix(String imageName) {
return LIBRARY_PROXY_PREFIX + imageName;
}
}