Skip to content

Commit

Permalink
Clean docker image cache (#1636)
Browse files Browse the repository at this point in the history
  • Loading branch information
wind57 authored Apr 17, 2024
1 parent c7c4220 commit 013b920
Show file tree
Hide file tree
Showing 26 changed files with 283 additions and 48 deletions.
1 change: 0 additions & 1 deletion .github/workflows/composites/env-variables/action.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
3 changes: 3 additions & 0 deletions .github/workflows/composites/pre-test-actions/action.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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: |
Expand Down
42 changes: 42 additions & 0 deletions .github/workflows/composites/restore-docker-images/action.yaml
Original file line number Diff line number Diff line change
@@ -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
19 changes: 0 additions & 19 deletions .github/workflows/composites/upload-docker-images/action.yaml

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@

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;
Expand Down Expand Up @@ -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());

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@

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;
Expand Down Expand Up @@ -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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@

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;
Expand Down Expand Up @@ -73,6 +74,8 @@ static void beforeAll() throws Exception {
Commons.validateImage(IMAGE_NAME, K3S);
Commons.loadSpringCloudKubernetesImage(IMAGE_NAME, K3S);

Images.loadBusybox(K3S);

util = new Util(K3S);

util.createNamespace(NAMESPACE_A);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@

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;
Expand Down Expand Up @@ -92,6 +93,9 @@ static void beforeAll() throws Exception {
Commons.validateImage(IMAGE_NAME, K3S);
Commons.loadSpringCloudKubernetesImage(IMAGE_NAME, K3S);

Images.loadBusybox(K3S);
Images.loadWiremock(K3S);

util = new Util(K3S);
client = util.client();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,14 +35,14 @@
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;
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
Expand All @@ -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;
Expand All @@ -69,12 +65,7 @@ static void beforeAll() throws Exception {
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);

This comment has been minimized.

Copy link
@ryanjbaxter

ryanjbaxter Apr 29, 2024

Contributor

@wind57 I think we need to revert this and go back to loading the images into the container. This causes a problem for us on Jenkins where k8s is not authenticated and eventually runs into 429 errors from docker hub.

E0429 19:23:54.965497      44 pod_workers.go:1300] "Error syncing pod, skipping" err="failed to \"StartContainer\" for \"discovery\" with ErrImagePull: \"failed to pull and unpack image \\\"docker.io/istio/pilot:1.20.5\\\": failed to copy: httpReadSeeker: failed open: unexpected status code https://registry-1.docker.io/v2/istio/pilot/manifests/sha256:2976cd482914d05ddca77152967ac57a4cf4b3f3705c83c6ee70bfa094be55b5: 429 Too Many Requests - Server message: toomanyrequests: You have reached your pull rate limit. You may increase the limit by authenticating and upgrading: https://www.docker.com/increase-rate-limit\"" pod="istio-system/istiod-86489f7989-ljrxr" podUID="3b118209-41cf-4461-871a-bf22334d5bc5"

Pulling and loading the images in the test avoids this

This comment has been minimized.

Copy link
@ryanjbaxter

ryanjbaxter Apr 29, 2024

Contributor

Well I guess when we call loadIstioctl we not only need to load istioctl but also proxy and pilot

Images.loadIstioctl(K3S);

processExecResult(K3S.execInContainer("sh", "-c", "kubectl create namespace istio-test"));
processExecResult(
Expand Down Expand Up @@ -127,6 +118,7 @@ private static void appManifests(Phase phase) {
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);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@

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;
Expand Down Expand Up @@ -75,6 +76,9 @@ static void beforeAll() throws Exception {
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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
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;

Expand Down Expand Up @@ -66,6 +67,9 @@ static void beforeAll() throws Exception {
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);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@

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;
Expand Down Expand Up @@ -153,6 +154,8 @@ static void beforeAll() throws Exception {
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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
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;
Expand Down Expand Up @@ -80,6 +81,9 @@ static void beforeAll() throws Exception {
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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@

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;
Expand Down Expand Up @@ -79,6 +80,8 @@ static void beforeAll() throws Exception {
Commons.validateImage(IMAGE_NAME, K3S);
Commons.loadSpringCloudKubernetesImage(IMAGE_NAME, K3S);

Images.loadWiremock(K3S);

util = new Util(K3S);

util.createNamespace(NAMESPACE_A);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
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;
Expand Down Expand Up @@ -77,6 +78,8 @@ static void beforeAll() throws Exception {
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);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
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;
Expand Down Expand Up @@ -76,6 +77,8 @@ static void beforeAll() throws Exception {
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);
}
Expand Down
Loading

0 comments on commit 013b920

Please sign in to comment.