Clean docker image cache (#1636)
This commit is contained in:
@@ -21,4 +21,3 @@ runs:
|
||||
|
||||
echo "BRANCH_NAME=$(echo $GITHUB_HEAD_REF)" >> $GITHUB_ENV
|
||||
echo "BASE_BRANCH_NAME=$(echo $GITHUB_BASE_REF)" >> $GITHUB_ENV
|
||||
echo "DOCKER_IMAGES_KEY=$(echo $GITHUB_RUN_ID)" >> $GITHUB_ENV
|
||||
|
||||
@@ -22,6 +22,9 @@ runs:
|
||||
- name: cache local maven repository
|
||||
uses: ./.github/workflows/composites/cache
|
||||
|
||||
- name: restore common images
|
||||
uses: ./.github/workflows/composites/restore-docker-images
|
||||
|
||||
- name: build project
|
||||
shell: bash
|
||||
run: |
|
||||
|
||||
42
.github/workflows/composites/restore-docker-images/action.yaml
vendored
Normal file
42
.github/workflows/composites/restore-docker-images/action.yaml
vendored
Normal file
@@ -0,0 +1,42 @@
|
||||
name: restore-docker-images
|
||||
description: upload docker images
|
||||
runs:
|
||||
using: "composite"
|
||||
steps:
|
||||
|
||||
- name: restore images if cache matches
|
||||
uses: actions/cache/restore@v4
|
||||
id: images-cache
|
||||
with:
|
||||
path: /tmp/docker/images
|
||||
key: docker-images-github-cache-${{ hashFiles('**/current-images.txt') }}
|
||||
|
||||
- name: pull docker images
|
||||
shell: bash
|
||||
if: steps.images-cache.outputs.cache-hit != 'true'
|
||||
run: |
|
||||
echo 'start pulling common images'
|
||||
mkdir -p /tmp/docker/images
|
||||
result=$(find . -name 'current-images.txt')
|
||||
while read line; do
|
||||
docker pull "$line"
|
||||
replace_slash=$(tr '/' '-' <<< "$line")
|
||||
docker save "${line}" > "/tmp/docker/images/${replace_slash}.tar"
|
||||
done <$result
|
||||
|
||||
- name: save docker images
|
||||
id: save-docker-images
|
||||
uses: actions/cache/save@v4
|
||||
if: steps.images-cache.outputs.cache-hit != 'true'
|
||||
with:
|
||||
path: |
|
||||
/tmp/docker/images
|
||||
key: docker-images-github-cache-${{ hashFiles('**/current-images.txt') }}
|
||||
|
||||
- name: print images
|
||||
shell: bash
|
||||
run: |
|
||||
echo 'printing images'
|
||||
ls /tmp/docker/images
|
||||
|
||||
|
||||
@@ -1,19 +0,0 @@
|
||||
# we are not going to use upload/download actions, since it is slower than cache usage
|
||||
# as key to the cache we are going to use DOCKER_IMAGES_KEY, which is the same as GITHUB_RUN_ID
|
||||
|
||||
name: upload docker images
|
||||
description: upload docker images
|
||||
runs:
|
||||
using: "composite"
|
||||
steps:
|
||||
|
||||
- uses: Wandalen/wretry.action@master
|
||||
with:
|
||||
attempt_limit: 3
|
||||
action: buildjet/cache@v3
|
||||
with: |
|
||||
path: /tmp/docker/images
|
||||
key: docker-images-cache-${{ env.DOCKER_IMAGES_KEY }}
|
||||
restore-keys: docker-images-cache-${{ env.DOCKER_IMAGES_KEY }}
|
||||
|
||||
|
||||
@@ -23,7 +23,6 @@ import java.util.Set;
|
||||
|
||||
import com.github.tomakehurst.wiremock.WireMockServer;
|
||||
import com.github.tomakehurst.wiremock.client.WireMock;
|
||||
import com.github.tomakehurst.wiremock.common.ConsoleNotifier;
|
||||
import io.kubernetes.client.openapi.ApiClient;
|
||||
import io.kubernetes.client.openapi.Configuration;
|
||||
import io.kubernetes.client.openapi.JSON;
|
||||
@@ -100,7 +99,7 @@ class KubernetesClientServicesListSupplierTests {
|
||||
|
||||
@BeforeAll
|
||||
static void setup() {
|
||||
wireMockServer = new WireMockServer(options().dynamicPort().notifier(new ConsoleNotifier(true)));
|
||||
wireMockServer = new WireMockServer(options().dynamicPort());
|
||||
wireMockServer.start();
|
||||
WireMock.configureFor("localhost", wireMockServer.port());
|
||||
|
||||
|
||||
@@ -18,7 +18,6 @@ package org.springframework.cloud.kubernetes.client.loadbalancer.it.mode.service
|
||||
|
||||
import com.github.tomakehurst.wiremock.WireMockServer;
|
||||
import com.github.tomakehurst.wiremock.client.WireMock;
|
||||
import com.github.tomakehurst.wiremock.common.ConsoleNotifier;
|
||||
import io.kubernetes.client.openapi.ApiClient;
|
||||
import io.kubernetes.client.openapi.models.V1Endpoints;
|
||||
import io.kubernetes.client.openapi.models.V1EndpointsList;
|
||||
@@ -90,7 +89,7 @@ class AllNamespacesTest {
|
||||
@BeforeAll
|
||||
static void beforeAll() {
|
||||
|
||||
wireMockServer = new WireMockServer(options().dynamicPort().notifier(new ConsoleNotifier(true)));
|
||||
wireMockServer = new WireMockServer(options().dynamicPort());
|
||||
wireMockServer.start();
|
||||
WireMock.configureFor("localhost", wireMockServer.port());
|
||||
mockWatchers();
|
||||
|
||||
@@ -33,6 +33,7 @@ import org.testcontainers.k3s.K3sContainer;
|
||||
|
||||
import org.springframework.cloud.kubernetes.commons.discovery.EndpointNameAndNamespace;
|
||||
import org.springframework.cloud.kubernetes.integration.tests.commons.Commons;
|
||||
import org.springframework.cloud.kubernetes.integration.tests.commons.Images;
|
||||
import org.springframework.cloud.kubernetes.integration.tests.commons.Phase;
|
||||
import org.springframework.cloud.kubernetes.integration.tests.commons.fabric8_client.Util;
|
||||
import org.springframework.core.ParameterizedTypeReference;
|
||||
@@ -73,6 +74,8 @@ class Fabric8CatalogWatchIT {
|
||||
Commons.validateImage(IMAGE_NAME, K3S);
|
||||
Commons.loadSpringCloudKubernetesImage(IMAGE_NAME, K3S);
|
||||
|
||||
Images.loadBusybox(K3S);
|
||||
|
||||
util = new Util(K3S);
|
||||
|
||||
util.createNamespace(NAMESPACE_A);
|
||||
|
||||
@@ -42,6 +42,7 @@ import reactor.util.retry.RetryBackoffSpec;
|
||||
|
||||
import org.springframework.cloud.kubernetes.commons.discovery.DefaultKubernetesServiceInstance;
|
||||
import org.springframework.cloud.kubernetes.integration.tests.commons.Commons;
|
||||
import org.springframework.cloud.kubernetes.integration.tests.commons.Images;
|
||||
import org.springframework.cloud.kubernetes.integration.tests.commons.Phase;
|
||||
import org.springframework.cloud.kubernetes.integration.tests.commons.fabric8_client.Util;
|
||||
import org.springframework.core.ParameterizedTypeReference;
|
||||
@@ -92,6 +93,9 @@ class Fabric8DiscoveryPodMetadataIT {
|
||||
Commons.validateImage(IMAGE_NAME, K3S);
|
||||
Commons.loadSpringCloudKubernetesImage(IMAGE_NAME, K3S);
|
||||
|
||||
Images.loadBusybox(K3S);
|
||||
Images.loadWiremock(K3S);
|
||||
|
||||
util = new Util(K3S);
|
||||
client = util.client();
|
||||
|
||||
|
||||
@@ -35,6 +35,7 @@ import reactor.util.retry.Retry;
|
||||
import reactor.util.retry.RetryBackoffSpec;
|
||||
|
||||
import org.springframework.cloud.kubernetes.integration.tests.commons.Commons;
|
||||
import org.springframework.cloud.kubernetes.integration.tests.commons.Images;
|
||||
import org.springframework.cloud.kubernetes.integration.tests.commons.Phase;
|
||||
import org.springframework.cloud.kubernetes.integration.tests.commons.fabric8_client.Util;
|
||||
import org.springframework.http.HttpMethod;
|
||||
@@ -42,7 +43,6 @@ import org.springframework.http.client.reactive.ReactorClientHttpConnector;
|
||||
import org.springframework.web.reactive.function.client.WebClient;
|
||||
|
||||
import static org.springframework.cloud.kubernetes.integration.tests.commons.Commons.processExecResult;
|
||||
import static org.springframework.cloud.kubernetes.integration.tests.commons.fabric8_client.Util.ISTIO_ISTIOCTL;
|
||||
|
||||
/**
|
||||
* @author wind57
|
||||
@@ -53,10 +53,6 @@ class Fabric8IstioIT {
|
||||
|
||||
private static final String IMAGE_NAME = "spring-cloud-kubernetes-fabric8-client-istio";
|
||||
|
||||
private static final String ISTIO_PROXY = "istio/proxyv2";
|
||||
|
||||
private static final String ISTIO_PILOT = "istio/pilot";
|
||||
|
||||
private static Util util;
|
||||
|
||||
private static K3sContainer K3S;
|
||||
@@ -69,12 +65,7 @@ class Fabric8IstioIT {
|
||||
Commons.validateImage(IMAGE_NAME, K3S);
|
||||
Commons.loadSpringCloudKubernetesImage(IMAGE_NAME, K3S);
|
||||
|
||||
Commons.pullImage(ISTIO_ISTIOCTL, Commons.ISTIO_VERSION, K3S);
|
||||
Commons.loadImage(ISTIO_ISTIOCTL, Commons.ISTIO_VERSION, "istioctl", K3S);
|
||||
Commons.pullImage(ISTIO_PROXY, Commons.ISTIO_VERSION, K3S);
|
||||
Commons.loadImage(ISTIO_PROXY, Commons.ISTIO_VERSION, "istioproxy", K3S);
|
||||
Commons.pullImage(ISTIO_PILOT, Commons.ISTIO_VERSION, K3S);
|
||||
Commons.loadImage(ISTIO_PILOT, Commons.ISTIO_VERSION, "istiopilot", K3S);
|
||||
Images.loadIstioctl(K3S);
|
||||
|
||||
processExecResult(K3S.execInContainer("sh", "-c", "kubectl create namespace istio-test"));
|
||||
processExecResult(
|
||||
@@ -127,6 +118,7 @@ class Fabric8IstioIT {
|
||||
InputStream ingressStream = util.inputStream("istio-ingress.yaml");
|
||||
|
||||
Deployment deployment = Serialization.unmarshal(deploymentStream, Deployment.class);
|
||||
|
||||
Service service = Serialization.unmarshal(serviceStream, Service.class);
|
||||
Ingress ingress = Serialization.unmarshal(ingressStream, Ingress.class);
|
||||
|
||||
|
||||
@@ -39,6 +39,7 @@ import reactor.util.retry.RetryBackoffSpec;
|
||||
|
||||
import org.springframework.cloud.kubernetes.commons.discovery.EndpointNameAndNamespace;
|
||||
import org.springframework.cloud.kubernetes.integration.tests.commons.Commons;
|
||||
import org.springframework.cloud.kubernetes.integration.tests.commons.Images;
|
||||
import org.springframework.cloud.kubernetes.integration.tests.commons.Phase;
|
||||
import org.springframework.cloud.kubernetes.integration.tests.commons.native_client.Util;
|
||||
import org.springframework.core.ParameterizedTypeReference;
|
||||
@@ -75,6 +76,9 @@ class KubernetesClientCatalogWatchIT {
|
||||
K3S.start();
|
||||
Commons.validateImage(APP_NAME, K3S);
|
||||
Commons.loadSpringCloudKubernetesImage(APP_NAME, K3S);
|
||||
|
||||
Images.loadBusybox(K3S);
|
||||
|
||||
util = new Util(K3S);
|
||||
util.setUp(NAMESPACE);
|
||||
app(Phase.CREATE);
|
||||
|
||||
@@ -34,6 +34,7 @@ import org.testcontainers.containers.Container;
|
||||
import org.testcontainers.k3s.K3sContainer;
|
||||
|
||||
import org.springframework.cloud.kubernetes.integration.tests.commons.Commons;
|
||||
import org.springframework.cloud.kubernetes.integration.tests.commons.Images;
|
||||
import org.springframework.cloud.kubernetes.integration.tests.commons.Phase;
|
||||
import org.springframework.cloud.kubernetes.integration.tests.commons.native_client.Util;
|
||||
|
||||
@@ -66,6 +67,9 @@ class ActuatorRefreshIT {
|
||||
K3S.start();
|
||||
Commons.validateImage(SPRING_CLOUD_K8S_CONFIG_WATCHER_APP_NAME, K3S);
|
||||
Commons.loadSpringCloudKubernetesImage(SPRING_CLOUD_K8S_CONFIG_WATCHER_APP_NAME, K3S);
|
||||
|
||||
Images.loadWiremock(K3S);
|
||||
|
||||
util = new Util(K3S);
|
||||
util.setUp(NAMESPACE);
|
||||
|
||||
|
||||
@@ -37,6 +37,7 @@ import reactor.util.retry.RetryBackoffSpec;
|
||||
|
||||
import org.springframework.boot.test.json.BasicJsonTester;
|
||||
import org.springframework.cloud.kubernetes.integration.tests.commons.Commons;
|
||||
import org.springframework.cloud.kubernetes.integration.tests.commons.Images;
|
||||
import org.springframework.cloud.kubernetes.integration.tests.commons.Phase;
|
||||
import org.springframework.cloud.kubernetes.integration.tests.commons.native_client.Util;
|
||||
import org.springframework.http.HttpMethod;
|
||||
@@ -153,6 +154,8 @@ class DiscoveryClientIT {
|
||||
Commons.validateImage(SPRING_CLOUD_K8S_DISCOVERY_CLIENT_APP_NAME, K3S);
|
||||
Commons.loadSpringCloudKubernetesImage(SPRING_CLOUD_K8S_DISCOVERY_CLIENT_APP_NAME, K3S);
|
||||
|
||||
Images.loadWiremock(K3S);
|
||||
|
||||
util = new Util(K3S);
|
||||
rbacApi = new RbacAuthorizationV1Api();
|
||||
util.setUp(NAMESPACE);
|
||||
|
||||
@@ -43,6 +43,7 @@ import reactor.util.retry.RetryBackoffSpec;
|
||||
import org.springframework.cloud.client.ServiceInstance;
|
||||
import org.springframework.cloud.kubernetes.commons.discovery.DefaultKubernetesServiceInstance;
|
||||
import org.springframework.cloud.kubernetes.integration.tests.commons.Commons;
|
||||
import org.springframework.cloud.kubernetes.integration.tests.commons.Images;
|
||||
import org.springframework.cloud.kubernetes.integration.tests.commons.Phase;
|
||||
import org.springframework.cloud.kubernetes.integration.tests.commons.native_client.Util;
|
||||
import org.springframework.core.ParameterizedTypeReference;
|
||||
@@ -80,6 +81,9 @@ class KubernetesClientDiscoveryClientIT {
|
||||
Commons.validateImage(IMAGE_NAME, K3S);
|
||||
Commons.loadSpringCloudKubernetesImage(IMAGE_NAME, K3S);
|
||||
|
||||
Images.loadWiremock(K3S);
|
||||
Images.loadBusybox(K3S);
|
||||
|
||||
util = new Util(K3S);
|
||||
util.setUp(NAMESPACE);
|
||||
manifests(Phase.CREATE);
|
||||
|
||||
@@ -42,6 +42,7 @@ import reactor.util.retry.RetryBackoffSpec;
|
||||
|
||||
import org.springframework.cloud.kubernetes.commons.discovery.DefaultKubernetesServiceInstance;
|
||||
import org.springframework.cloud.kubernetes.integration.tests.commons.Commons;
|
||||
import org.springframework.cloud.kubernetes.integration.tests.commons.Images;
|
||||
import org.springframework.cloud.kubernetes.integration.tests.commons.Phase;
|
||||
import org.springframework.cloud.kubernetes.integration.tests.commons.native_client.Util;
|
||||
import org.springframework.core.ParameterizedTypeReference;
|
||||
@@ -79,6 +80,8 @@ class KubernetesClientDiscoverySelectiveNamespacesIT {
|
||||
Commons.validateImage(IMAGE_NAME, K3S);
|
||||
Commons.loadSpringCloudKubernetesImage(IMAGE_NAME, K3S);
|
||||
|
||||
Images.loadWiremock(K3S);
|
||||
|
||||
util = new Util(K3S);
|
||||
|
||||
util.createNamespace(NAMESPACE_A);
|
||||
|
||||
@@ -36,6 +36,7 @@ import reactor.util.retry.Retry;
|
||||
import reactor.util.retry.RetryBackoffSpec;
|
||||
|
||||
import org.springframework.cloud.kubernetes.integration.tests.commons.Commons;
|
||||
import org.springframework.cloud.kubernetes.integration.tests.commons.Images;
|
||||
import org.springframework.cloud.kubernetes.integration.tests.commons.Phase;
|
||||
import org.springframework.cloud.kubernetes.integration.tests.commons.native_client.Util;
|
||||
import org.springframework.http.HttpMethod;
|
||||
@@ -77,6 +78,8 @@ class ConfigurationWatcherMultipleAppsIT {
|
||||
Commons.validateImage(CONFIG_WATCHER_APP_B_IMAGE, K3S);
|
||||
Commons.loadSpringCloudKubernetesImage(CONFIG_WATCHER_APP_B_IMAGE, K3S);
|
||||
|
||||
Images.loadKafka(K3S);
|
||||
|
||||
util = new Util(K3S);
|
||||
util.setUp(NAMESPACE);
|
||||
}
|
||||
|
||||
@@ -36,6 +36,7 @@ import reactor.util.retry.Retry;
|
||||
import reactor.util.retry.RetryBackoffSpec;
|
||||
|
||||
import org.springframework.cloud.kubernetes.integration.tests.commons.Commons;
|
||||
import org.springframework.cloud.kubernetes.integration.tests.commons.Images;
|
||||
import org.springframework.cloud.kubernetes.integration.tests.commons.Phase;
|
||||
import org.springframework.cloud.kubernetes.integration.tests.commons.native_client.Util;
|
||||
import org.springframework.http.HttpMethod;
|
||||
@@ -76,6 +77,8 @@ class ConfigurationWatcherMultipleAppIT {
|
||||
Commons.validateImage(CONFIG_WATCHER_APP_B_IMAGE, K3S);
|
||||
Commons.loadSpringCloudKubernetesImage(CONFIG_WATCHER_APP_B_IMAGE, K3S);
|
||||
|
||||
Images.loadRabbitmq(K3S);
|
||||
|
||||
util = new Util(K3S);
|
||||
util.setUp(NAMESPACE);
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2013-2022 the original author or authors.
|
||||
* Copyright 2013-2024 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.
|
||||
@@ -26,6 +26,7 @@ import java.nio.file.Paths;
|
||||
import java.time.Duration;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
import com.github.dockerjava.api.command.ListImagesCmd;
|
||||
@@ -57,9 +58,9 @@ public final class Commons {
|
||||
private static final Log LOG = LogFactory.getLog(Commons.class);
|
||||
|
||||
/**
|
||||
* istio version used in our integration tests.
|
||||
* this path is generated by the pipeline of github actions.
|
||||
*/
|
||||
public static final String ISTIO_VERSION = "1.20.5";
|
||||
private static final String TMP_IMAGES = "/tmp/docker/images";
|
||||
|
||||
private Commons() {
|
||||
throw new AssertionError("No instance provided");
|
||||
@@ -90,7 +91,7 @@ public final class Commons {
|
||||
|
||||
private static final K3sContainer CONTAINER = new FixedPortsK3sContainer(DockerImageName.parse(Commons.RANCHER))
|
||||
.configureFixedPorts(EXPOSED_PORTS).withFileSystemBind(TEMP_FOLDER, TEMP_FOLDER)
|
||||
.withCommand(Commons.RANCHER_COMMAND).withReuse(true);
|
||||
.withFileSystemBind(TMP_IMAGES, TMP_IMAGES).withCommand(Commons.RANCHER_COMMAND).withReuse(true);
|
||||
|
||||
public static K3sContainer container() {
|
||||
return CONTAINER;
|
||||
@@ -166,6 +167,56 @@ public final class Commons {
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* either get the tar from '/tmp/docker/images', or pull the image.
|
||||
*/
|
||||
public static void load(K3sContainer container, String tarName, String imageNameForDownload, String imageVersion) {
|
||||
File dockerImagesRootDir = Paths.get(Commons.TMP_IMAGES).toFile();
|
||||
if (dockerImagesRootDir.exists() && dockerImagesRootDir.isDirectory()) {
|
||||
File[] tars = dockerImagesRootDir.listFiles();
|
||||
if (tars != null && tars.length > 0) {
|
||||
Optional<String> found = Arrays.stream(tars).map(File::getName).filter(x -> x.contains(tarName))
|
||||
.findFirst();
|
||||
if (found.isPresent()) {
|
||||
LOG.info("running in github actions, will load from : " + Commons.TMP_IMAGES + " tar : "
|
||||
+ found.get());
|
||||
Commons.loadImageFromPath(found.get(), container);
|
||||
return;
|
||||
}
|
||||
else {
|
||||
LOG.info(tarName + " not found, resorting to pulling the image");
|
||||
}
|
||||
}
|
||||
else {
|
||||
LOG.info("no tars found, will resort to pulling the image");
|
||||
}
|
||||
}
|
||||
else {
|
||||
LOG.info("running outside github actions");
|
||||
}
|
||||
|
||||
try {
|
||||
LOG.info("no tars found, will resort to pulling the image");
|
||||
LOG.info("using : " + imageVersion + " for : " + imageNameForDownload);
|
||||
Commons.pullImage(imageNameForDownload, imageVersion, container);
|
||||
Commons.loadImage(imageNameForDownload, imageVersion, tarName, container);
|
||||
}
|
||||
catch (Exception e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
|
||||
private static void loadImageFromPath(String tarName, K3sContainer container) {
|
||||
await().atMost(Duration.ofMinutes(2)).pollInterval(Duration.ofSeconds(1)).until(() -> {
|
||||
Container.ExecResult result = container.execInContainer("ctr", "i", "import", TMP_IMAGES + "/" + tarName);
|
||||
boolean noErrors = result.getStderr() == null || result.getStderr().isEmpty();
|
||||
if (!noErrors) {
|
||||
LOG.info("error is : " + result.getStderr());
|
||||
}
|
||||
return noErrors;
|
||||
});
|
||||
}
|
||||
|
||||
public static void cleanUp(String image, K3sContainer container) throws Exception {
|
||||
container.execInContainer("crictl", "rmi", "docker.io/springcloud/" + image + ":" + pomVersion());
|
||||
container.execInContainer("rm", TEMP_FOLDER + "/" + image + ".tar");
|
||||
|
||||
@@ -0,0 +1,101 @@
|
||||
/*
|
||||
* Copyright 2013-2024 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.cloud.kubernetes.integration.tests.commons;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.InputStreamReader;
|
||||
|
||||
import org.testcontainers.k3s.K3sContainer;
|
||||
|
||||
/**
|
||||
* @author wind57
|
||||
*/
|
||||
public final class Images {
|
||||
|
||||
private static final String BUSYBOX = "busybox";
|
||||
|
||||
private static final String BUSYBOX_TAR = BUSYBOX + ":" + busyboxVersion();
|
||||
|
||||
private static final String WIREMOCK = "wiremock/wiremock";
|
||||
|
||||
private static final String WIREMOCK_TAR = WIREMOCK.replace('/', '-') + ":" + wiremockVersion();
|
||||
|
||||
private static final String ISTIOCTL = "istio/istioctl";
|
||||
|
||||
private static final String ISTIOCTL_TAR = ISTIOCTL.replace('/', '-') + ":" + istioctlVersion();
|
||||
|
||||
private static final String KAFKA = "confluentinc/cp-kafka";
|
||||
|
||||
private static final String KAFKA_TAR = KAFKA.replace('/', '-') + kafkaVersion();
|
||||
|
||||
private static final String RABBITMQ = "rabbitmq";
|
||||
|
||||
private static final String RABBITMQ_TAR = "rabbitmq";
|
||||
|
||||
private Images() {
|
||||
|
||||
}
|
||||
|
||||
public static String busyboxVersion() {
|
||||
return imageVersion(BUSYBOX);
|
||||
}
|
||||
|
||||
public static String istioctlVersion() {
|
||||
return imageVersion(ISTIOCTL);
|
||||
}
|
||||
|
||||
public static String kafkaVersion() {
|
||||
return imageVersion(KAFKA);
|
||||
}
|
||||
|
||||
public static String rabbitMqVersion() {
|
||||
return imageVersion(RABBITMQ);
|
||||
}
|
||||
|
||||
public static String wiremockVersion() {
|
||||
return imageVersion(WIREMOCK);
|
||||
}
|
||||
|
||||
public static void loadBusybox(K3sContainer container) {
|
||||
Commons.load(container, BUSYBOX_TAR, BUSYBOX, busyboxVersion());
|
||||
}
|
||||
|
||||
public static void loadWiremock(K3sContainer container) {
|
||||
Commons.load(container, WIREMOCK_TAR, WIREMOCK, wiremockVersion());
|
||||
}
|
||||
|
||||
public static void loadIstioctl(K3sContainer container) {
|
||||
Commons.load(container, ISTIOCTL_TAR, ISTIOCTL, istioctlVersion());
|
||||
}
|
||||
|
||||
public static void loadKafka(K3sContainer container) {
|
||||
Commons.load(container, KAFKA_TAR, KAFKA, kafkaVersion());
|
||||
}
|
||||
|
||||
public static void loadRabbitmq(K3sContainer container) {
|
||||
Commons.load(container, RABBITMQ_TAR, RABBITMQ, rabbitMqVersion());
|
||||
}
|
||||
|
||||
// find the image version from current-images.txt
|
||||
private static String imageVersion(String imageNameForDownload) {
|
||||
BufferedReader reader = new BufferedReader(
|
||||
new InputStreamReader(Commons.class.getClassLoader().getResourceAsStream("current-images.txt")));
|
||||
return reader.lines().filter(line -> line.contains(imageNameForDownload)).map(line -> line.split(":")[1])
|
||||
.findFirst().orElseThrow();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -48,7 +48,7 @@ import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
import org.testcontainers.k3s.K3sContainer;
|
||||
|
||||
import org.springframework.cloud.kubernetes.integration.tests.commons.Commons;
|
||||
import org.springframework.cloud.kubernetes.integration.tests.commons.Images;
|
||||
import org.springframework.cloud.kubernetes.integration.tests.commons.Phase;
|
||||
|
||||
import static org.awaitility.Awaitility.await;
|
||||
@@ -123,6 +123,12 @@ public final class Util {
|
||||
InputStream deploymentStream = inputStream("busybox/deployment.yaml");
|
||||
InputStream serviceStream = inputStream("busybox/service.yaml");
|
||||
Deployment deployment = client.apps().deployments().load(deploymentStream).item();
|
||||
|
||||
String busyboxVersion = Images.busyboxVersion();
|
||||
String imageWithoutVersion = deployment.getSpec().getTemplate().getSpec().getContainers().get(0).getImage();
|
||||
String imageWithVersion = imageWithoutVersion + ":" + busyboxVersion;
|
||||
deployment.getSpec().getTemplate().getSpec().getContainers().get(0).setImage(imageWithVersion);
|
||||
|
||||
Service service = client.services().load(serviceStream).item();
|
||||
|
||||
if (phase.equals(Phase.CREATE)) {
|
||||
@@ -259,9 +265,10 @@ public final class Util {
|
||||
InputStream istioctlDeploymentStream = inputStream("istio/istioctl-deployment.yaml");
|
||||
Deployment istioctlDeployment = Serialization.unmarshal(istioctlDeploymentStream, Deployment.class);
|
||||
|
||||
// Ensure the version in the yaml is consistent with images we pulled.
|
||||
istioctlDeployment.getSpec().getTemplate().getSpec().getContainers().get(0)
|
||||
.setImage(ISTIO_ISTIOCTL + ":" + Commons.ISTIO_VERSION);
|
||||
String imageWithoutVersion = istioctlDeployment.getSpec().getTemplate().getSpec().getContainers().get(0)
|
||||
.getImage();
|
||||
String imageWithVersion = imageWithoutVersion + ":" + Images.istioctlVersion();
|
||||
istioctlDeployment.getSpec().getTemplate().getSpec().getContainers().get(0).setImage(imageWithVersion);
|
||||
|
||||
if (phase.equals(Phase.CREATE)) {
|
||||
createAndWait(namespace, null, istioctlDeployment, null, null, false);
|
||||
@@ -293,6 +300,10 @@ public final class Util {
|
||||
InputStream ingressStream = inputStream("wiremock/wiremock-ingress.yaml");
|
||||
|
||||
Deployment deployment = client.apps().deployments().load(deploymentStream).item();
|
||||
String imageWithoutVersion = deployment.getSpec().getTemplate().getSpec().getContainers().get(0).getImage();
|
||||
String imageWithVersion = imageWithoutVersion + ":" + Images.wiremockVersion();
|
||||
deployment.getSpec().getTemplate().getSpec().getContainers().get(0).setImage(imageWithVersion);
|
||||
|
||||
Service service = client.services().load(serviceStream).item();
|
||||
Ingress ingress = null;
|
||||
|
||||
|
||||
@@ -60,6 +60,7 @@ import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
import org.testcontainers.k3s.K3sContainer;
|
||||
|
||||
import org.springframework.cloud.kubernetes.integration.tests.commons.Images;
|
||||
import org.springframework.cloud.kubernetes.integration.tests.commons.Phase;
|
||||
|
||||
import static org.awaitility.Awaitility.await;
|
||||
@@ -233,6 +234,11 @@ public final class Util {
|
||||
|
||||
public void busybox(String namespace, Phase phase) {
|
||||
V1Deployment deployment = (V1Deployment) yaml("busybox/deployment.yaml");
|
||||
|
||||
String imageWithoutVersion = deployment.getSpec().getTemplate().getSpec().getContainers().get(0).getImage();
|
||||
String imageWithVersion = imageWithoutVersion + ":" + Images.busyboxVersion();
|
||||
deployment.getSpec().getTemplate().getSpec().getContainers().get(0).setImage(imageWithVersion);
|
||||
|
||||
V1Service service = (V1Service) yaml("busybox/service.yaml");
|
||||
if (phase.equals(Phase.CREATE)) {
|
||||
createAndWait(namespace, "busybox", deployment, service, null, false);
|
||||
@@ -244,6 +250,11 @@ public final class Util {
|
||||
|
||||
public void kafka(String namespace, Phase phase) {
|
||||
V1Deployment deployment = (V1Deployment) yaml("kafka/kafka-deployment.yaml");
|
||||
|
||||
String imageWithoutVersion = deployment.getSpec().getTemplate().getSpec().getContainers().get(0).getImage();
|
||||
String imageWithVersion = imageWithoutVersion + ":" + Images.kafkaVersion();
|
||||
deployment.getSpec().getTemplate().getSpec().getContainers().get(0).setImage(imageWithVersion);
|
||||
|
||||
V1Service service = (V1Service) yaml("kafka/kafka-service.yaml");
|
||||
V1ConfigMap configMap = (V1ConfigMap) yaml("kafka/kafka-configmap-startup-script.yaml");
|
||||
|
||||
@@ -259,6 +270,11 @@ public final class Util {
|
||||
|
||||
public void rabbitMq(String namespace, Phase phase) {
|
||||
V1Deployment deployment = (V1Deployment) yaml("rabbitmq/rabbitmq-deployment.yaml");
|
||||
|
||||
String imageWithoutVersion = deployment.getSpec().getTemplate().getSpec().getContainers().get(0).getImage();
|
||||
String imageWithVersion = imageWithoutVersion + ":" + Images.rabbitMqVersion();
|
||||
deployment.getSpec().getTemplate().getSpec().getContainers().get(0).setImage(imageWithVersion);
|
||||
|
||||
V1Service service = (V1Service) yaml("rabbitmq/rabbitmq-service.yaml");
|
||||
|
||||
if (phase.equals(Phase.CREATE)) {
|
||||
@@ -430,6 +446,11 @@ public final class Util {
|
||||
|
||||
public void wiremock(String namespace, String path, Phase phase, boolean withIngress) {
|
||||
V1Deployment deployment = (V1Deployment) yaml("wiremock/wiremock-deployment.yaml");
|
||||
|
||||
String imageWithoutVersion = deployment.getSpec().getTemplate().getSpec().getContainers().get(0).getImage();
|
||||
String imageWithVersion = imageWithoutVersion + ":" + Images.wiremockVersion();
|
||||
deployment.getSpec().getTemplate().getSpec().getContainers().get(0).setImage(imageWithVersion);
|
||||
|
||||
V1Service service = (V1Service) yaml("wiremock/wiremock-service.yaml");
|
||||
|
||||
V1Ingress ingress = null;
|
||||
|
||||
@@ -17,6 +17,6 @@ spec:
|
||||
containers:
|
||||
- name: busybox
|
||||
# image: arm64/busybox:latest
|
||||
image: busybox:1.35
|
||||
image: busybox
|
||||
command: ["/bin/sh"]
|
||||
args: ["-c", "sleep 100000"]
|
||||
|
||||
@@ -0,0 +1,5 @@
|
||||
busybox:1.36.1
|
||||
istio/istioctl:1.20.5
|
||||
confluentinc/cp-kafka:7.2.1
|
||||
rabbitmq:3-management
|
||||
wiremock/wiremock:3.4.2
|
||||
@@ -15,7 +15,7 @@ spec:
|
||||
spec:
|
||||
containers:
|
||||
- name: istio-ctl
|
||||
image: istio/istioctl:1.20.5
|
||||
image: istio/istioctl
|
||||
imagePullPolicy: IfNotPresent
|
||||
command: [ "/bin/bash" ]
|
||||
args: [ "-c", "trap : TERM INT; sleep infinity & wait" ]
|
||||
|
||||
@@ -33,7 +33,7 @@ spec:
|
||||
mountPath: /tmp
|
||||
command:
|
||||
- /tmp/kafka_start.sh
|
||||
image: confluentinc/cp-kafka:7.2.1
|
||||
image: confluentinc/cp-kafka
|
||||
ports:
|
||||
- containerPort: 9092
|
||||
env:
|
||||
|
||||
@@ -18,7 +18,7 @@ spec:
|
||||
spec:
|
||||
containers:
|
||||
- name: taskqueue
|
||||
image: rabbitmq:3-management
|
||||
image: rabbitmq
|
||||
imagePullPolicy: IfNotPresent
|
||||
|
||||
|
||||
|
||||
@@ -13,7 +13,7 @@ spec:
|
||||
spec:
|
||||
containers:
|
||||
- name: service-wiremock
|
||||
image: wiremock/wiremock:3.4.2
|
||||
image: wiremock/wiremock
|
||||
args: ["--verbose"]
|
||||
imagePullPolicy: IfNotPresent
|
||||
readinessProbe:
|
||||
|
||||
Reference in New Issue
Block a user