From 982897e8a6fcbe61f6a1fc52d8bad2c93de22159 Mon Sep 17 00:00:00 2001 From: mpeddada1 Date: Thu, 6 Jun 2024 21:53:48 +0000 Subject: [PATCH 01/45] fix: allow pushing images with different arch/os to docker daemon --- .../tools/jib/api/JibIntegrationTest.java | 24 +++++------ .../tools/jib/builder/steps/StepsRunner.java | 28 ++++++------- .../jib/builder/steps/StepsRunnerTest.java | 41 +++++++++++++++---- 3 files changed, 56 insertions(+), 37 deletions(-) diff --git a/jib-core/src/integration-test/java/com/google/cloud/tools/jib/api/JibIntegrationTest.java b/jib-core/src/integration-test/java/com/google/cloud/tools/jib/api/JibIntegrationTest.java index 4e49d1e12d..2f60763dc5 100644 --- a/jib-core/src/integration-test/java/com/google/cloud/tools/jib/api/JibIntegrationTest.java +++ b/jib-core/src/integration-test/java/com/google/cloud/tools/jib/api/JibIntegrationTest.java @@ -343,13 +343,9 @@ public void testBasicMultiPlatform_toDockerDaemon() } @Test - public void testBasicMultiPlatform_toDockerDaemon_noMatchingImage() { - ExecutionException exception = - assertThrows( - ExecutionException.class, - () -> - Jib.from( - RegistryImage.named( + public void testBasicMultiPlatform_toDockerDaemon_pickFirstPlatformWhenNoMatchingImage() throws IOException, InterruptedException, InvalidImageReferenceException, CacheDirectoryCreationException, ExecutionException, RegistryException { + Jib.from( + RegistryImage.named( "busybox@sha256:4f47c01fa91355af2865ac10fef5bf6ec9c7f42ad2321377c21e844427972977")) .setPlatforms( ImmutableSet.of( @@ -359,11 +355,15 @@ public void testBasicMultiPlatform_toDockerDaemon_noMatchingImage() { Containerizer.to( DockerDaemonImage.named( dockerHost + ":5000/docker-daemon-multi-platform")) - .setAllowInsecureRegistries(true))); - assertThat(exception) - .hasCauseThat() - .hasMessageThat() - .startsWith("The configured platforms don't match the Docker Engine's OS and architecture"); + .setAllowInsecureRegistries(true)); + String os = + new Command("docker", "inspect", dockerHost + ":5000/docker-daemon-multi-platform", "--format", "{{.Os}}") + .run().replace("\n", ""); + String architecture = + new Command("docker", "inspect", dockerHost + ":5000/docker-daemon-multi-platform", "--format", "{{.Architecture}}") + .run().replace("\n", ""); + assertThat(os).isEqualTo("linux"); + assertThat(architecture).isEqualTo("s390x"); } @Test diff --git a/jib-core/src/main/java/com/google/cloud/tools/jib/builder/steps/StepsRunner.java b/jib-core/src/main/java/com/google/cloud/tools/jib/builder/steps/StepsRunner.java index be760a13eb..4c3e8adac2 100644 --- a/jib-core/src/main/java/com/google/cloud/tools/jib/builder/steps/StepsRunner.java +++ b/jib-core/src/main/java/com/google/cloud/tools/jib/builder/steps/StepsRunner.java @@ -624,14 +624,9 @@ private void loadDocker( DockerInfoDetails dockerInfoDetails = dockerClient.info(); String osType = dockerInfoDetails.getOsType(); String architecture = normalizeArchitecture(dockerInfoDetails.getArchitecture()); - Optional builtImage = fetchBuiltImageForLocalBuild(osType, architecture); - Preconditions.checkState( - builtImage.isPresent(), - String.format( - "The configured platforms don't match the Docker Engine's OS and architecture (%s/%s)", - osType, architecture)); + Image builtImage = fetchBuiltImageForLocalBuild(osType, architecture); return new LoadDockerStep( - buildContext, progressDispatcherFactory, dockerClient, builtImage.get()) + buildContext, progressDispatcherFactory, dockerClient, builtImage) .call(); }); } @@ -669,21 +664,22 @@ String normalizeArchitecture(String architecture) { } @VisibleForTesting - Optional fetchBuiltImageForLocalBuild(String osType, String architecture) + Image fetchBuiltImageForLocalBuild(String osType, String architecture) throws InterruptedException, ExecutionException { if (results.baseImagesAndBuiltImages.get().size() > 1) { LOGGER.warning( String.format( - "Detected multi-platform configuration, only building the one that matches the local Docker Engine's os and architecture (%s/%s)", + "Detected multi-platform configuration, only building the one that matches the local Docker Engine's os and architecture (%s/%s) or " + + "the first platform specified", osType, architecture)); - } - for (Map.Entry> imageEntry : - results.baseImagesAndBuiltImages.get().entrySet()) { - Image image = imageEntry.getValue().get(); - if (image.getArchitecture().equals(architecture) && image.getOs().equals(osType)) { - return Optional.of(image); + for (Map.Entry> imageEntry : + results.baseImagesAndBuiltImages.get().entrySet()) { + Image image = imageEntry.getValue().get(); + if (image.getArchitecture().equals(architecture) && image.getOs().equals(osType)) { + return image; + } } } - return Optional.empty(); + return results.baseImagesAndBuiltImages.get().values().iterator().next().get(); } } diff --git a/jib-core/src/test/java/com/google/cloud/tools/jib/builder/steps/StepsRunnerTest.java b/jib-core/src/test/java/com/google/cloud/tools/jib/builder/steps/StepsRunnerTest.java index 9436c7df4a..4e854afa92 100644 --- a/jib-core/src/test/java/com/google/cloud/tools/jib/builder/steps/StepsRunnerTest.java +++ b/jib-core/src/test/java/com/google/cloud/tools/jib/builder/steps/StepsRunnerTest.java @@ -203,14 +203,14 @@ public void testFetchBuildImageForLocalBuild_matchingOsAndArch() Futures.immediateFuture(builtAmd64AndWindowsImage)))); stepsRunner.buildImages(progressDispatcherFactory); - Optional expectedImage = stepsRunner.fetchBuiltImageForLocalBuild("windows", "amd64"); + Image expectedImage = stepsRunner.fetchBuiltImageForLocalBuild("windows", "amd64"); - assertThat(expectedImage.get().getOs()).isEqualTo("windows"); - assertThat(expectedImage.get().getArchitecture()).isEqualTo("amd64"); + assertThat(expectedImage.getOs()).isEqualTo("windows"); + assertThat(expectedImage.getArchitecture()).isEqualTo("amd64"); } @Test - public void testFetchBuildImageForLocalBuild_differentOs() + public void testFetchBuildImageForLocalBuild_differentOs_buildImageForFirstPlatform() throws ExecutionException, InterruptedException { when(builtArm64AndLinuxImage.getArchitecture()).thenReturn("arm64"); when(builtArm64AndLinuxImage.getOs()).thenReturn("linux"); @@ -225,13 +225,15 @@ public void testFetchBuildImageForLocalBuild_differentOs() Futures.immediateFuture(builtAmd64AndWindowsImage)))); stepsRunner.buildImages(progressDispatcherFactory); - Optional expectedImage = stepsRunner.fetchBuiltImageForLocalBuild("os", "arm64"); + Image expectedImage = stepsRunner.fetchBuiltImageForLocalBuild("os", "arm64"); + + assertThat(expectedImage.getOs()).isEqualTo("linux"); + assertThat(expectedImage.getArchitecture()).isEqualTo("arm64"); - assertThat(expectedImage.isPresent()).isFalse(); } @Test - public void testFetchBuildImageForLocalBuild_differentArch() + public void testFetchBuildImageForLocalBuild_differentArch_buildImageForFirstPlatform() throws ExecutionException, InterruptedException { when(builtArm64AndLinuxImage.getArchitecture()).thenReturn("arm64"); when(builtAmd64AndWindowsImage.getArchitecture()).thenReturn("amd64"); @@ -245,9 +247,30 @@ public void testFetchBuildImageForLocalBuild_differentArch() Futures.immediateFuture(builtAmd64AndWindowsImage)))); stepsRunner.buildImages(progressDispatcherFactory); - Optional expectedImage = stepsRunner.fetchBuiltImageForLocalBuild("linux", "arch"); + Image expectedImage = stepsRunner.fetchBuiltImageForLocalBuild("linux", "arch"); + + assertThat(expectedImage.getArchitecture()).isEqualTo("arm64"); + } + + @Test + public void testFetchBuildImageForLocalBuild_singleImage_imagePlatformDifferentFromDockerEnv() + throws ExecutionException, InterruptedException { + when(builtArm64AndLinuxImage.getArchitecture()).thenReturn("arm64"); + when(builtArm64AndLinuxImage.getOs()).thenReturn("linux"); + + when(builtAmd64AndWindowsImage.getOs()).thenReturn("linux"); + when(executorService.submit(Mockito.any(Callable.class))) + .thenReturn( + Futures.immediateFuture( + ImmutableMap.of( + baseImage1, + Futures.immediateFuture(builtArm64AndLinuxImage)))); + stepsRunner.buildImages(progressDispatcherFactory); + + Image expectedImage = stepsRunner.fetchBuiltImageForLocalBuild("linux", "amd64"); - assertThat(expectedImage.isPresent()).isFalse(); + assertThat(expectedImage.getOs()).isEqualTo("linux"); + assertThat(expectedImage.getArchitecture()).isEqualTo("arm64"); } @Test From ffc4df760b0b74f3615a95db2010cfdb7f2c4283 Mon Sep 17 00:00:00 2001 From: mpeddada1 Date: Thu, 6 Jun 2024 23:23:34 +0000 Subject: [PATCH 02/45] fix formatting --- .../tools/jib/api/JibIntegrationTest.java | 44 ++++++++++++------- .../tools/jib/builder/steps/StepsRunner.java | 6 +-- .../jib/builder/steps/StepsRunnerTest.java | 11 ++--- 3 files changed, 34 insertions(+), 27 deletions(-) diff --git a/jib-core/src/integration-test/java/com/google/cloud/tools/jib/api/JibIntegrationTest.java b/jib-core/src/integration-test/java/com/google/cloud/tools/jib/api/JibIntegrationTest.java index 2f60763dc5..61b72a2d9a 100644 --- a/jib-core/src/integration-test/java/com/google/cloud/tools/jib/api/JibIntegrationTest.java +++ b/jib-core/src/integration-test/java/com/google/cloud/tools/jib/api/JibIntegrationTest.java @@ -17,7 +17,6 @@ package com.google.cloud.tools.jib.api; import static com.google.common.truth.Truth.assertThat; -import static org.junit.Assert.assertThrows; import com.google.cloud.tools.jib.Command; import com.google.cloud.tools.jib.api.buildplan.Platform; @@ -343,25 +342,36 @@ public void testBasicMultiPlatform_toDockerDaemon() } @Test - public void testBasicMultiPlatform_toDockerDaemon_pickFirstPlatformWhenNoMatchingImage() throws IOException, InterruptedException, InvalidImageReferenceException, CacheDirectoryCreationException, ExecutionException, RegistryException { + public void testBasicMultiPlatform_toDockerDaemon_pickFirstPlatformWhenNoMatchingImage() + throws IOException, InterruptedException, InvalidImageReferenceException, + CacheDirectoryCreationException, ExecutionException, RegistryException { Jib.from( - RegistryImage.named( - "busybox@sha256:4f47c01fa91355af2865ac10fef5bf6ec9c7f42ad2321377c21e844427972977")) - .setPlatforms( - ImmutableSet.of( - new Platform("s390x", "linux"), new Platform("arm", "linux"))) - .setEntrypoint("echo", "Hello World") - .containerize( - Containerizer.to( - DockerDaemonImage.named( - dockerHost + ":5000/docker-daemon-multi-platform")) - .setAllowInsecureRegistries(true)); + RegistryImage.named( + "busybox@sha256:4f47c01fa91355af2865ac10fef5bf6ec9c7f42ad2321377c21e844427972977")) + .setPlatforms(ImmutableSet.of(new Platform("s390x", "linux"), new Platform("arm", "linux"))) + .setEntrypoint("echo", "Hello World") + .containerize( + Containerizer.to( + DockerDaemonImage.named(dockerHost + ":5000/docker-daemon-multi-platform")) + .setAllowInsecureRegistries(true)); String os = - new Command("docker", "inspect", dockerHost + ":5000/docker-daemon-multi-platform", "--format", "{{.Os}}") - .run().replace("\n", ""); + new Command( + "docker", + "inspect", + dockerHost + ":5000/docker-daemon-multi-platform", + "--format", + "{{.Os}}") + .run() + .replace("\n", ""); String architecture = - new Command("docker", "inspect", dockerHost + ":5000/docker-daemon-multi-platform", "--format", "{{.Architecture}}") - .run().replace("\n", ""); + new Command( + "docker", + "inspect", + dockerHost + ":5000/docker-daemon-multi-platform", + "--format", + "{{.Architecture}}") + .run() + .replace("\n", ""); assertThat(os).isEqualTo("linux"); assertThat(architecture).isEqualTo("s390x"); } diff --git a/jib-core/src/main/java/com/google/cloud/tools/jib/builder/steps/StepsRunner.java b/jib-core/src/main/java/com/google/cloud/tools/jib/builder/steps/StepsRunner.java index 4c3e8adac2..ba35eea77d 100644 --- a/jib-core/src/main/java/com/google/cloud/tools/jib/builder/steps/StepsRunner.java +++ b/jib-core/src/main/java/com/google/cloud/tools/jib/builder/steps/StepsRunner.java @@ -669,11 +669,11 @@ Image fetchBuiltImageForLocalBuild(String osType, String architecture) if (results.baseImagesAndBuiltImages.get().size() > 1) { LOGGER.warning( String.format( - "Detected multi-platform configuration, only building the one that matches the local Docker Engine's os and architecture (%s/%s) or " + - "the first platform specified", + "Detected multi-platform configuration, only building the one that matches the local Docker Engine's os and architecture (%s/%s) or " + + "the first platform specified", osType, architecture)); for (Map.Entry> imageEntry : - results.baseImagesAndBuiltImages.get().entrySet()) { + results.baseImagesAndBuiltImages.get().entrySet()) { Image image = imageEntry.getValue().get(); if (image.getArchitecture().equals(architecture) && image.getOs().equals(osType)) { return image; diff --git a/jib-core/src/test/java/com/google/cloud/tools/jib/builder/steps/StepsRunnerTest.java b/jib-core/src/test/java/com/google/cloud/tools/jib/builder/steps/StepsRunnerTest.java index 4e854afa92..5e4b0e040d 100644 --- a/jib-core/src/test/java/com/google/cloud/tools/jib/builder/steps/StepsRunnerTest.java +++ b/jib-core/src/test/java/com/google/cloud/tools/jib/builder/steps/StepsRunnerTest.java @@ -229,7 +229,6 @@ public void testFetchBuildImageForLocalBuild_differentOs_buildImageForFirstPlatf assertThat(expectedImage.getOs()).isEqualTo("linux"); assertThat(expectedImage.getArchitecture()).isEqualTo("arm64"); - } @Test @@ -254,17 +253,15 @@ public void testFetchBuildImageForLocalBuild_differentArch_buildImageForFirstPla @Test public void testFetchBuildImageForLocalBuild_singleImage_imagePlatformDifferentFromDockerEnv() - throws ExecutionException, InterruptedException { + throws ExecutionException, InterruptedException { when(builtArm64AndLinuxImage.getArchitecture()).thenReturn("arm64"); when(builtArm64AndLinuxImage.getOs()).thenReturn("linux"); when(builtAmd64AndWindowsImage.getOs()).thenReturn("linux"); when(executorService.submit(Mockito.any(Callable.class))) - .thenReturn( - Futures.immediateFuture( - ImmutableMap.of( - baseImage1, - Futures.immediateFuture(builtArm64AndLinuxImage)))); + .thenReturn( + Futures.immediateFuture( + ImmutableMap.of(baseImage1, Futures.immediateFuture(builtArm64AndLinuxImage)))); stepsRunner.buildImages(progressDispatcherFactory); Image expectedImage = stepsRunner.fetchBuiltImageForLocalBuild("linux", "amd64"); From f2d886b289a2e0d471f37281ce23322e00e6a288 Mon Sep 17 00:00:00 2001 From: mpeddada1 Date: Thu, 6 Jun 2024 23:29:28 +0000 Subject: [PATCH 03/45] stubbing --- .../google/cloud/tools/jib/builder/steps/StepsRunnerTest.java | 2 -- 1 file changed, 2 deletions(-) diff --git a/jib-core/src/test/java/com/google/cloud/tools/jib/builder/steps/StepsRunnerTest.java b/jib-core/src/test/java/com/google/cloud/tools/jib/builder/steps/StepsRunnerTest.java index 5e4b0e040d..54154ff751 100644 --- a/jib-core/src/test/java/com/google/cloud/tools/jib/builder/steps/StepsRunnerTest.java +++ b/jib-core/src/test/java/com/google/cloud/tools/jib/builder/steps/StepsRunnerTest.java @@ -256,8 +256,6 @@ public void testFetchBuildImageForLocalBuild_singleImage_imagePlatformDifferentF throws ExecutionException, InterruptedException { when(builtArm64AndLinuxImage.getArchitecture()).thenReturn("arm64"); when(builtArm64AndLinuxImage.getOs()).thenReturn("linux"); - - when(builtAmd64AndWindowsImage.getOs()).thenReturn("linux"); when(executorService.submit(Mockito.any(Callable.class))) .thenReturn( Futures.immediateFuture( From 9ff90bd4cf8aea53db7bfea31f7aa265550f5cd0 Mon Sep 17 00:00:00 2001 From: mpeddada1 Date: Fri, 7 Jun 2024 14:45:39 +0000 Subject: [PATCH 04/45] add test for arm64 image --- .../tools/jib/api/JibIntegrationTest.java | 34 ++++++++++++++++++- 1 file changed, 33 insertions(+), 1 deletion(-) diff --git a/jib-core/src/integration-test/java/com/google/cloud/tools/jib/api/JibIntegrationTest.java b/jib-core/src/integration-test/java/com/google/cloud/tools/jib/api/JibIntegrationTest.java index 61b72a2d9a..d1d63dd408 100644 --- a/jib-core/src/integration-test/java/com/google/cloud/tools/jib/api/JibIntegrationTest.java +++ b/jib-core/src/integration-test/java/com/google/cloud/tools/jib/api/JibIntegrationTest.java @@ -320,6 +320,39 @@ public void testBasic_jibImageToDockerDaemon() Assert.assertEquals("Hello World\n", output); } + @Test + public void testBasic_jibImageToDockerDaemon_arm64() + throws IOException, InterruptedException, InvalidImageReferenceException, ExecutionException, + RegistryException, CacheDirectoryCreationException { + Jib.from( + RegistryImage.named( + "busybox@sha256:eb427d855f82782c110b48b9a398556c629ce4951ae252c6f6751a136e194668")) + .containerize( + Containerizer.to( + DockerDaemonImage.named(dockerHost + ":5000/docker-daemon-mismatched-arch"))); + + String os = + new Command( + "docker", + "inspect", + dockerHost + ":5000/docker-daemon-mismatched-arch", + "--format", + "{{.Os}}") + .run() + .replace("\n", ""); + String architecture = + new Command( + "docker", + "inspect", + dockerHost + ":5000/docker-daemon-mismatched-arch", + "--format", + "{{.Architecture}}") + .run() + .replace("\n", ""); + assertThat(os).isEqualTo("linux"); + assertThat(architecture).isEqualTo("arm64"); + } + @Test public void testBasicMultiPlatform_toDockerDaemon() throws IOException, InterruptedException, ExecutionException, RegistryException, @@ -349,7 +382,6 @@ public void testBasicMultiPlatform_toDockerDaemon_pickFirstPlatformWhenNoMatchin RegistryImage.named( "busybox@sha256:4f47c01fa91355af2865ac10fef5bf6ec9c7f42ad2321377c21e844427972977")) .setPlatforms(ImmutableSet.of(new Platform("s390x", "linux"), new Platform("arm", "linux"))) - .setEntrypoint("echo", "Hello World") .containerize( Containerizer.to( DockerDaemonImage.named(dockerHost + ":5000/docker-daemon-multi-platform")) From 62ef48462be5e4367ce2920cf0484f4260abe0ad Mon Sep 17 00:00:00 2001 From: mpeddada1 Date: Mon, 10 Jun 2024 15:39:29 +0000 Subject: [PATCH 05/45] choose more detailed image name --- .../com/google/cloud/tools/jib/api/JibIntegrationTest.java | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/jib-core/src/integration-test/java/com/google/cloud/tools/jib/api/JibIntegrationTest.java b/jib-core/src/integration-test/java/com/google/cloud/tools/jib/api/JibIntegrationTest.java index d1d63dd408..f077c1dd6c 100644 --- a/jib-core/src/integration-test/java/com/google/cloud/tools/jib/api/JibIntegrationTest.java +++ b/jib-core/src/integration-test/java/com/google/cloud/tools/jib/api/JibIntegrationTest.java @@ -384,13 +384,14 @@ public void testBasicMultiPlatform_toDockerDaemon_pickFirstPlatformWhenNoMatchin .setPlatforms(ImmutableSet.of(new Platform("s390x", "linux"), new Platform("arm", "linux"))) .containerize( Containerizer.to( - DockerDaemonImage.named(dockerHost + ":5000/docker-daemon-multi-platform")) + DockerDaemonImage.named( + dockerHost + ":5000/docker-daemon-multi-plat-mismatched-configs")) .setAllowInsecureRegistries(true)); String os = new Command( "docker", "inspect", - dockerHost + ":5000/docker-daemon-multi-platform", + dockerHost + ":5000/docker-daemon-multi-plat-mismatched-configs", "--format", "{{.Os}}") .run() @@ -399,7 +400,7 @@ public void testBasicMultiPlatform_toDockerDaemon_pickFirstPlatformWhenNoMatchin new Command( "docker", "inspect", - dockerHost + ":5000/docker-daemon-multi-platform", + dockerHost + ":5000/docker-daemon-multi-plat-mismatched-configs", "--format", "{{.Architecture}}") .run() From 49e84f163251d209bb1a9f3e3dc111815e25b71e Mon Sep 17 00:00:00 2001 From: mpeddada1 Date: Mon, 10 Jun 2024 16:14:37 +0000 Subject: [PATCH 06/45] temporarily comment out arm64 test --- .../tools/jib/api/JibIntegrationTest.java | 55 ++++++++++--------- 1 file changed, 28 insertions(+), 27 deletions(-) diff --git a/jib-core/src/integration-test/java/com/google/cloud/tools/jib/api/JibIntegrationTest.java b/jib-core/src/integration-test/java/com/google/cloud/tools/jib/api/JibIntegrationTest.java index f077c1dd6c..ed7cd8adbb 100644 --- a/jib-core/src/integration-test/java/com/google/cloud/tools/jib/api/JibIntegrationTest.java +++ b/jib-core/src/integration-test/java/com/google/cloud/tools/jib/api/JibIntegrationTest.java @@ -324,33 +324,34 @@ public void testBasic_jibImageToDockerDaemon() public void testBasic_jibImageToDockerDaemon_arm64() throws IOException, InterruptedException, InvalidImageReferenceException, ExecutionException, RegistryException, CacheDirectoryCreationException { - Jib.from( - RegistryImage.named( - "busybox@sha256:eb427d855f82782c110b48b9a398556c629ce4951ae252c6f6751a136e194668")) - .containerize( - Containerizer.to( - DockerDaemonImage.named(dockerHost + ":5000/docker-daemon-mismatched-arch"))); - - String os = - new Command( - "docker", - "inspect", - dockerHost + ":5000/docker-daemon-mismatched-arch", - "--format", - "{{.Os}}") - .run() - .replace("\n", ""); - String architecture = - new Command( - "docker", - "inspect", - dockerHost + ":5000/docker-daemon-mismatched-arch", - "--format", - "{{.Architecture}}") - .run() - .replace("\n", ""); - assertThat(os).isEqualTo("linux"); - assertThat(architecture).isEqualTo("arm64"); + // Jib.from( + // RegistryImage.named( + // + // "busybox@sha256:eb427d855f82782c110b48b9a398556c629ce4951ae252c6f6751a136e194668")) + // .containerize( + // Containerizer.to( + // DockerDaemonImage.named(dockerHost + ":5000/docker-daemon-mismatched-arch"))); + // + // String os = + // new Command( + // "docker", + // "inspect", + // dockerHost + ":5000/docker-daemon-mismatched-arch", + // "--format", + // "{{.Os}}") + // .run() + // .replace("\n", ""); + // String architecture = + // new Command( + // "docker", + // "inspect", + // dockerHost + ":5000/docker-daemon-mismatched-arch", + // "--format", + // "{{.Architecture}}") + // .run() + // .replace("\n", ""); + // assertThat(os).isEqualTo("linux"); + // assertThat(architecture).isEqualTo("arm64"); } @Test From 4b62074b8e3ba5c249b2f56042dadd44e7af2e36 Mon Sep 17 00:00:00 2001 From: mpeddada1 Date: Mon, 10 Jun 2024 19:54:42 +0000 Subject: [PATCH 07/45] fix formatting --- .../tools/jib/api/JibIntegrationTest.java | 55 +++++++++---------- 1 file changed, 27 insertions(+), 28 deletions(-) diff --git a/jib-core/src/integration-test/java/com/google/cloud/tools/jib/api/JibIntegrationTest.java b/jib-core/src/integration-test/java/com/google/cloud/tools/jib/api/JibIntegrationTest.java index ed7cd8adbb..f077c1dd6c 100644 --- a/jib-core/src/integration-test/java/com/google/cloud/tools/jib/api/JibIntegrationTest.java +++ b/jib-core/src/integration-test/java/com/google/cloud/tools/jib/api/JibIntegrationTest.java @@ -324,34 +324,33 @@ public void testBasic_jibImageToDockerDaemon() public void testBasic_jibImageToDockerDaemon_arm64() throws IOException, InterruptedException, InvalidImageReferenceException, ExecutionException, RegistryException, CacheDirectoryCreationException { - // Jib.from( - // RegistryImage.named( - // - // "busybox@sha256:eb427d855f82782c110b48b9a398556c629ce4951ae252c6f6751a136e194668")) - // .containerize( - // Containerizer.to( - // DockerDaemonImage.named(dockerHost + ":5000/docker-daemon-mismatched-arch"))); - // - // String os = - // new Command( - // "docker", - // "inspect", - // dockerHost + ":5000/docker-daemon-mismatched-arch", - // "--format", - // "{{.Os}}") - // .run() - // .replace("\n", ""); - // String architecture = - // new Command( - // "docker", - // "inspect", - // dockerHost + ":5000/docker-daemon-mismatched-arch", - // "--format", - // "{{.Architecture}}") - // .run() - // .replace("\n", ""); - // assertThat(os).isEqualTo("linux"); - // assertThat(architecture).isEqualTo("arm64"); + Jib.from( + RegistryImage.named( + "busybox@sha256:eb427d855f82782c110b48b9a398556c629ce4951ae252c6f6751a136e194668")) + .containerize( + Containerizer.to( + DockerDaemonImage.named(dockerHost + ":5000/docker-daemon-mismatched-arch"))); + + String os = + new Command( + "docker", + "inspect", + dockerHost + ":5000/docker-daemon-mismatched-arch", + "--format", + "{{.Os}}") + .run() + .replace("\n", ""); + String architecture = + new Command( + "docker", + "inspect", + dockerHost + ":5000/docker-daemon-mismatched-arch", + "--format", + "{{.Architecture}}") + .run() + .replace("\n", ""); + assertThat(os).isEqualTo("linux"); + assertThat(architecture).isEqualTo("arm64"); } @Test From 6a8d80924a0afdef8523e6f8a662d2b090151ddc Mon Sep 17 00:00:00 2001 From: mpeddada1 Date: Mon, 10 Jun 2024 20:49:07 +0000 Subject: [PATCH 08/45] use different base image --- .../com/google/cloud/tools/jib/api/JibIntegrationTest.java | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/jib-core/src/integration-test/java/com/google/cloud/tools/jib/api/JibIntegrationTest.java b/jib-core/src/integration-test/java/com/google/cloud/tools/jib/api/JibIntegrationTest.java index f077c1dd6c..7045d9c915 100644 --- a/jib-core/src/integration-test/java/com/google/cloud/tools/jib/api/JibIntegrationTest.java +++ b/jib-core/src/integration-test/java/com/google/cloud/tools/jib/api/JibIntegrationTest.java @@ -324,9 +324,14 @@ public void testBasic_jibImageToDockerDaemon() public void testBasic_jibImageToDockerDaemon_arm64() throws IOException, InterruptedException, InvalidImageReferenceException, ExecutionException, RegistryException, CacheDirectoryCreationException { + // Use arm64v8/busybox as base image. Jib.from( RegistryImage.named( - "busybox@sha256:eb427d855f82782c110b48b9a398556c629ce4951ae252c6f6751a136e194668")) + "busybox@sha256:4f47c01fa91355af2865ac10fef5bf6ec9c7f42ad2321377c21e844427972977") + // RegistryImage.named( + // + // "busybox@sha256:eb427d855f82782c110b48b9a398556c629ce4951ae252c6f6751a136e194668") + ) .containerize( Containerizer.to( DockerDaemonImage.named(dockerHost + ":5000/docker-daemon-mismatched-arch"))); From ba4cfdf195082c7defa3b6d18a5bea77e80dfebf Mon Sep 17 00:00:00 2001 From: mpeddada1 Date: Mon, 10 Jun 2024 21:27:07 +0000 Subject: [PATCH 09/45] try simple base image to verify start up --- .../tools/jib/api/JibIntegrationTest.java | 29 ++++++++++--------- 1 file changed, 16 insertions(+), 13 deletions(-) diff --git a/jib-core/src/integration-test/java/com/google/cloud/tools/jib/api/JibIntegrationTest.java b/jib-core/src/integration-test/java/com/google/cloud/tools/jib/api/JibIntegrationTest.java index 7045d9c915..9807bfa1fa 100644 --- a/jib-core/src/integration-test/java/com/google/cloud/tools/jib/api/JibIntegrationTest.java +++ b/jib-core/src/integration-test/java/com/google/cloud/tools/jib/api/JibIntegrationTest.java @@ -326,15 +326,18 @@ public void testBasic_jibImageToDockerDaemon_arm64() RegistryException, CacheDirectoryCreationException { // Use arm64v8/busybox as base image. Jib.from( - RegistryImage.named( - "busybox@sha256:4f47c01fa91355af2865ac10fef5bf6ec9c7f42ad2321377c21e844427972977") + DockerDaemonImage.named(dockerHost + ":5000/busybox") + // RegistryImage.named( + // + // "busybox@sha256:4f47c01fa91355af2865ac10fef5bf6ec9c7f42ad2321377c21e844427972977") // RegistryImage.named( // // "busybox@sha256:eb427d855f82782c110b48b9a398556c629ce4951ae252c6f6751a136e194668") ) .containerize( Containerizer.to( - DockerDaemonImage.named(dockerHost + ":5000/docker-daemon-mismatched-arch"))); + DockerDaemonImage.named(dockerHost + ":5000/docker-daemon-mismatched-arch")) + .setAllowInsecureRegistries(true)); String os = new Command( @@ -345,17 +348,17 @@ public void testBasic_jibImageToDockerDaemon_arm64() "{{.Os}}") .run() .replace("\n", ""); - String architecture = - new Command( - "docker", - "inspect", - dockerHost + ":5000/docker-daemon-mismatched-arch", - "--format", - "{{.Architecture}}") - .run() - .replace("\n", ""); + // String architecture = + // new Command( + // "docker", + // "inspect", + // dockerHost + ":5000/docker-daemon-mismatched-arch", + // "--format", + // "{{.Architecture}}") + // .run() + // .replace("\n", ""); assertThat(os).isEqualTo("linux"); - assertThat(architecture).isEqualTo("arm64"); + // assertThat(architecture).isEqualTo("arm64"); } @Test From 8b5340259381580280aea96a5daab51c7b46268c Mon Sep 17 00:00:00 2001 From: mpeddada1 Date: Tue, 11 Jun 2024 01:32:43 +0000 Subject: [PATCH 10/45] debug --- .../tools/jib/api/JibIntegrationTest.java | 20 +++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/jib-core/src/integration-test/java/com/google/cloud/tools/jib/api/JibIntegrationTest.java b/jib-core/src/integration-test/java/com/google/cloud/tools/jib/api/JibIntegrationTest.java index 9807bfa1fa..23d5546069 100644 --- a/jib-core/src/integration-test/java/com/google/cloud/tools/jib/api/JibIntegrationTest.java +++ b/jib-core/src/integration-test/java/com/google/cloud/tools/jib/api/JibIntegrationTest.java @@ -39,6 +39,7 @@ import java.util.concurrent.ExecutionException; import java.util.concurrent.ExecutorService; import java.util.concurrent.Executors; +import java.util.logging.Logger; import org.junit.After; import org.junit.Assert; import org.junit.Before; @@ -78,6 +79,8 @@ public class JibIntegrationTest { new FailoverHttpClient(true, true, ignored -> {})) .newRegistryClient(); + private static final Logger LOGGER = Logger.getLogger(JibIntegrationTest.class.getName()); + /** * Pulls a built image and attempts to run it. * @@ -321,29 +324,26 @@ public void testBasic_jibImageToDockerDaemon() } @Test - public void testBasic_jibImageToDockerDaemon_arm64() + public void testBasic_jibImageToDockerDaemon_arm64BaseImage() throws IOException, InterruptedException, InvalidImageReferenceException, ExecutionException, RegistryException, CacheDirectoryCreationException { + LOGGER.warning("Beginning of testBasic_jibImageToDockerDaemon_arm64"); // Use arm64v8/busybox as base image. Jib.from( - DockerDaemonImage.named(dockerHost + ":5000/busybox") + // DockerDaemonImage.named(dockerHost + ":5000/busybox") // RegistryImage.named( // // "busybox@sha256:4f47c01fa91355af2865ac10fef5bf6ec9c7f42ad2321377c21e844427972977") - // RegistryImage.named( - // - // "busybox@sha256:eb427d855f82782c110b48b9a398556c629ce4951ae252c6f6751a136e194668") - ) + RegistryImage.named( + "busybox@sha256:eb427d855f82782c110b48b9a398556c629ce4951ae252c6f6751a136e194668")) .containerize( - Containerizer.to( - DockerDaemonImage.named(dockerHost + ":5000/docker-daemon-mismatched-arch")) - .setAllowInsecureRegistries(true)); + Containerizer.to(DockerDaemonImage.named(dockerHost + ":5000/docker-mismatched-arch"))); String os = new Command( "docker", "inspect", - dockerHost + ":5000/docker-daemon-mismatched-arch", + dockerHost + ":5000/docker-mismatched-arch", "--format", "{{.Os}}") .run() From bf39817fb74949b7e0b53a40be06954e945afedd Mon Sep 17 00:00:00 2001 From: mpeddada1 Date: Tue, 11 Jun 2024 01:47:08 +0000 Subject: [PATCH 11/45] undo debugging --- .../tools/jib/api/JibIntegrationTest.java | 28 +++++++------------ 1 file changed, 10 insertions(+), 18 deletions(-) diff --git a/jib-core/src/integration-test/java/com/google/cloud/tools/jib/api/JibIntegrationTest.java b/jib-core/src/integration-test/java/com/google/cloud/tools/jib/api/JibIntegrationTest.java index 23d5546069..7c0e6278e4 100644 --- a/jib-core/src/integration-test/java/com/google/cloud/tools/jib/api/JibIntegrationTest.java +++ b/jib-core/src/integration-test/java/com/google/cloud/tools/jib/api/JibIntegrationTest.java @@ -39,7 +39,6 @@ import java.util.concurrent.ExecutionException; import java.util.concurrent.ExecutorService; import java.util.concurrent.Executors; -import java.util.logging.Logger; import org.junit.After; import org.junit.Assert; import org.junit.Before; @@ -79,8 +78,6 @@ public class JibIntegrationTest { new FailoverHttpClient(true, true, ignored -> {})) .newRegistryClient(); - private static final Logger LOGGER = Logger.getLogger(JibIntegrationTest.class.getName()); - /** * Pulls a built image and attempts to run it. * @@ -327,13 +324,8 @@ public void testBasic_jibImageToDockerDaemon() public void testBasic_jibImageToDockerDaemon_arm64BaseImage() throws IOException, InterruptedException, InvalidImageReferenceException, ExecutionException, RegistryException, CacheDirectoryCreationException { - LOGGER.warning("Beginning of testBasic_jibImageToDockerDaemon_arm64"); // Use arm64v8/busybox as base image. Jib.from( - // DockerDaemonImage.named(dockerHost + ":5000/busybox") - // RegistryImage.named( - // - // "busybox@sha256:4f47c01fa91355af2865ac10fef5bf6ec9c7f42ad2321377c21e844427972977") RegistryImage.named( "busybox@sha256:eb427d855f82782c110b48b9a398556c629ce4951ae252c6f6751a136e194668")) .containerize( @@ -348,17 +340,17 @@ public void testBasic_jibImageToDockerDaemon_arm64BaseImage() "{{.Os}}") .run() .replace("\n", ""); - // String architecture = - // new Command( - // "docker", - // "inspect", - // dockerHost + ":5000/docker-daemon-mismatched-arch", - // "--format", - // "{{.Architecture}}") - // .run() - // .replace("\n", ""); + String architecture = + new Command( + "docker", + "inspect", + dockerHost + ":5000/docker-daemon-mismatched-arch", + "--format", + "{{.Architecture}}") + .run() + .replace("\n", ""); assertThat(os).isEqualTo("linux"); - // assertThat(architecture).isEqualTo("arm64"); + assertThat(architecture).isEqualTo("arm64"); } @Test From d3ee6b31cd922837e676c45dd09a5567a57e5e57 Mon Sep 17 00:00:00 2001 From: mpeddada1 Date: Tue, 11 Jun 2024 02:00:14 +0000 Subject: [PATCH 12/45] fix arm64 test --- .../java/com/google/cloud/tools/jib/api/JibIntegrationTest.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/jib-core/src/integration-test/java/com/google/cloud/tools/jib/api/JibIntegrationTest.java b/jib-core/src/integration-test/java/com/google/cloud/tools/jib/api/JibIntegrationTest.java index 7c0e6278e4..eec00c85a1 100644 --- a/jib-core/src/integration-test/java/com/google/cloud/tools/jib/api/JibIntegrationTest.java +++ b/jib-core/src/integration-test/java/com/google/cloud/tools/jib/api/JibIntegrationTest.java @@ -344,7 +344,7 @@ public void testBasic_jibImageToDockerDaemon_arm64BaseImage() new Command( "docker", "inspect", - dockerHost + ":5000/docker-daemon-mismatched-arch", + dockerHost + ":5000/docker-mismatched-arch", "--format", "{{.Architecture}}") .run() From d98b504fe0e556dbafe55b40234648e0fb203527 Mon Sep 17 00:00:00 2001 From: mpeddada1 Date: Tue, 11 Jun 2024 02:28:43 +0000 Subject: [PATCH 13/45] debug macos --- kokoro/docker_setup_macos.sh | 1 + 1 file changed, 1 insertion(+) diff --git a/kokoro/docker_setup_macos.sh b/kokoro/docker_setup_macos.sh index 66422462e3..82df966217 100644 --- a/kokoro/docker_setup_macos.sh +++ b/kokoro/docker_setup_macos.sh @@ -1,6 +1,7 @@ #!/bin/bash docker-machine ls +docker-machine create --driver virtualbox default docker-machine start default export DOCKER_IP="$(docker-machine ip default)" echo $DOCKER_IP From 02cc3511d7fea4dfdf12f54c48346c71c0c5a78d Mon Sep 17 00:00:00 2001 From: mpeddada1 Date: Tue, 11 Jun 2024 20:01:20 +0000 Subject: [PATCH 14/45] undo workaround --- kokoro/docker_setup_macos.sh | 1 - 1 file changed, 1 deletion(-) diff --git a/kokoro/docker_setup_macos.sh b/kokoro/docker_setup_macos.sh index 82df966217..66422462e3 100644 --- a/kokoro/docker_setup_macos.sh +++ b/kokoro/docker_setup_macos.sh @@ -1,7 +1,6 @@ #!/bin/bash docker-machine ls -docker-machine create --driver virtualbox default docker-machine start default export DOCKER_IP="$(docker-machine ip default)" echo $DOCKER_IP From 74b6c041b48ca71fa28c72e740785349e6a77368 Mon Sep 17 00:00:00 2001 From: mpeddada1 Date: Tue, 11 Jun 2024 20:12:02 +0000 Subject: [PATCH 15/45] revert name change --- .../java/com/google/cloud/tools/jib/api/JibIntegrationTest.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/jib-core/src/integration-test/java/com/google/cloud/tools/jib/api/JibIntegrationTest.java b/jib-core/src/integration-test/java/com/google/cloud/tools/jib/api/JibIntegrationTest.java index eec00c85a1..190d4ecbff 100644 --- a/jib-core/src/integration-test/java/com/google/cloud/tools/jib/api/JibIntegrationTest.java +++ b/jib-core/src/integration-test/java/com/google/cloud/tools/jib/api/JibIntegrationTest.java @@ -321,7 +321,7 @@ public void testBasic_jibImageToDockerDaemon() } @Test - public void testBasic_jibImageToDockerDaemon_arm64BaseImage() + public void testBasic_jibImageToDockerDaemon_arm64() throws IOException, InterruptedException, InvalidImageReferenceException, ExecutionException, RegistryException, CacheDirectoryCreationException { // Use arm64v8/busybox as base image. From 25d6e94cb8e2749456b503d07066a04a919b67d1 Mon Sep 17 00:00:00 2001 From: mpeddada1 Date: Tue, 11 Jun 2024 20:36:21 +0000 Subject: [PATCH 16/45] rename test and revert image change --- .../google/cloud/tools/jib/api/JibIntegrationTest.java | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/jib-core/src/integration-test/java/com/google/cloud/tools/jib/api/JibIntegrationTest.java b/jib-core/src/integration-test/java/com/google/cloud/tools/jib/api/JibIntegrationTest.java index 190d4ecbff..7a4ab6457e 100644 --- a/jib-core/src/integration-test/java/com/google/cloud/tools/jib/api/JibIntegrationTest.java +++ b/jib-core/src/integration-test/java/com/google/cloud/tools/jib/api/JibIntegrationTest.java @@ -321,7 +321,7 @@ public void testBasic_jibImageToDockerDaemon() } @Test - public void testBasic_jibImageToDockerDaemon_arm64() + public void testBasic_jibImageToDockerDaemon_arm64BaseImage() throws IOException, InterruptedException, InvalidImageReferenceException, ExecutionException, RegistryException, CacheDirectoryCreationException { // Use arm64v8/busybox as base image. @@ -329,13 +329,14 @@ public void testBasic_jibImageToDockerDaemon_arm64() RegistryImage.named( "busybox@sha256:eb427d855f82782c110b48b9a398556c629ce4951ae252c6f6751a136e194668")) .containerize( - Containerizer.to(DockerDaemonImage.named(dockerHost + ":5000/docker-mismatched-arch"))); + Containerizer.to( + DockerDaemonImage.named(dockerHost + ":5000/docker-daemon-mismatched-arch"))); String os = new Command( "docker", "inspect", - dockerHost + ":5000/docker-mismatched-arch", + dockerHost + ":5000/docker-daemon-mismatched-arch", "--format", "{{.Os}}") .run() @@ -344,7 +345,7 @@ public void testBasic_jibImageToDockerDaemon_arm64() new Command( "docker", "inspect", - dockerHost + ":5000/docker-mismatched-arch", + dockerHost + ":5000/docker-daemon-mismatched-arch", "--format", "{{.Architecture}}") .run() From 2144d08fdd1a4f8147e5ac8a9dfbb731b33b790f Mon Sep 17 00:00:00 2001 From: mpeddada1 Date: Tue, 11 Jun 2024 21:05:09 +0000 Subject: [PATCH 17/45] empty commit From 2c4afc6f18da51ad9343978c2f534a5d4884c283 Mon Sep 17 00:00:00 2001 From: mpeddada1 Date: Tue, 11 Jun 2024 21:28:31 +0000 Subject: [PATCH 18/45] rename to testBasic_toDockerDaemon_arm64 --- .../java/com/google/cloud/tools/jib/api/JibIntegrationTest.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/jib-core/src/integration-test/java/com/google/cloud/tools/jib/api/JibIntegrationTest.java b/jib-core/src/integration-test/java/com/google/cloud/tools/jib/api/JibIntegrationTest.java index 7a4ab6457e..53bb6f6fd4 100644 --- a/jib-core/src/integration-test/java/com/google/cloud/tools/jib/api/JibIntegrationTest.java +++ b/jib-core/src/integration-test/java/com/google/cloud/tools/jib/api/JibIntegrationTest.java @@ -321,7 +321,7 @@ public void testBasic_jibImageToDockerDaemon() } @Test - public void testBasic_jibImageToDockerDaemon_arm64BaseImage() + public void testBasic_toDockerDaemon_arm64() throws IOException, InterruptedException, InvalidImageReferenceException, ExecutionException, RegistryException, CacheDirectoryCreationException { // Use arm64v8/busybox as base image. From d4829f6be08e8d478a9cc97de63f42af6a943f6d Mon Sep 17 00:00:00 2001 From: mpeddada1 Date: Tue, 11 Jun 2024 21:50:31 +0000 Subject: [PATCH 19/45] debug CI behavior with test names --- .../java/com/google/cloud/tools/jib/api/JibIntegrationTest.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/jib-core/src/integration-test/java/com/google/cloud/tools/jib/api/JibIntegrationTest.java b/jib-core/src/integration-test/java/com/google/cloud/tools/jib/api/JibIntegrationTest.java index 53bb6f6fd4..34b5d791b9 100644 --- a/jib-core/src/integration-test/java/com/google/cloud/tools/jib/api/JibIntegrationTest.java +++ b/jib-core/src/integration-test/java/com/google/cloud/tools/jib/api/JibIntegrationTest.java @@ -321,7 +321,7 @@ public void testBasic_jibImageToDockerDaemon() } @Test - public void testBasic_toDockerDaemon_arm64() + public void testBasic_foo_arm64() throws IOException, InterruptedException, InvalidImageReferenceException, ExecutionException, RegistryException, CacheDirectoryCreationException { // Use arm64v8/busybox as base image. From 25e12b6e0143b4426fa25a9df0f3da1cf69a4ab1 Mon Sep 17 00:00:00 2001 From: mpeddada1 Date: Tue, 11 Jun 2024 22:38:32 +0000 Subject: [PATCH 20/45] verify with diff arch name --- .../java/com/google/cloud/tools/jib/api/JibIntegrationTest.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/jib-core/src/integration-test/java/com/google/cloud/tools/jib/api/JibIntegrationTest.java b/jib-core/src/integration-test/java/com/google/cloud/tools/jib/api/JibIntegrationTest.java index 34b5d791b9..7afca6f39e 100644 --- a/jib-core/src/integration-test/java/com/google/cloud/tools/jib/api/JibIntegrationTest.java +++ b/jib-core/src/integration-test/java/com/google/cloud/tools/jib/api/JibIntegrationTest.java @@ -321,7 +321,7 @@ public void testBasic_jibImageToDockerDaemon() } @Test - public void testBasic_foo_arm64() + public void testBasic_jibImageToDockerDaemon_amd64() throws IOException, InterruptedException, InvalidImageReferenceException, ExecutionException, RegistryException, CacheDirectoryCreationException { // Use arm64v8/busybox as base image. From 3c8a6f09681516b10a804e8a333e03ce327a74c3 Mon Sep 17 00:00:00 2001 From: mpeddada1 Date: Tue, 11 Jun 2024 23:35:50 +0000 Subject: [PATCH 21/45] rename to arm64BaseImage --- .../java/com/google/cloud/tools/jib/api/JibIntegrationTest.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/jib-core/src/integration-test/java/com/google/cloud/tools/jib/api/JibIntegrationTest.java b/jib-core/src/integration-test/java/com/google/cloud/tools/jib/api/JibIntegrationTest.java index 7afca6f39e..7a4ab6457e 100644 --- a/jib-core/src/integration-test/java/com/google/cloud/tools/jib/api/JibIntegrationTest.java +++ b/jib-core/src/integration-test/java/com/google/cloud/tools/jib/api/JibIntegrationTest.java @@ -321,7 +321,7 @@ public void testBasic_jibImageToDockerDaemon() } @Test - public void testBasic_jibImageToDockerDaemon_amd64() + public void testBasic_jibImageToDockerDaemon_arm64BaseImage() throws IOException, InterruptedException, InvalidImageReferenceException, ExecutionException, RegistryException, CacheDirectoryCreationException { // Use arm64v8/busybox as base image. From fca0b681579d94d5347b8f4dbd94e6fa837c48fd Mon Sep 17 00:00:00 2001 From: mpeddada1 Date: Thu, 13 Jun 2024 21:19:04 +0000 Subject: [PATCH 22/45] add logic to clean up containers after tests --- .../tools/jib/api/JibIntegrationTest.java | 82 ++++++++----------- 1 file changed, 32 insertions(+), 50 deletions(-) diff --git a/jib-core/src/integration-test/java/com/google/cloud/tools/jib/api/JibIntegrationTest.java b/jib-core/src/integration-test/java/com/google/cloud/tools/jib/api/JibIntegrationTest.java index 7a4ab6457e..228c6a62c8 100644 --- a/jib-core/src/integration-test/java/com/google/cloud/tools/jib/api/JibIntegrationTest.java +++ b/jib-core/src/integration-test/java/com/google/cloud/tools/jib/api/JibIntegrationTest.java @@ -59,6 +59,8 @@ public class JibIntegrationTest { @Rule public final TemporaryFolder temporaryFolder = new TemporaryFolder(); + private String imageToDelete; + private final String dockerHost = System.getenv("DOCKER_IP") != null ? System.getenv("DOCKER_IP") : "localhost"; @@ -103,8 +105,11 @@ public void setUp() { } @After - public void tearDown() { + public void tearDown() throws IOException, InterruptedException { System.clearProperty("sendCredentialsOverHttp"); + if (imageToDelete != null) { + new Command("docker", "rmi", imageToDelete).run(); + } } @Test @@ -121,6 +126,7 @@ public void testBasic_helloWorld() Assert.assertEquals("Hello World\n", pullAndRunBuiltImage(toImage)); Assert.assertEquals( "Hello World\n", pullAndRunBuiltImage(toImage + "@" + jibContainer.getDigest())); + imageToDelete = toImage; } @Test @@ -137,20 +143,21 @@ public void testBasic_dockerDaemonBaseImage() Assert.assertEquals("Hello World\n", pullAndRunBuiltImage(toImage)); Assert.assertEquals( "Hello World\n", pullAndRunBuiltImage(toImage + "@" + jibContainer.getDigest())); + imageToDelete = toImage; } @Test public void testBasic_dockerDaemonBaseImageToDockerDaemon() throws IOException, InterruptedException, InvalidImageReferenceException, ExecutionException, RegistryException, CacheDirectoryCreationException { + String toImage = dockerHost + ":5000/docker-to-docker"; Jib.from(DockerDaemonImage.named(dockerHost + ":5000/busybox")) .setEntrypoint("echo", "Hello World") - .containerize( - Containerizer.to(DockerDaemonImage.named(dockerHost + ":5000/docker-to-docker"))); + .containerize(Containerizer.to(DockerDaemonImage.named(toImage))); - String output = - new Command("docker", "run", "--rm", dockerHost + ":5000/docker-to-docker").run(); + String output = new Command("docker", "run", "--rm", toImage).run(); Assert.assertEquals("Hello World\n", output); + imageToDelete = toImage; } @Test @@ -170,6 +177,7 @@ public void testBasic_tarBaseImage_dockerSavedCommand() Assert.assertEquals("Hello World\n", pullAndRunBuiltImage(toImage)); Assert.assertEquals( "Hello World\n", pullAndRunBuiltImage(toImage + "@" + jibContainer.getDigest())); + imageToDelete = toImage; } @Test @@ -232,6 +240,7 @@ public void testBasic_tarBaseImage_jibImageToDockerDaemon() Assert.assertEquals("Hello World\n", pullAndRunBuiltImage(toImage)); Assert.assertEquals( "Hello World\n", pullAndRunBuiltImage(toImage + "@" + jibContainer.getDigest())); + imageToDelete = toImage; } @Test @@ -310,14 +319,14 @@ public void testScratch_multiPlatform() public void testBasic_jibImageToDockerDaemon() throws IOException, InterruptedException, InvalidImageReferenceException, ExecutionException, RegistryException, CacheDirectoryCreationException { + String toImage = dockerHost + ":5000/docker-to-docker"; Jib.from(DockerDaemonImage.named(dockerHost + ":5000/busybox")) .setEntrypoint("echo", "Hello World") - .containerize( - Containerizer.to(DockerDaemonImage.named(dockerHost + ":5000/docker-to-docker"))); + .containerize(Containerizer.to(DockerDaemonImage.named(toImage))); - String output = - new Command("docker", "run", "--rm", dockerHost + ":5000/docker-to-docker").run(); + String output = new Command("docker", "run", "--rm", toImage).run(); Assert.assertEquals("Hello World\n", output); + imageToDelete = toImage; } @Test @@ -325,39 +334,28 @@ public void testBasic_jibImageToDockerDaemon_arm64BaseImage() throws IOException, InterruptedException, InvalidImageReferenceException, ExecutionException, RegistryException, CacheDirectoryCreationException { // Use arm64v8/busybox as base image. + String toImage = dockerHost + ":5000/docker-daemon-mismatched-arch"; Jib.from( RegistryImage.named( "busybox@sha256:eb427d855f82782c110b48b9a398556c629ce4951ae252c6f6751a136e194668")) - .containerize( - Containerizer.to( - DockerDaemonImage.named(dockerHost + ":5000/docker-daemon-mismatched-arch"))); + .containerize(Containerizer.to(DockerDaemonImage.named(toImage))); String os = - new Command( - "docker", - "inspect", - dockerHost + ":5000/docker-daemon-mismatched-arch", - "--format", - "{{.Os}}") - .run() - .replace("\n", ""); + new Command("docker", "inspect", toImage, "--format", "{{.Os}}").run().replace("\n", ""); String architecture = - new Command( - "docker", - "inspect", - dockerHost + ":5000/docker-daemon-mismatched-arch", - "--format", - "{{.Architecture}}") + new Command("docker", "inspect", toImage, "--format", "{{.Architecture}}") .run() .replace("\n", ""); assertThat(os).isEqualTo("linux"); assertThat(architecture).isEqualTo("arm64"); + imageToDelete = toImage; } @Test public void testBasicMultiPlatform_toDockerDaemon() throws IOException, InterruptedException, ExecutionException, RegistryException, CacheDirectoryCreationException, InvalidImageReferenceException { + String toImage = dockerHost + ":5000/docker-daemon-multi-platform"; Jib.from( RegistryImage.named( "busybox@sha256:4f47c01fa91355af2865ac10fef5bf6ec9c7f42ad2321377c21e844427972977")) @@ -365,49 +363,33 @@ public void testBasicMultiPlatform_toDockerDaemon() ImmutableSet.of(new Platform("arm64", "linux"), new Platform("amd64", "linux"))) .setEntrypoint("echo", "Hello World") .containerize( - Containerizer.to( - DockerDaemonImage.named(dockerHost + ":5000/docker-daemon-multi-platform")) - .setAllowInsecureRegistries(true)); + Containerizer.to(DockerDaemonImage.named(toImage)).setAllowInsecureRegistries(true)); - String output = - new Command("docker", "run", "--rm", dockerHost + ":5000/docker-daemon-multi-platform") - .run(); + String output = new Command("docker", "run", "--rm", toImage).run(); Assert.assertEquals("Hello World\n", output); + imageToDelete = toImage; } @Test public void testBasicMultiPlatform_toDockerDaemon_pickFirstPlatformWhenNoMatchingImage() throws IOException, InterruptedException, InvalidImageReferenceException, CacheDirectoryCreationException, ExecutionException, RegistryException { + String toImage = dockerHost + ":5000/docker-daemon-multi-plat-mismatched-configs"; Jib.from( RegistryImage.named( "busybox@sha256:4f47c01fa91355af2865ac10fef5bf6ec9c7f42ad2321377c21e844427972977")) .setPlatforms(ImmutableSet.of(new Platform("s390x", "linux"), new Platform("arm", "linux"))) .containerize( - Containerizer.to( - DockerDaemonImage.named( - dockerHost + ":5000/docker-daemon-multi-plat-mismatched-configs")) - .setAllowInsecureRegistries(true)); + Containerizer.to(DockerDaemonImage.named(toImage)).setAllowInsecureRegistries(true)); String os = - new Command( - "docker", - "inspect", - dockerHost + ":5000/docker-daemon-multi-plat-mismatched-configs", - "--format", - "{{.Os}}") - .run() - .replace("\n", ""); + new Command("docker", "inspect", toImage, "--format", "{{.Os}}").run().replace("\n", ""); String architecture = - new Command( - "docker", - "inspect", - dockerHost + ":5000/docker-daemon-multi-plat-mismatched-configs", - "--format", - "{{.Architecture}}") + new Command("docker", "inspect", toImage, "--format", "{{.Architecture}}") .run() .replace("\n", ""); assertThat(os).isEqualTo("linux"); assertThat(architecture).isEqualTo("s390x"); + imageToDelete = toImage; } @Test From e7a51d8a06abd6545a374f7f0636250cd56af9f2 Mon Sep 17 00:00:00 2001 From: mpeddada1 Date: Fri, 14 Jun 2024 16:30:50 +0000 Subject: [PATCH 23/45] verify with original name after test resource clean up --- .../java/com/google/cloud/tools/jib/api/JibIntegrationTest.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/jib-core/src/integration-test/java/com/google/cloud/tools/jib/api/JibIntegrationTest.java b/jib-core/src/integration-test/java/com/google/cloud/tools/jib/api/JibIntegrationTest.java index 228c6a62c8..8d2b6c1b73 100644 --- a/jib-core/src/integration-test/java/com/google/cloud/tools/jib/api/JibIntegrationTest.java +++ b/jib-core/src/integration-test/java/com/google/cloud/tools/jib/api/JibIntegrationTest.java @@ -330,7 +330,7 @@ public void testBasic_jibImageToDockerDaemon() } @Test - public void testBasic_jibImageToDockerDaemon_arm64BaseImage() + public void testBasic_jibImageToDockerDaemon_arm64() throws IOException, InterruptedException, InvalidImageReferenceException, ExecutionException, RegistryException, CacheDirectoryCreationException { // Use arm64v8/busybox as base image. From d92123d9675a3ea662c8c1a77e757bf003ffe0c6 Mon Sep 17 00:00:00 2001 From: mpeddada1 Date: Fri, 14 Jun 2024 17:14:52 +0000 Subject: [PATCH 24/45] understand order of execution on CI --- .../tools/jib/api/JibIntegrationTest.java | 36 ++++++++++++++++++- 1 file changed, 35 insertions(+), 1 deletion(-) diff --git a/jib-core/src/integration-test/java/com/google/cloud/tools/jib/api/JibIntegrationTest.java b/jib-core/src/integration-test/java/com/google/cloud/tools/jib/api/JibIntegrationTest.java index 8d2b6c1b73..cef92a8f68 100644 --- a/jib-core/src/integration-test/java/com/google/cloud/tools/jib/api/JibIntegrationTest.java +++ b/jib-core/src/integration-test/java/com/google/cloud/tools/jib/api/JibIntegrationTest.java @@ -116,6 +116,7 @@ public void tearDown() throws IOException, InterruptedException { public void testBasic_helloWorld() throws InvalidImageReferenceException, InterruptedException, CacheDirectoryCreationException, IOException, RegistryException, ExecutionException { + System.out.println("testBasic_helloWorld()"); String toImage = dockerHost + ":5000/basic-helloworld"; JibContainer jibContainer = Jib.from(dockerHost + ":5000/busybox") @@ -133,6 +134,7 @@ public void testBasic_helloWorld() public void testBasic_dockerDaemonBaseImage() throws IOException, InterruptedException, InvalidImageReferenceException, ExecutionException, RegistryException, CacheDirectoryCreationException { + System.out.println("testBasic_dockerDaemonBaseImage()"); String toImage = dockerHost + ":5000/basic-dockerdaemon"; JibContainer jibContainer = Jib.from("docker://" + dockerHost + ":5000/busybox") @@ -150,6 +152,7 @@ public void testBasic_dockerDaemonBaseImage() public void testBasic_dockerDaemonBaseImageToDockerDaemon() throws IOException, InterruptedException, InvalidImageReferenceException, ExecutionException, RegistryException, CacheDirectoryCreationException { + System.out.println("testBasic_dockerDaemonBaseImageToDockerDaemon()"); String toImage = dockerHost + ":5000/docker-to-docker"; Jib.from(DockerDaemonImage.named(dockerHost + ":5000/busybox")) .setEntrypoint("echo", "Hello World") @@ -164,6 +167,8 @@ public void testBasic_dockerDaemonBaseImageToDockerDaemon() public void testBasic_tarBaseImage_dockerSavedCommand() throws IOException, InterruptedException, InvalidImageReferenceException, ExecutionException, RegistryException, CacheDirectoryCreationException { + System.out.println("testBasic_tarBaseImage_dockerSavedCommand()"); + Path path = temporaryFolder.getRoot().toPath().resolve("docker-save.tar"); new Command("docker", "save", dockerHost + ":5000/busybox", "-o=" + path).run(); @@ -184,6 +189,8 @@ public void testBasic_tarBaseImage_dockerSavedCommand() public void testBasic_tarBaseImage_dockerSavedFile() throws IOException, InterruptedException, InvalidImageReferenceException, ExecutionException, RegistryException, CacheDirectoryCreationException, URISyntaxException { + System.out.println("testBasic_tarBaseImage_dockerSavedFile()"); + // tar saved with 'docker save busybox -o busybox.tar' Path path = Paths.get(Resources.getResource("core/busybox-docker.tar").toURI()); @@ -203,6 +210,8 @@ public void testBasic_tarBaseImage_dockerSavedFile() public void testBasic_tarBaseImage_jibImage() throws InvalidImageReferenceException, InterruptedException, ExecutionException, RegistryException, CacheDirectoryCreationException, IOException, URISyntaxException { + System.out.println("testBasic_tarBaseImage_jibImage()"); + Path outputPath = temporaryFolder.getRoot().toPath().resolve("jib-image.tar"); Jib.from(dockerHost + ":5000/busybox") .addLayer( @@ -227,6 +236,8 @@ public void testBasic_tarBaseImage_jibImage() public void testBasic_tarBaseImage_jibImageToDockerDaemon() throws InvalidImageReferenceException, InterruptedException, ExecutionException, RegistryException, CacheDirectoryCreationException, IOException, URISyntaxException { + System.out.println("testBasic_tarBaseImage_jibImageToDockerDaemon()"); + // tar saved with Jib.from("busybox").addLayer(...("core/hello")).containerize(TarImage.at...) Path path = Paths.get(Resources.getResource("core/busybox-jib.tar").toURI()); @@ -247,6 +258,8 @@ public void testBasic_tarBaseImage_jibImageToDockerDaemon() public void testScratch_defaultPlatform() throws IOException, InterruptedException, ExecutionException, RegistryException, CacheDirectoryCreationException, InvalidImageReferenceException { + System.out.println("testScratch_defaultPlatform()"); + Jib.fromScratch() .containerize( Containerizer.to(RegistryImage.named(dockerHost + ":5000/jib-scratch:default-platform")) @@ -270,6 +283,8 @@ public void testScratch_defaultPlatform() public void testScratch_singlePlatform() throws IOException, InterruptedException, ExecutionException, RegistryException, CacheDirectoryCreationException, InvalidImageReferenceException { + System.out.println("testScratch_singlePlatform()"); + Jib.fromScratch() .setPlatforms(ImmutableSet.of(new Platform("arm64", "windows"))) .containerize( @@ -294,6 +309,8 @@ public void testScratch_singlePlatform() public void testScratch_multiPlatform() throws IOException, InterruptedException, ExecutionException, RegistryException, CacheDirectoryCreationException, InvalidImageReferenceException { + System.out.println("testScratch_multiPlatform()"); + Jib.fromScratch() .setPlatforms( ImmutableSet.of(new Platform("arm64", "windows"), new Platform("amd32", "windows"))) @@ -319,6 +336,8 @@ public void testScratch_multiPlatform() public void testBasic_jibImageToDockerDaemon() throws IOException, InterruptedException, InvalidImageReferenceException, ExecutionException, RegistryException, CacheDirectoryCreationException { + System.out.println("testBasic_jibImageToDockerDaemon()"); + String toImage = dockerHost + ":5000/docker-to-docker"; Jib.from(DockerDaemonImage.named(dockerHost + ":5000/busybox")) .setEntrypoint("echo", "Hello World") @@ -330,9 +349,11 @@ public void testBasic_jibImageToDockerDaemon() } @Test - public void testBasic_jibImageToDockerDaemon_arm64() + public void testBasic_jibImageToDockerDaemon_arm64BaseImage() throws IOException, InterruptedException, InvalidImageReferenceException, ExecutionException, RegistryException, CacheDirectoryCreationException { + System.out.println("testBasic_jibImageToDockerDaemon_arm64BaseImage() 2"); + // Use arm64v8/busybox as base image. String toImage = dockerHost + ":5000/docker-daemon-mismatched-arch"; Jib.from( @@ -355,6 +376,8 @@ public void testBasic_jibImageToDockerDaemon_arm64() public void testBasicMultiPlatform_toDockerDaemon() throws IOException, InterruptedException, ExecutionException, RegistryException, CacheDirectoryCreationException, InvalidImageReferenceException { + System.out.println("testBasicMultiPlatform_toDockerDaemon()"); + String toImage = dockerHost + ":5000/docker-daemon-multi-platform"; Jib.from( RegistryImage.named( @@ -374,6 +397,9 @@ public void testBasicMultiPlatform_toDockerDaemon() public void testBasicMultiPlatform_toDockerDaemon_pickFirstPlatformWhenNoMatchingImage() throws IOException, InterruptedException, InvalidImageReferenceException, CacheDirectoryCreationException, ExecutionException, RegistryException { + System.out.println( + "testBasicMultiPlatform_toDockerDaemon_pickFirstPlatformWhenNoMatchingImage()"); + String toImage = dockerHost + ":5000/docker-daemon-multi-plat-mismatched-configs"; Jib.from( RegistryImage.named( @@ -396,6 +422,8 @@ public void testBasicMultiPlatform_toDockerDaemon_pickFirstPlatformWhenNoMatchin public void testDistroless_ociManifest() throws IOException, InterruptedException, ExecutionException, RegistryException, CacheDirectoryCreationException, InvalidImageReferenceException { + System.out.println("testDistroless_ociManifest()"); + Jib.from("gcr.io/distroless/base@" + KNOWN_OCI_INDEX_SHA) .setPlatforms( ImmutableSet.of(new Platform("arm64", "linux"), new Platform("amd64", "linux"))) @@ -423,6 +451,8 @@ public void testDistroless_ociManifest() public void testOffline() throws IOException, InterruptedException, InvalidImageReferenceException, ExecutionException, RegistryException, CacheDirectoryCreationException { + System.out.println("testOffline"); + Path cacheDirectory = temporaryFolder.getRoot().toPath(); JibContainerBuilder jibContainerBuilder = @@ -474,6 +504,8 @@ public void testOffline() public void testProvidedExecutorNotDisposed() throws InvalidImageReferenceException, InterruptedException, CacheDirectoryCreationException, IOException, RegistryException, ExecutionException { + System.out.println("testProvidedExecutorNotDisposed"); + ExecutorService executorService = Executors.newCachedThreadPool(); try { Jib.fromScratch() @@ -491,6 +523,8 @@ public void testProvidedExecutorNotDisposed() public void testManifestListReferenceByShaDoesNotFail() throws InvalidImageReferenceException, IOException, InterruptedException, ExecutionException, RegistryException, CacheDirectoryCreationException { + System.out.println("testManifestListReferenceByShaDoesNotFail()"); + Containerizer containerizer = Containerizer.to(TarImage.at(temporaryFolder.newFile("goose").toPath()).named("whatever")); From 0a6862d2071bdb32d702bc079334b4179a7b3b4a Mon Sep 17 00:00:00 2001 From: mpeddada1 Date: Fri, 14 Jun 2024 17:32:54 +0000 Subject: [PATCH 25/45] change back to original name --- .../com/google/cloud/tools/jib/api/JibIntegrationTest.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/jib-core/src/integration-test/java/com/google/cloud/tools/jib/api/JibIntegrationTest.java b/jib-core/src/integration-test/java/com/google/cloud/tools/jib/api/JibIntegrationTest.java index cef92a8f68..e3b6c7b2d6 100644 --- a/jib-core/src/integration-test/java/com/google/cloud/tools/jib/api/JibIntegrationTest.java +++ b/jib-core/src/integration-test/java/com/google/cloud/tools/jib/api/JibIntegrationTest.java @@ -349,10 +349,10 @@ public void testBasic_jibImageToDockerDaemon() } @Test - public void testBasic_jibImageToDockerDaemon_arm64BaseImage() + public void testBasic_jibImageToDockerDaemon_arm64() throws IOException, InterruptedException, InvalidImageReferenceException, ExecutionException, RegistryException, CacheDirectoryCreationException { - System.out.println("testBasic_jibImageToDockerDaemon_arm64BaseImage() 2"); + System.out.println("testBasic_jibImageToDockerDaemon_arm64"); // Use arm64v8/busybox as base image. String toImage = dockerHost + ":5000/docker-daemon-mismatched-arch"; From 8ca43cac30fa89d8df443e2c48791065df0b4e07 Mon Sep 17 00:00:00 2001 From: mpeddada1 Date: Fri, 14 Jun 2024 18:24:35 +0000 Subject: [PATCH 26/45] verify image creation --- .../java/com/google/cloud/tools/jib/api/JibIntegrationTest.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/jib-core/src/integration-test/java/com/google/cloud/tools/jib/api/JibIntegrationTest.java b/jib-core/src/integration-test/java/com/google/cloud/tools/jib/api/JibIntegrationTest.java index e3b6c7b2d6..c6752b6522 100644 --- a/jib-core/src/integration-test/java/com/google/cloud/tools/jib/api/JibIntegrationTest.java +++ b/jib-core/src/integration-test/java/com/google/cloud/tools/jib/api/JibIntegrationTest.java @@ -360,7 +360,7 @@ public void testBasic_jibImageToDockerDaemon_arm64() RegistryImage.named( "busybox@sha256:eb427d855f82782c110b48b9a398556c629ce4951ae252c6f6751a136e194668")) .containerize(Containerizer.to(DockerDaemonImage.named(toImage))); - + System.out.println("Verified image creation"); String os = new Command("docker", "inspect", toImage, "--format", "{{.Os}}").run().replace("\n", ""); String architecture = From 9552133d047fade08294fa55b6468a0a252ab1db Mon Sep 17 00:00:00 2001 From: mpeddada1 Date: Fri, 14 Jun 2024 19:37:20 +0000 Subject: [PATCH 27/45] skip distroless_ociManifest test --- .../tools/jib/api/JibIntegrationTest.java | 23 ++++++++++++------- 1 file changed, 15 insertions(+), 8 deletions(-) diff --git a/jib-core/src/integration-test/java/com/google/cloud/tools/jib/api/JibIntegrationTest.java b/jib-core/src/integration-test/java/com/google/cloud/tools/jib/api/JibIntegrationTest.java index c6752b6522..8bc781291d 100644 --- a/jib-core/src/integration-test/java/com/google/cloud/tools/jib/api/JibIntegrationTest.java +++ b/jib-core/src/integration-test/java/com/google/cloud/tools/jib/api/JibIntegrationTest.java @@ -72,13 +72,13 @@ public class JibIntegrationTest { new FailoverHttpClient(true, true, ignored -> {})) .newRegistryClient(); - private final RegistryClient distrolessRegistryClient = - RegistryClient.factory( - EventHandlers.NONE, - dockerHost + ":5000", - "jib-distroless", - new FailoverHttpClient(true, true, ignored -> {})) - .newRegistryClient(); + // private final RegistryClient distrolessRegistryClient = + // RegistryClient.factory( + // EventHandlers.NONE, + // dockerHost + ":5000", + // "jib-distroless", + // new FailoverHttpClient(true, true, ignored -> {})) + // .newRegistryClient(); /** * Pulls a built image and attempts to run it. @@ -418,7 +418,7 @@ public void testBasicMultiPlatform_toDockerDaemon_pickFirstPlatformWhenNoMatchin imageToDelete = toImage; } - @Test + // @Test public void testDistroless_ociManifest() throws IOException, InterruptedException, ExecutionException, RegistryException, CacheDirectoryCreationException, InvalidImageReferenceException { @@ -432,6 +432,13 @@ public void testDistroless_ociManifest() RegistryImage.named(dockerHost + ":5000/jib-distroless:multi-platform")) .setAllowInsecureRegistries(true)); + RegistryClient distrolessRegistryClient = + RegistryClient.factory( + EventHandlers.NONE, + dockerHost + ":5000", + "jib-distroless", + new FailoverHttpClient(true, true, ignored -> {})) + .newRegistryClient(); V22ManifestListTemplate manifestList = (V22ManifestListTemplate) distrolessRegistryClient.pullManifest("multi-platform").getManifest(); From 61d528da454e0aa919926c8ca06e0c6406ec5ac9 Mon Sep 17 00:00:00 2001 From: mpeddada1 Date: Fri, 14 Jun 2024 19:47:09 +0000 Subject: [PATCH 28/45] add Ignore --- .../com/google/cloud/tools/jib/api/JibIntegrationTest.java | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/jib-core/src/integration-test/java/com/google/cloud/tools/jib/api/JibIntegrationTest.java b/jib-core/src/integration-test/java/com/google/cloud/tools/jib/api/JibIntegrationTest.java index 8bc781291d..f156c14c98 100644 --- a/jib-core/src/integration-test/java/com/google/cloud/tools/jib/api/JibIntegrationTest.java +++ b/jib-core/src/integration-test/java/com/google/cloud/tools/jib/api/JibIntegrationTest.java @@ -44,6 +44,7 @@ import org.junit.Before; import org.junit.BeforeClass; import org.junit.ClassRule; +import org.junit.Ignore; import org.junit.Rule; import org.junit.Test; import org.junit.rules.TemporaryFolder; @@ -418,7 +419,8 @@ public void testBasicMultiPlatform_toDockerDaemon_pickFirstPlatformWhenNoMatchin imageToDelete = toImage; } - // @Test + @Test + @Ignore public void testDistroless_ociManifest() throws IOException, InterruptedException, ExecutionException, RegistryException, CacheDirectoryCreationException, InvalidImageReferenceException { From b76259049b85204ab8dfe01d61b5dfcaf70c4745 Mon Sep 17 00:00:00 2001 From: mpeddada1 Date: Fri, 14 Jun 2024 20:41:43 +0000 Subject: [PATCH 29/45] verify with lightweight base image --- .../tools/jib/api/JibIntegrationTest.java | 31 +++++++------------ 1 file changed, 12 insertions(+), 19 deletions(-) diff --git a/jib-core/src/integration-test/java/com/google/cloud/tools/jib/api/JibIntegrationTest.java b/jib-core/src/integration-test/java/com/google/cloud/tools/jib/api/JibIntegrationTest.java index f156c14c98..5b1ac2f6da 100644 --- a/jib-core/src/integration-test/java/com/google/cloud/tools/jib/api/JibIntegrationTest.java +++ b/jib-core/src/integration-test/java/com/google/cloud/tools/jib/api/JibIntegrationTest.java @@ -44,7 +44,6 @@ import org.junit.Before; import org.junit.BeforeClass; import org.junit.ClassRule; -import org.junit.Ignore; import org.junit.Rule; import org.junit.Test; import org.junit.rules.TemporaryFolder; @@ -57,6 +56,7 @@ public class JibIntegrationTest { "sha256:2c50b819aa3bfaf6ae72e47682f6c5abc0f647cf3f4224a4a9be97dd30433909"; @ClassRule public static final LocalRegistry localRegistry = new LocalRegistry(5000); + @ClassRule public static final LocalRegistry localRegistry2 = new LocalRegistry(6000); @Rule public final TemporaryFolder temporaryFolder = new TemporaryFolder(); @@ -73,13 +73,13 @@ public class JibIntegrationTest { new FailoverHttpClient(true, true, ignored -> {})) .newRegistryClient(); - // private final RegistryClient distrolessRegistryClient = - // RegistryClient.factory( - // EventHandlers.NONE, - // dockerHost + ":5000", - // "jib-distroless", - // new FailoverHttpClient(true, true, ignored -> {})) - // .newRegistryClient(); + private final RegistryClient distrolessRegistryClient = + RegistryClient.factory( + EventHandlers.NONE, + dockerHost + ":5000", + "jib-distroless", + new FailoverHttpClient(true, true, ignored -> {})) + .newRegistryClient(); /** * Pulls a built image and attempts to run it. @@ -356,12 +356,11 @@ public void testBasic_jibImageToDockerDaemon_arm64() System.out.println("testBasic_jibImageToDockerDaemon_arm64"); // Use arm64v8/busybox as base image. - String toImage = dockerHost + ":5000/docker-daemon-mismatched-arch"; + String toImage = "docker-daemon-mismatched-arch"; Jib.from( RegistryImage.named( "busybox@sha256:eb427d855f82782c110b48b9a398556c629ce4951ae252c6f6751a136e194668")) .containerize(Containerizer.to(DockerDaemonImage.named(toImage))); - System.out.println("Verified image creation"); String os = new Command("docker", "inspect", toImage, "--format", "{{.Os}}").run().replace("\n", ""); String architecture = @@ -420,13 +419,14 @@ public void testBasicMultiPlatform_toDockerDaemon_pickFirstPlatformWhenNoMatchin } @Test - @Ignore + // @Ignore public void testDistroless_ociManifest() throws IOException, InterruptedException, ExecutionException, RegistryException, CacheDirectoryCreationException, InvalidImageReferenceException { System.out.println("testDistroless_ociManifest()"); - Jib.from("gcr.io/distroless/base@" + KNOWN_OCI_INDEX_SHA) + Jib.fromScratch() + // .from(dockerHost + ":5000/distroless/base") .setPlatforms( ImmutableSet.of(new Platform("arm64", "linux"), new Platform("amd64", "linux"))) .containerize( @@ -434,13 +434,6 @@ public void testDistroless_ociManifest() RegistryImage.named(dockerHost + ":5000/jib-distroless:multi-platform")) .setAllowInsecureRegistries(true)); - RegistryClient distrolessRegistryClient = - RegistryClient.factory( - EventHandlers.NONE, - dockerHost + ":5000", - "jib-distroless", - new FailoverHttpClient(true, true, ignored -> {})) - .newRegistryClient(); V22ManifestListTemplate manifestList = (V22ManifestListTemplate) distrolessRegistryClient.pullManifest("multi-platform").getManifest(); From 1668da634baec31ed76456a751e3d0b2c6d390f2 Mon Sep 17 00:00:00 2001 From: mpeddada1 Date: Fri, 14 Jun 2024 21:22:22 +0000 Subject: [PATCH 30/45] use separate registry for ociManifest test --- .../google/cloud/tools/jib/api/JibIntegrationTest.java | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/jib-core/src/integration-test/java/com/google/cloud/tools/jib/api/JibIntegrationTest.java b/jib-core/src/integration-test/java/com/google/cloud/tools/jib/api/JibIntegrationTest.java index 5b1ac2f6da..3f82d1c67f 100644 --- a/jib-core/src/integration-test/java/com/google/cloud/tools/jib/api/JibIntegrationTest.java +++ b/jib-core/src/integration-test/java/com/google/cloud/tools/jib/api/JibIntegrationTest.java @@ -76,7 +76,7 @@ public class JibIntegrationTest { private final RegistryClient distrolessRegistryClient = RegistryClient.factory( EventHandlers.NONE, - dockerHost + ":5000", + dockerHost + ":6000", "jib-distroless", new FailoverHttpClient(true, true, ignored -> {})) .newRegistryClient(); @@ -419,19 +419,17 @@ public void testBasicMultiPlatform_toDockerDaemon_pickFirstPlatformWhenNoMatchin } @Test - // @Ignore public void testDistroless_ociManifest() throws IOException, InterruptedException, ExecutionException, RegistryException, CacheDirectoryCreationException, InvalidImageReferenceException { System.out.println("testDistroless_ociManifest()"); - Jib.fromScratch() - // .from(dockerHost + ":5000/distroless/base") + Jib.from("gcr.io/distroless/base@" + KNOWN_OCI_INDEX_SHA) .setPlatforms( ImmutableSet.of(new Platform("arm64", "linux"), new Platform("amd64", "linux"))) .containerize( Containerizer.to( - RegistryImage.named(dockerHost + ":5000/jib-distroless:multi-platform")) + RegistryImage.named(dockerHost + ":6000/jib-distroless:multi-platform")) .setAllowInsecureRegistries(true)); V22ManifestListTemplate manifestList = From 87d9113b2b49c234dff8eb1fd8a5887ff0949150 Mon Sep 17 00:00:00 2001 From: mpeddada1 Date: Fri, 14 Jun 2024 21:40:50 +0000 Subject: [PATCH 31/45] revert to previous image ref --- .../java/com/google/cloud/tools/jib/api/JibIntegrationTest.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/jib-core/src/integration-test/java/com/google/cloud/tools/jib/api/JibIntegrationTest.java b/jib-core/src/integration-test/java/com/google/cloud/tools/jib/api/JibIntegrationTest.java index 3f82d1c67f..9355a6ab7e 100644 --- a/jib-core/src/integration-test/java/com/google/cloud/tools/jib/api/JibIntegrationTest.java +++ b/jib-core/src/integration-test/java/com/google/cloud/tools/jib/api/JibIntegrationTest.java @@ -356,7 +356,7 @@ public void testBasic_jibImageToDockerDaemon_arm64() System.out.println("testBasic_jibImageToDockerDaemon_arm64"); // Use arm64v8/busybox as base image. - String toImage = "docker-daemon-mismatched-arch"; + String toImage = dockerHost + ":5000/docker-daemon-mismatched-arch"; Jib.from( RegistryImage.named( "busybox@sha256:eb427d855f82782c110b48b9a398556c629ce4951ae252c6f6751a136e194668")) From 908a72be1faafde66abaabc5ba917ce04ce977ac Mon Sep 17 00:00:00 2001 From: mpeddada1 Date: Fri, 14 Jun 2024 23:25:36 +0000 Subject: [PATCH 32/45] try different base image --- .../java/com/google/cloud/tools/jib/api/JibIntegrationTest.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/jib-core/src/integration-test/java/com/google/cloud/tools/jib/api/JibIntegrationTest.java b/jib-core/src/integration-test/java/com/google/cloud/tools/jib/api/JibIntegrationTest.java index 9355a6ab7e..07ec893723 100644 --- a/jib-core/src/integration-test/java/com/google/cloud/tools/jib/api/JibIntegrationTest.java +++ b/jib-core/src/integration-test/java/com/google/cloud/tools/jib/api/JibIntegrationTest.java @@ -424,7 +424,7 @@ public void testDistroless_ociManifest() CacheDirectoryCreationException, InvalidImageReferenceException { System.out.println("testDistroless_ociManifest()"); - Jib.from("gcr.io/distroless/base@" + KNOWN_OCI_INDEX_SHA) + Jib.from("alpine") .setPlatforms( ImmutableSet.of(new Platform("arm64", "linux"), new Platform("amd64", "linux"))) .containerize( From 693f09c72ccf645103321ac8062ec2ce233964af Mon Sep 17 00:00:00 2001 From: mpeddada1 Date: Sat, 15 Jun 2024 01:38:46 +0000 Subject: [PATCH 33/45] debug --- .../tools/jib/api/JibIntegrationTest.java | 28 +++++++++---------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/jib-core/src/integration-test/java/com/google/cloud/tools/jib/api/JibIntegrationTest.java b/jib-core/src/integration-test/java/com/google/cloud/tools/jib/api/JibIntegrationTest.java index 07ec893723..742defba69 100644 --- a/jib-core/src/integration-test/java/com/google/cloud/tools/jib/api/JibIntegrationTest.java +++ b/jib-core/src/integration-test/java/com/google/cloud/tools/jib/api/JibIntegrationTest.java @@ -424,7 +424,7 @@ public void testDistroless_ociManifest() CacheDirectoryCreationException, InvalidImageReferenceException { System.out.println("testDistroless_ociManifest()"); - Jib.from("alpine") + Jib.from("gcr.io/distroless/base@" + KNOWN_OCI_INDEX_SHA) .setPlatforms( ImmutableSet.of(new Platform("arm64", "linux"), new Platform("amd64", "linux"))) .containerize( @@ -432,19 +432,19 @@ public void testDistroless_ociManifest() RegistryImage.named(dockerHost + ":6000/jib-distroless:multi-platform")) .setAllowInsecureRegistries(true)); - V22ManifestListTemplate manifestList = - (V22ManifestListTemplate) - distrolessRegistryClient.pullManifest("multi-platform").getManifest(); - Assert.assertEquals(2, manifestList.getManifests().size()); - ManifestDescriptorTemplate.Platform platform1 = - manifestList.getManifests().get(0).getPlatform(); - ManifestDescriptorTemplate.Platform platform2 = - manifestList.getManifests().get(1).getPlatform(); - - Assert.assertEquals("arm64", platform1.getArchitecture()); - Assert.assertEquals("linux", platform1.getOs()); - Assert.assertEquals("amd64", platform2.getArchitecture()); - Assert.assertEquals("linux", platform2.getOs()); + // V22ManifestListTemplate manifestList = + // (V22ManifestListTemplate) + // distrolessRegistryClient.pullManifest("multi-platform").getManifest(); + // Assert.assertEquals(2, manifestList.getManifests().size()); + // ManifestDescriptorTemplate.Platform platform1 = + // manifestList.getManifests().get(0).getPlatform(); + // ManifestDescriptorTemplate.Platform platform2 = + // manifestList.getManifests().get(1).getPlatform(); + // + // Assert.assertEquals("arm64", platform1.getArchitecture()); + // Assert.assertEquals("linux", platform1.getOs()); + // Assert.assertEquals("amd64", platform2.getArchitecture()); + // Assert.assertEquals("linux", platform2.getOs()); } @Test From ec3146310c09a9cea4c3c599d73f6404d96dd00d Mon Sep 17 00:00:00 2001 From: mpeddada1 Date: Sat, 15 Jun 2024 02:01:33 +0000 Subject: [PATCH 34/45] docker daemon --- .../java/com/google/cloud/tools/jib/api/JibIntegrationTest.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/jib-core/src/integration-test/java/com/google/cloud/tools/jib/api/JibIntegrationTest.java b/jib-core/src/integration-test/java/com/google/cloud/tools/jib/api/JibIntegrationTest.java index 742defba69..dd90f4ede4 100644 --- a/jib-core/src/integration-test/java/com/google/cloud/tools/jib/api/JibIntegrationTest.java +++ b/jib-core/src/integration-test/java/com/google/cloud/tools/jib/api/JibIntegrationTest.java @@ -429,7 +429,7 @@ public void testDistroless_ociManifest() ImmutableSet.of(new Platform("arm64", "linux"), new Platform("amd64", "linux"))) .containerize( Containerizer.to( - RegistryImage.named(dockerHost + ":6000/jib-distroless:multi-platform")) + DockerDaemonImage.named(dockerHost + ":6000/jib-distroless:multi-platform")) .setAllowInsecureRegistries(true)); // V22ManifestListTemplate manifestList = From c32a132408d9b1f8c1977d7b2518b667200806b5 Mon Sep 17 00:00:00 2001 From: mpeddada1 Date: Tue, 18 Jun 2024 23:40:01 +0000 Subject: [PATCH 35/45] add logging for tear down and move jib build into one test --- .../tools/jib/api/JibIntegrationTest.java | 25 +++++++++++++------ .../tools/jib/registry/LocalRegistry.java | 1 + kokoro/presubmit.sh | 2 +- 3 files changed, 20 insertions(+), 8 deletions(-) diff --git a/jib-core/src/integration-test/java/com/google/cloud/tools/jib/api/JibIntegrationTest.java b/jib-core/src/integration-test/java/com/google/cloud/tools/jib/api/JibIntegrationTest.java index dd90f4ede4..1deae3502c 100644 --- a/jib-core/src/integration-test/java/com/google/cloud/tools/jib/api/JibIntegrationTest.java +++ b/jib-core/src/integration-test/java/com/google/cloud/tools/jib/api/JibIntegrationTest.java @@ -423,21 +423,32 @@ public void testDistroless_ociManifest() throws IOException, InterruptedException, ExecutionException, RegistryException, CacheDirectoryCreationException, InvalidImageReferenceException { System.out.println("testDistroless_ociManifest()"); + System.out.println(Runtime.getRuntime().availableProcessors()); Jib.from("gcr.io/distroless/base@" + KNOWN_OCI_INDEX_SHA) .setPlatforms( ImmutableSet.of(new Platform("arm64", "linux"), new Platform("amd64", "linux"))) + // Pushing to registry causes next test to hang. .containerize( Containerizer.to( - DockerDaemonImage.named(dockerHost + ":6000/jib-distroless:multi-platform")) + RegistryImage.named(dockerHost + ":6000/jib-distroless:multi-platform")) .setAllowInsecureRegistries(true)); - // V22ManifestListTemplate manifestList = - // (V22ManifestListTemplate) - // distrolessRegistryClient.pullManifest("multi-platform").getManifest(); - // Assert.assertEquals(2, manifestList.getManifests().size()); - // ManifestDescriptorTemplate.Platform platform1 = - // manifestList.getManifests().get(0).getPlatform(); + String toImage = dockerHost + ":5000/docker-daemon-mismatched-arch"; + Jib.from( + RegistryImage.named( + "busybox@sha256:eb427d855f82782c110b48b9a398556c629ce4951ae252c6f6751a136e194668")) + .containerize(Containerizer.to(DockerDaemonImage.named(toImage))); + System.out.println("post-build"); + + V22ManifestListTemplate manifestList = + (V22ManifestListTemplate) + distrolessRegistryClient.pullManifest("multi-platform").getManifest(); + Assert.assertEquals(2, manifestList.getManifests().size()); + ManifestDescriptorTemplate.Platform platform1 = + manifestList.getManifests().get(0).getPlatform(); + System.out.println(platform1.getArchitecture()); + // ManifestDescriptorTemplate.Platform platform2 = // manifestList.getManifests().get(1).getPlatform(); // diff --git a/jib-core/src/integration-test/java/com/google/cloud/tools/jib/registry/LocalRegistry.java b/jib-core/src/integration-test/java/com/google/cloud/tools/jib/registry/LocalRegistry.java index c6cb6a16c8..cda1bc75c3 100644 --- a/jib-core/src/integration-test/java/com/google/cloud/tools/jib/registry/LocalRegistry.java +++ b/jib-core/src/integration-test/java/com/google/cloud/tools/jib/registry/LocalRegistry.java @@ -65,6 +65,7 @@ protected void before() throws IOException, InterruptedException { @Override protected void after() { + System.out.println("tear down"); stop(); } diff --git a/kokoro/presubmit.sh b/kokoro/presubmit.sh index 96d3acea40..837b45174f 100755 --- a/kokoro/presubmit.sh +++ b/kokoro/presubmit.sh @@ -26,4 +26,4 @@ docker kill $(docker ps --all --quiet | grep -v "$CONTAINER_ID") || true cd github/jib # we only run integration tests on jib-core for presubmit -./gradlew clean build :jib-core:integrationTest --info --stacktrace +./gradlew clean build :jib-core:integrationTest --tests "com.google.cloud.tools.jib.api.JibIntegrationTest.testDistroless_ociManifest" --info --stacktrace From a9f44153266770b761141afffa9589f255784ee2 Mon Sep 17 00:00:00 2001 From: mpeddada1 Date: Tue, 18 Jun 2024 23:57:21 +0000 Subject: [PATCH 36/45] debugging --- .../java/com/google/cloud/tools/jib/api/JibIntegrationTest.java | 1 + 1 file changed, 1 insertion(+) diff --git a/jib-core/src/integration-test/java/com/google/cloud/tools/jib/api/JibIntegrationTest.java b/jib-core/src/integration-test/java/com/google/cloud/tools/jib/api/JibIntegrationTest.java index 1deae3502c..57746893eb 100644 --- a/jib-core/src/integration-test/java/com/google/cloud/tools/jib/api/JibIntegrationTest.java +++ b/jib-core/src/integration-test/java/com/google/cloud/tools/jib/api/JibIntegrationTest.java @@ -433,6 +433,7 @@ public void testDistroless_ociManifest() Containerizer.to( RegistryImage.named(dockerHost + ":6000/jib-distroless:multi-platform")) .setAllowInsecureRegistries(true)); + System.out.println("Between builds"); String toImage = dockerHost + ":5000/docker-daemon-mismatched-arch"; Jib.from( From 72ab27cef031b823174aa38a5c53de31c7a07393 Mon Sep 17 00:00:00 2001 From: mpeddada1 Date: Wed, 19 Jun 2024 00:39:38 +0000 Subject: [PATCH 37/45] switch order --- .../cloud/tools/jib/api/JibIntegrationTest.java | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/jib-core/src/integration-test/java/com/google/cloud/tools/jib/api/JibIntegrationTest.java b/jib-core/src/integration-test/java/com/google/cloud/tools/jib/api/JibIntegrationTest.java index 57746893eb..dc3b768afc 100644 --- a/jib-core/src/integration-test/java/com/google/cloud/tools/jib/api/JibIntegrationTest.java +++ b/jib-core/src/integration-test/java/com/google/cloud/tools/jib/api/JibIntegrationTest.java @@ -425,6 +425,13 @@ public void testDistroless_ociManifest() System.out.println("testDistroless_ociManifest()"); System.out.println(Runtime.getRuntime().availableProcessors()); + String toImage = dockerHost + ":5000/docker-daemon-mismatched-arch"; + Jib.from( + RegistryImage.named( + "busybox@sha256:eb427d855f82782c110b48b9a398556c629ce4951ae252c6f6751a136e194668")) + .containerize(Containerizer.to(DockerDaemonImage.named(toImage))); + + System.out.println("Between builds"); Jib.from("gcr.io/distroless/base@" + KNOWN_OCI_INDEX_SHA) .setPlatforms( ImmutableSet.of(new Platform("arm64", "linux"), new Platform("amd64", "linux"))) @@ -433,13 +440,7 @@ public void testDistroless_ociManifest() Containerizer.to( RegistryImage.named(dockerHost + ":6000/jib-distroless:multi-platform")) .setAllowInsecureRegistries(true)); - System.out.println("Between builds"); - String toImage = dockerHost + ":5000/docker-daemon-mismatched-arch"; - Jib.from( - RegistryImage.named( - "busybox@sha256:eb427d855f82782c110b48b9a398556c629ce4951ae252c6f6751a136e194668")) - .containerize(Containerizer.to(DockerDaemonImage.named(toImage))); System.out.println("post-build"); V22ManifestListTemplate manifestList = From b1c242f865fd66c06da2279ef5e32043958fee88 Mon Sep 17 00:00:00 2001 From: mpeddada1 Date: Wed, 19 Jun 2024 00:52:10 +0000 Subject: [PATCH 38/45] sleep before next build --- .../cloud/tools/jib/api/JibIntegrationTest.java | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/jib-core/src/integration-test/java/com/google/cloud/tools/jib/api/JibIntegrationTest.java b/jib-core/src/integration-test/java/com/google/cloud/tools/jib/api/JibIntegrationTest.java index dc3b768afc..3116f96313 100644 --- a/jib-core/src/integration-test/java/com/google/cloud/tools/jib/api/JibIntegrationTest.java +++ b/jib-core/src/integration-test/java/com/google/cloud/tools/jib/api/JibIntegrationTest.java @@ -425,13 +425,6 @@ public void testDistroless_ociManifest() System.out.println("testDistroless_ociManifest()"); System.out.println(Runtime.getRuntime().availableProcessors()); - String toImage = dockerHost + ":5000/docker-daemon-mismatched-arch"; - Jib.from( - RegistryImage.named( - "busybox@sha256:eb427d855f82782c110b48b9a398556c629ce4951ae252c6f6751a136e194668")) - .containerize(Containerizer.to(DockerDaemonImage.named(toImage))); - - System.out.println("Between builds"); Jib.from("gcr.io/distroless/base@" + KNOWN_OCI_INDEX_SHA) .setPlatforms( ImmutableSet.of(new Platform("arm64", "linux"), new Platform("amd64", "linux"))) @@ -441,6 +434,13 @@ public void testDistroless_ociManifest() RegistryImage.named(dockerHost + ":6000/jib-distroless:multi-platform")) .setAllowInsecureRegistries(true)); + System.out.println("Between builds"); + Thread.sleep(2000); + String toImage = dockerHost + ":5000/docker-daemon-mismatched-arch"; + Jib.from( + RegistryImage.named( + "busybox@sha256:eb427d855f82782c110b48b9a398556c629ce4951ae252c6f6751a136e194668")) + .containerize(Containerizer.to(DockerDaemonImage.named(toImage))); System.out.println("post-build"); V22ManifestListTemplate manifestList = From 772c88343d79105757874b24114c7eac641985e7 Mon Sep 17 00:00:00 2001 From: mpeddada1 Date: Wed, 19 Jun 2024 01:10:40 +0000 Subject: [PATCH 39/45] check with timeout of 120 --- .../java/com/google/cloud/tools/jib/api/JibIntegrationTest.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/jib-core/src/integration-test/java/com/google/cloud/tools/jib/api/JibIntegrationTest.java b/jib-core/src/integration-test/java/com/google/cloud/tools/jib/api/JibIntegrationTest.java index 3116f96313..12a36b424e 100644 --- a/jib-core/src/integration-test/java/com/google/cloud/tools/jib/api/JibIntegrationTest.java +++ b/jib-core/src/integration-test/java/com/google/cloud/tools/jib/api/JibIntegrationTest.java @@ -435,7 +435,7 @@ public void testDistroless_ociManifest() .setAllowInsecureRegistries(true)); System.out.println("Between builds"); - Thread.sleep(2000); + Thread.sleep(120000); String toImage = dockerHost + ":5000/docker-daemon-mismatched-arch"; Jib.from( RegistryImage.named( From 9d51b1ff75a97cf72cb39d62bfff79e94d53fe17 Mon Sep 17 00:00:00 2001 From: mpeddada1 Date: Thu, 20 Jun 2024 14:57:10 +0000 Subject: [PATCH 40/45] fromScratch --- .../cloud/tools/jib/api/JibIntegrationTest.java | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/jib-core/src/integration-test/java/com/google/cloud/tools/jib/api/JibIntegrationTest.java b/jib-core/src/integration-test/java/com/google/cloud/tools/jib/api/JibIntegrationTest.java index 12a36b424e..97749e27ad 100644 --- a/jib-core/src/integration-test/java/com/google/cloud/tools/jib/api/JibIntegrationTest.java +++ b/jib-core/src/integration-test/java/com/google/cloud/tools/jib/api/JibIntegrationTest.java @@ -435,12 +435,13 @@ public void testDistroless_ociManifest() .setAllowInsecureRegistries(true)); System.out.println("Between builds"); - Thread.sleep(120000); + // Thread.sleep(120000); String toImage = dockerHost + ":5000/docker-daemon-mismatched-arch"; - Jib.from( - RegistryImage.named( - "busybox@sha256:eb427d855f82782c110b48b9a398556c629ce4951ae252c6f6751a136e194668")) - .containerize(Containerizer.to(DockerDaemonImage.named(toImage))); + // Jib.from( + // RegistryImage.named( + // + // "busybox@sha256:eb427d855f82782c110b48b9a398556c629ce4951ae252c6f6751a136e194668")) + Jib.fromScratch().containerize(Containerizer.to(DockerDaemonImage.named(toImage))); System.out.println("post-build"); V22ManifestListTemplate manifestList = From 74c25a2c5555973d47c1872a562a2e7c1b59a387 Mon Sep 17 00:00:00 2001 From: mpeddada1 Date: Thu, 20 Jun 2024 17:15:20 +0000 Subject: [PATCH 41/45] enable all tests --- .../tools/jib/api/JibIntegrationTest.java | 110 ++++++++---------- .../api/JibMultiPlatformIntegrationTest.java | 78 +++++++++++++ kokoro/presubmit.sh | 2 +- 3 files changed, 130 insertions(+), 60 deletions(-) create mode 100644 jib-core/src/integration-test/java/com/google/cloud/tools/jib/api/JibMultiPlatformIntegrationTest.java diff --git a/jib-core/src/integration-test/java/com/google/cloud/tools/jib/api/JibIntegrationTest.java b/jib-core/src/integration-test/java/com/google/cloud/tools/jib/api/JibIntegrationTest.java index 97749e27ad..5dd7e2c766 100644 --- a/jib-core/src/integration-test/java/com/google/cloud/tools/jib/api/JibIntegrationTest.java +++ b/jib-core/src/integration-test/java/com/google/cloud/tools/jib/api/JibIntegrationTest.java @@ -16,8 +16,6 @@ package com.google.cloud.tools.jib.api; -import static com.google.common.truth.Truth.assertThat; - import com.google.cloud.tools.jib.Command; import com.google.cloud.tools.jib.api.buildplan.Platform; import com.google.cloud.tools.jib.blob.Blobs; @@ -349,28 +347,30 @@ public void testBasic_jibImageToDockerDaemon() imageToDelete = toImage; } - @Test - public void testBasic_jibImageToDockerDaemon_arm64() - throws IOException, InterruptedException, InvalidImageReferenceException, ExecutionException, - RegistryException, CacheDirectoryCreationException { - System.out.println("testBasic_jibImageToDockerDaemon_arm64"); - - // Use arm64v8/busybox as base image. - String toImage = dockerHost + ":5000/docker-daemon-mismatched-arch"; - Jib.from( - RegistryImage.named( - "busybox@sha256:eb427d855f82782c110b48b9a398556c629ce4951ae252c6f6751a136e194668")) - .containerize(Containerizer.to(DockerDaemonImage.named(toImage))); - String os = - new Command("docker", "inspect", toImage, "--format", "{{.Os}}").run().replace("\n", ""); - String architecture = - new Command("docker", "inspect", toImage, "--format", "{{.Architecture}}") - .run() - .replace("\n", ""); - assertThat(os).isEqualTo("linux"); - assertThat(architecture).isEqualTo("arm64"); - imageToDelete = toImage; - } + // @Test + // public void testBasic_jibImageToDockerDaemon_arm64() + // throws IOException, InterruptedException, InvalidImageReferenceException, + // ExecutionException, + // RegistryException, CacheDirectoryCreationException { + // System.out.println("testBasic_jibImageToDockerDaemon_arm64"); + // + // // Use arm64v8/busybox as base image. + // String toImage = dockerHost + ":5000/docker-daemon-mismatched-arch"; + // Jib.from( + // RegistryImage.named( + // + // "busybox@sha256:eb427d855f82782c110b48b9a398556c629ce4951ae252c6f6751a136e194668")) + // .containerize(Containerizer.to(DockerDaemonImage.named(toImage))); + // String os = + // new Command("docker", "inspect", toImage, "--format", "{{.Os}}").run().replace("\n", ""); + // String architecture = + // new Command("docker", "inspect", toImage, "--format", "{{.Architecture}}") + // .run() + // .replace("\n", ""); + // assertThat(os).isEqualTo("linux"); + // assertThat(architecture).isEqualTo("arm64"); + // imageToDelete = toImage; + // } @Test public void testBasicMultiPlatform_toDockerDaemon() @@ -393,37 +393,38 @@ public void testBasicMultiPlatform_toDockerDaemon() imageToDelete = toImage; } - @Test - public void testBasicMultiPlatform_toDockerDaemon_pickFirstPlatformWhenNoMatchingImage() - throws IOException, InterruptedException, InvalidImageReferenceException, - CacheDirectoryCreationException, ExecutionException, RegistryException { - System.out.println( - "testBasicMultiPlatform_toDockerDaemon_pickFirstPlatformWhenNoMatchingImage()"); - - String toImage = dockerHost + ":5000/docker-daemon-multi-plat-mismatched-configs"; - Jib.from( - RegistryImage.named( - "busybox@sha256:4f47c01fa91355af2865ac10fef5bf6ec9c7f42ad2321377c21e844427972977")) - .setPlatforms(ImmutableSet.of(new Platform("s390x", "linux"), new Platform("arm", "linux"))) - .containerize( - Containerizer.to(DockerDaemonImage.named(toImage)).setAllowInsecureRegistries(true)); - String os = - new Command("docker", "inspect", toImage, "--format", "{{.Os}}").run().replace("\n", ""); - String architecture = - new Command("docker", "inspect", toImage, "--format", "{{.Architecture}}") - .run() - .replace("\n", ""); - assertThat(os).isEqualTo("linux"); - assertThat(architecture).isEqualTo("s390x"); - imageToDelete = toImage; - } + // @Test + // public void testBasicMultiPlatform_toDockerDaemon_pickFirstPlatformWhenNoMatchingImage() + // throws IOException, InterruptedException, InvalidImageReferenceException, + // CacheDirectoryCreationException, ExecutionException, RegistryException { + // System.out.println( + // "testBasicMultiPlatform_toDockerDaemon_pickFirstPlatformWhenNoMatchingImage()"); + // + // String toImage = dockerHost + ":5000/docker-daemon-multi-plat-mismatched-configs"; + // Jib.from( + // RegistryImage.named( + // + // "busybox@sha256:4f47c01fa91355af2865ac10fef5bf6ec9c7f42ad2321377c21e844427972977")) + // .setPlatforms(ImmutableSet.of(new Platform("s390x", "linux"), new Platform("arm", + // "linux"))) + // .containerize( + // Containerizer.to(DockerDaemonImage.named(toImage)).setAllowInsecureRegistries(true)); + // String os = + // new Command("docker", "inspect", toImage, "--format", "{{.Os}}").run().replace("\n", ""); + // String architecture = + // new Command("docker", "inspect", toImage, "--format", "{{.Architecture}}") + // .run() + // .replace("\n", ""); + // assertThat(os).isEqualTo("linux"); + // assertThat(architecture).isEqualTo("s390x"); + // imageToDelete = toImage; + // } @Test public void testDistroless_ociManifest() throws IOException, InterruptedException, ExecutionException, RegistryException, CacheDirectoryCreationException, InvalidImageReferenceException { - System.out.println("testDistroless_ociManifest()"); - System.out.println(Runtime.getRuntime().availableProcessors()); + System.out.println("testDistroless_ociManifest() "); Jib.from("gcr.io/distroless/base@" + KNOWN_OCI_INDEX_SHA) .setPlatforms( @@ -433,15 +434,6 @@ public void testDistroless_ociManifest() Containerizer.to( RegistryImage.named(dockerHost + ":6000/jib-distroless:multi-platform")) .setAllowInsecureRegistries(true)); - - System.out.println("Between builds"); - // Thread.sleep(120000); - String toImage = dockerHost + ":5000/docker-daemon-mismatched-arch"; - // Jib.from( - // RegistryImage.named( - // - // "busybox@sha256:eb427d855f82782c110b48b9a398556c629ce4951ae252c6f6751a136e194668")) - Jib.fromScratch().containerize(Containerizer.to(DockerDaemonImage.named(toImage))); System.out.println("post-build"); V22ManifestListTemplate manifestList = diff --git a/jib-core/src/integration-test/java/com/google/cloud/tools/jib/api/JibMultiPlatformIntegrationTest.java b/jib-core/src/integration-test/java/com/google/cloud/tools/jib/api/JibMultiPlatformIntegrationTest.java new file mode 100644 index 0000000000..9e768c5620 --- /dev/null +++ b/jib-core/src/integration-test/java/com/google/cloud/tools/jib/api/JibMultiPlatformIntegrationTest.java @@ -0,0 +1,78 @@ +package com.google.cloud.tools.jib.api; + +import static com.google.common.truth.Truth.assertThat; + +import com.google.cloud.tools.jib.Command; +import com.google.cloud.tools.jib.api.buildplan.Platform; +import com.google.cloud.tools.jib.registry.LocalRegistry; +import com.google.common.collect.ImmutableSet; +import java.io.IOException; +import java.util.concurrent.ExecutionException; +import org.junit.After; +import org.junit.ClassRule; +import org.junit.Test; + +public class JibMultiPlatformIntegrationTest { + + @ClassRule public static final LocalRegistry localRegistry = new LocalRegistry(5000); + + private final String dockerHost = + System.getenv("DOCKER_IP") != null ? System.getenv("DOCKER_IP") : "localhost"; + private String imageToDelete; + + @After + public void tearDown() throws IOException, InterruptedException { + System.clearProperty("sendCredentialsOverHttp"); + if (imageToDelete != null) { + new Command("docker", "rmi", imageToDelete).run(); + } + } + + @Test + public void testBasic_jibImageToDockerDaemon_arm64() + throws IOException, InterruptedException, InvalidImageReferenceException, ExecutionException, + RegistryException, CacheDirectoryCreationException { + System.out.println("testBasic_jibImageToDockerDaemon_arm64"); + + // Use arm64v8/busybox as base image. + String toImage = dockerHost + ":5000/docker-daemon-mismatched-arch"; + Jib.from( + RegistryImage.named( + "busybox@sha256:eb427d855f82782c110b48b9a398556c629ce4951ae252c6f6751a136e194668")) + .containerize(Containerizer.to(DockerDaemonImage.named(toImage))); + String os = + new Command("docker", "inspect", toImage, "--format", "{{.Os}}").run().replace("\n", ""); + String architecture = + new Command("docker", "inspect", toImage, "--format", "{{.Architecture}}") + .run() + .replace("\n", ""); + assertThat(os).isEqualTo("linux"); + assertThat(architecture).isEqualTo("arm64"); + imageToDelete = toImage; + } + + @Test + public void testBasicMultiPlatform_toDockerDaemon_pickFirstPlatformWhenNoMatchingImage() + throws IOException, InterruptedException, InvalidImageReferenceException, + CacheDirectoryCreationException, ExecutionException, RegistryException { + System.out.println( + "testBasicMultiPlatform_toDockerDaemon_pickFirstPlatformWhenNoMatchingImage()"); + + String toImage = dockerHost + ":5000/docker-daemon-multi-plat-mismatched-configs"; + Jib.from( + RegistryImage.named( + "busybox@sha256:4f47c01fa91355af2865ac10fef5bf6ec9c7f42ad2321377c21e844427972977")) + .setPlatforms(ImmutableSet.of(new Platform("s390x", "linux"), new Platform("arm", "linux"))) + .containerize( + Containerizer.to(DockerDaemonImage.named(toImage)).setAllowInsecureRegistries(true)); + String os = + new Command("docker", "inspect", toImage, "--format", "{{.Os}}").run().replace("\n", ""); + String architecture = + new Command("docker", "inspect", toImage, "--format", "{{.Architecture}}") + .run() + .replace("\n", ""); + assertThat(os).isEqualTo("linux"); + assertThat(architecture).isEqualTo("s390x"); + imageToDelete = toImage; + } +} diff --git a/kokoro/presubmit.sh b/kokoro/presubmit.sh index 837b45174f..96d3acea40 100755 --- a/kokoro/presubmit.sh +++ b/kokoro/presubmit.sh @@ -26,4 +26,4 @@ docker kill $(docker ps --all --quiet | grep -v "$CONTAINER_ID") || true cd github/jib # we only run integration tests on jib-core for presubmit -./gradlew clean build :jib-core:integrationTest --tests "com.google.cloud.tools.jib.api.JibIntegrationTest.testDistroless_ociManifest" --info --stacktrace +./gradlew clean build :jib-core:integrationTest --info --stacktrace From 3adfb49b54cd61f47032bc6d0cadcb1dc9d5cdba Mon Sep 17 00:00:00 2001 From: mpeddada1 Date: Thu, 20 Jun 2024 17:19:57 +0000 Subject: [PATCH 42/45] add header --- .../jib/api/JibMultiPlatformIntegrationTest.java | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/jib-core/src/integration-test/java/com/google/cloud/tools/jib/api/JibMultiPlatformIntegrationTest.java b/jib-core/src/integration-test/java/com/google/cloud/tools/jib/api/JibMultiPlatformIntegrationTest.java index 9e768c5620..fcc1cb66f9 100644 --- a/jib-core/src/integration-test/java/com/google/cloud/tools/jib/api/JibMultiPlatformIntegrationTest.java +++ b/jib-core/src/integration-test/java/com/google/cloud/tools/jib/api/JibMultiPlatformIntegrationTest.java @@ -1,3 +1,19 @@ +/* + * Copyright 2024 Google LLC. + * + * 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 + * + * http://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 com.google.cloud.tools.jib.api; import static com.google.common.truth.Truth.assertThat; From ebc6c142c52d8be6a68f58d8aa10ab3e2132c63d Mon Sep 17 00:00:00 2001 From: mpeddada1 Date: Fri, 21 Jun 2024 03:56:16 +0000 Subject: [PATCH 43/45] clean up tests; fix logging --- .../tools/jib/api/JibIntegrationTest.java | 122 ++---------------- .../api/JibMultiPlatformIntegrationTest.java | 25 +++- .../tools/jib/builder/steps/StepsRunner.java | 23 ++-- .../jib/builder/steps/StepsRunnerTest.java | 11 +- 4 files changed, 49 insertions(+), 132 deletions(-) diff --git a/jib-core/src/integration-test/java/com/google/cloud/tools/jib/api/JibIntegrationTest.java b/jib-core/src/integration-test/java/com/google/cloud/tools/jib/api/JibIntegrationTest.java index 5dd7e2c766..b748de6247 100644 --- a/jib-core/src/integration-test/java/com/google/cloud/tools/jib/api/JibIntegrationTest.java +++ b/jib-core/src/integration-test/java/com/google/cloud/tools/jib/api/JibIntegrationTest.java @@ -54,7 +54,6 @@ public class JibIntegrationTest { "sha256:2c50b819aa3bfaf6ae72e47682f6c5abc0f647cf3f4224a4a9be97dd30433909"; @ClassRule public static final LocalRegistry localRegistry = new LocalRegistry(5000); - @ClassRule public static final LocalRegistry localRegistry2 = new LocalRegistry(6000); @Rule public final TemporaryFolder temporaryFolder = new TemporaryFolder(); @@ -74,7 +73,7 @@ public class JibIntegrationTest { private final RegistryClient distrolessRegistryClient = RegistryClient.factory( EventHandlers.NONE, - dockerHost + ":6000", + dockerHost + ":5000", "jib-distroless", new FailoverHttpClient(true, true, ignored -> {})) .newRegistryClient(); @@ -115,7 +114,6 @@ public void tearDown() throws IOException, InterruptedException { public void testBasic_helloWorld() throws InvalidImageReferenceException, InterruptedException, CacheDirectoryCreationException, IOException, RegistryException, ExecutionException { - System.out.println("testBasic_helloWorld()"); String toImage = dockerHost + ":5000/basic-helloworld"; JibContainer jibContainer = Jib.from(dockerHost + ":5000/busybox") @@ -133,7 +131,6 @@ public void testBasic_helloWorld() public void testBasic_dockerDaemonBaseImage() throws IOException, InterruptedException, InvalidImageReferenceException, ExecutionException, RegistryException, CacheDirectoryCreationException { - System.out.println("testBasic_dockerDaemonBaseImage()"); String toImage = dockerHost + ":5000/basic-dockerdaemon"; JibContainer jibContainer = Jib.from("docker://" + dockerHost + ":5000/busybox") @@ -151,7 +148,6 @@ public void testBasic_dockerDaemonBaseImage() public void testBasic_dockerDaemonBaseImageToDockerDaemon() throws IOException, InterruptedException, InvalidImageReferenceException, ExecutionException, RegistryException, CacheDirectoryCreationException { - System.out.println("testBasic_dockerDaemonBaseImageToDockerDaemon()"); String toImage = dockerHost + ":5000/docker-to-docker"; Jib.from(DockerDaemonImage.named(dockerHost + ":5000/busybox")) .setEntrypoint("echo", "Hello World") @@ -166,8 +162,6 @@ public void testBasic_dockerDaemonBaseImageToDockerDaemon() public void testBasic_tarBaseImage_dockerSavedCommand() throws IOException, InterruptedException, InvalidImageReferenceException, ExecutionException, RegistryException, CacheDirectoryCreationException { - System.out.println("testBasic_tarBaseImage_dockerSavedCommand()"); - Path path = temporaryFolder.getRoot().toPath().resolve("docker-save.tar"); new Command("docker", "save", dockerHost + ":5000/busybox", "-o=" + path).run(); @@ -188,8 +182,6 @@ public void testBasic_tarBaseImage_dockerSavedCommand() public void testBasic_tarBaseImage_dockerSavedFile() throws IOException, InterruptedException, InvalidImageReferenceException, ExecutionException, RegistryException, CacheDirectoryCreationException, URISyntaxException { - System.out.println("testBasic_tarBaseImage_dockerSavedFile()"); - // tar saved with 'docker save busybox -o busybox.tar' Path path = Paths.get(Resources.getResource("core/busybox-docker.tar").toURI()); @@ -209,8 +201,6 @@ public void testBasic_tarBaseImage_dockerSavedFile() public void testBasic_tarBaseImage_jibImage() throws InvalidImageReferenceException, InterruptedException, ExecutionException, RegistryException, CacheDirectoryCreationException, IOException, URISyntaxException { - System.out.println("testBasic_tarBaseImage_jibImage()"); - Path outputPath = temporaryFolder.getRoot().toPath().resolve("jib-image.tar"); Jib.from(dockerHost + ":5000/busybox") .addLayer( @@ -235,8 +225,6 @@ public void testBasic_tarBaseImage_jibImage() public void testBasic_tarBaseImage_jibImageToDockerDaemon() throws InvalidImageReferenceException, InterruptedException, ExecutionException, RegistryException, CacheDirectoryCreationException, IOException, URISyntaxException { - System.out.println("testBasic_tarBaseImage_jibImageToDockerDaemon()"); - // tar saved with Jib.from("busybox").addLayer(...("core/hello")).containerize(TarImage.at...) Path path = Paths.get(Resources.getResource("core/busybox-jib.tar").toURI()); @@ -257,8 +245,6 @@ public void testBasic_tarBaseImage_jibImageToDockerDaemon() public void testScratch_defaultPlatform() throws IOException, InterruptedException, ExecutionException, RegistryException, CacheDirectoryCreationException, InvalidImageReferenceException { - System.out.println("testScratch_defaultPlatform()"); - Jib.fromScratch() .containerize( Containerizer.to(RegistryImage.named(dockerHost + ":5000/jib-scratch:default-platform")) @@ -282,8 +268,6 @@ public void testScratch_defaultPlatform() public void testScratch_singlePlatform() throws IOException, InterruptedException, ExecutionException, RegistryException, CacheDirectoryCreationException, InvalidImageReferenceException { - System.out.println("testScratch_singlePlatform()"); - Jib.fromScratch() .setPlatforms(ImmutableSet.of(new Platform("arm64", "windows"))) .containerize( @@ -308,8 +292,6 @@ public void testScratch_singlePlatform() public void testScratch_multiPlatform() throws IOException, InterruptedException, ExecutionException, RegistryException, CacheDirectoryCreationException, InvalidImageReferenceException { - System.out.println("testScratch_multiPlatform()"); - Jib.fromScratch() .setPlatforms( ImmutableSet.of(new Platform("arm64", "windows"), new Platform("amd32", "windows"))) @@ -335,8 +317,6 @@ public void testScratch_multiPlatform() public void testBasic_jibImageToDockerDaemon() throws IOException, InterruptedException, InvalidImageReferenceException, ExecutionException, RegistryException, CacheDirectoryCreationException { - System.out.println("testBasic_jibImageToDockerDaemon()"); - String toImage = dockerHost + ":5000/docker-to-docker"; Jib.from(DockerDaemonImage.named(dockerHost + ":5000/busybox")) .setEntrypoint("echo", "Hello World") @@ -347,94 +327,18 @@ public void testBasic_jibImageToDockerDaemon() imageToDelete = toImage; } - // @Test - // public void testBasic_jibImageToDockerDaemon_arm64() - // throws IOException, InterruptedException, InvalidImageReferenceException, - // ExecutionException, - // RegistryException, CacheDirectoryCreationException { - // System.out.println("testBasic_jibImageToDockerDaemon_arm64"); - // - // // Use arm64v8/busybox as base image. - // String toImage = dockerHost + ":5000/docker-daemon-mismatched-arch"; - // Jib.from( - // RegistryImage.named( - // - // "busybox@sha256:eb427d855f82782c110b48b9a398556c629ce4951ae252c6f6751a136e194668")) - // .containerize(Containerizer.to(DockerDaemonImage.named(toImage))); - // String os = - // new Command("docker", "inspect", toImage, "--format", "{{.Os}}").run().replace("\n", ""); - // String architecture = - // new Command("docker", "inspect", toImage, "--format", "{{.Architecture}}") - // .run() - // .replace("\n", ""); - // assertThat(os).isEqualTo("linux"); - // assertThat(architecture).isEqualTo("arm64"); - // imageToDelete = toImage; - // } - - @Test - public void testBasicMultiPlatform_toDockerDaemon() - throws IOException, InterruptedException, ExecutionException, RegistryException, - CacheDirectoryCreationException, InvalidImageReferenceException { - System.out.println("testBasicMultiPlatform_toDockerDaemon()"); - - String toImage = dockerHost + ":5000/docker-daemon-multi-platform"; - Jib.from( - RegistryImage.named( - "busybox@sha256:4f47c01fa91355af2865ac10fef5bf6ec9c7f42ad2321377c21e844427972977")) - .setPlatforms( - ImmutableSet.of(new Platform("arm64", "linux"), new Platform("amd64", "linux"))) - .setEntrypoint("echo", "Hello World") - .containerize( - Containerizer.to(DockerDaemonImage.named(toImage)).setAllowInsecureRegistries(true)); - - String output = new Command("docker", "run", "--rm", toImage).run(); - Assert.assertEquals("Hello World\n", output); - imageToDelete = toImage; - } - - // @Test - // public void testBasicMultiPlatform_toDockerDaemon_pickFirstPlatformWhenNoMatchingImage() - // throws IOException, InterruptedException, InvalidImageReferenceException, - // CacheDirectoryCreationException, ExecutionException, RegistryException { - // System.out.println( - // "testBasicMultiPlatform_toDockerDaemon_pickFirstPlatformWhenNoMatchingImage()"); - // - // String toImage = dockerHost + ":5000/docker-daemon-multi-plat-mismatched-configs"; - // Jib.from( - // RegistryImage.named( - // - // "busybox@sha256:4f47c01fa91355af2865ac10fef5bf6ec9c7f42ad2321377c21e844427972977")) - // .setPlatforms(ImmutableSet.of(new Platform("s390x", "linux"), new Platform("arm", - // "linux"))) - // .containerize( - // Containerizer.to(DockerDaemonImage.named(toImage)).setAllowInsecureRegistries(true)); - // String os = - // new Command("docker", "inspect", toImage, "--format", "{{.Os}}").run().replace("\n", ""); - // String architecture = - // new Command("docker", "inspect", toImage, "--format", "{{.Architecture}}") - // .run() - // .replace("\n", ""); - // assertThat(os).isEqualTo("linux"); - // assertThat(architecture).isEqualTo("s390x"); - // imageToDelete = toImage; - // } - @Test public void testDistroless_ociManifest() throws IOException, InterruptedException, ExecutionException, RegistryException, CacheDirectoryCreationException, InvalidImageReferenceException { - System.out.println("testDistroless_ociManifest() "); - Jib.from("gcr.io/distroless/base@" + KNOWN_OCI_INDEX_SHA) .setPlatforms( ImmutableSet.of(new Platform("arm64", "linux"), new Platform("amd64", "linux"))) // Pushing to registry causes next test to hang. .containerize( Containerizer.to( - RegistryImage.named(dockerHost + ":6000/jib-distroless:multi-platform")) + RegistryImage.named(dockerHost + ":5000/jib-distroless:multi-platform")) .setAllowInsecureRegistries(true)); - System.out.println("post-build"); V22ManifestListTemplate manifestList = (V22ManifestListTemplate) @@ -442,23 +346,19 @@ public void testDistroless_ociManifest() Assert.assertEquals(2, manifestList.getManifests().size()); ManifestDescriptorTemplate.Platform platform1 = manifestList.getManifests().get(0).getPlatform(); - System.out.println(platform1.getArchitecture()); - - // ManifestDescriptorTemplate.Platform platform2 = - // manifestList.getManifests().get(1).getPlatform(); - // - // Assert.assertEquals("arm64", platform1.getArchitecture()); - // Assert.assertEquals("linux", platform1.getOs()); - // Assert.assertEquals("amd64", platform2.getArchitecture()); - // Assert.assertEquals("linux", platform2.getOs()); + ManifestDescriptorTemplate.Platform platform2 = + manifestList.getManifests().get(1).getPlatform(); + + Assert.assertEquals("arm64", platform1.getArchitecture()); + Assert.assertEquals("linux", platform1.getOs()); + Assert.assertEquals("amd64", platform2.getArchitecture()); + Assert.assertEquals("linux", platform2.getOs()); } @Test public void testOffline() throws IOException, InterruptedException, InvalidImageReferenceException, ExecutionException, RegistryException, CacheDirectoryCreationException { - System.out.println("testOffline"); - Path cacheDirectory = temporaryFolder.getRoot().toPath(); JibContainerBuilder jibContainerBuilder = @@ -510,8 +410,6 @@ public void testOffline() public void testProvidedExecutorNotDisposed() throws InvalidImageReferenceException, InterruptedException, CacheDirectoryCreationException, IOException, RegistryException, ExecutionException { - System.out.println("testProvidedExecutorNotDisposed"); - ExecutorService executorService = Executors.newCachedThreadPool(); try { Jib.fromScratch() @@ -529,8 +427,6 @@ public void testProvidedExecutorNotDisposed() public void testManifestListReferenceByShaDoesNotFail() throws InvalidImageReferenceException, IOException, InterruptedException, ExecutionException, RegistryException, CacheDirectoryCreationException { - System.out.println("testManifestListReferenceByShaDoesNotFail()"); - Containerizer containerizer = Containerizer.to(TarImage.at(temporaryFolder.newFile("goose").toPath()).named("whatever")); diff --git a/jib-core/src/integration-test/java/com/google/cloud/tools/jib/api/JibMultiPlatformIntegrationTest.java b/jib-core/src/integration-test/java/com/google/cloud/tools/jib/api/JibMultiPlatformIntegrationTest.java index fcc1cb66f9..df00fe04d0 100644 --- a/jib-core/src/integration-test/java/com/google/cloud/tools/jib/api/JibMultiPlatformIntegrationTest.java +++ b/jib-core/src/integration-test/java/com/google/cloud/tools/jib/api/JibMultiPlatformIntegrationTest.java @@ -25,6 +25,7 @@ import java.io.IOException; import java.util.concurrent.ExecutionException; import org.junit.After; +import org.junit.Assert; import org.junit.ClassRule; import org.junit.Test; @@ -48,8 +49,6 @@ public void tearDown() throws IOException, InterruptedException { public void testBasic_jibImageToDockerDaemon_arm64() throws IOException, InterruptedException, InvalidImageReferenceException, ExecutionException, RegistryException, CacheDirectoryCreationException { - System.out.println("testBasic_jibImageToDockerDaemon_arm64"); - // Use arm64v8/busybox as base image. String toImage = dockerHost + ":5000/docker-daemon-mismatched-arch"; Jib.from( @@ -71,9 +70,6 @@ public void testBasic_jibImageToDockerDaemon_arm64() public void testBasicMultiPlatform_toDockerDaemon_pickFirstPlatformWhenNoMatchingImage() throws IOException, InterruptedException, InvalidImageReferenceException, CacheDirectoryCreationException, ExecutionException, RegistryException { - System.out.println( - "testBasicMultiPlatform_toDockerDaemon_pickFirstPlatformWhenNoMatchingImage()"); - String toImage = dockerHost + ":5000/docker-daemon-multi-plat-mismatched-configs"; Jib.from( RegistryImage.named( @@ -91,4 +87,23 @@ public void testBasicMultiPlatform_toDockerDaemon_pickFirstPlatformWhenNoMatchin assertThat(architecture).isEqualTo("s390x"); imageToDelete = toImage; } + + @Test + public void testBasicMultiPlatform_toDockerDaemon() + throws IOException, InterruptedException, ExecutionException, RegistryException, + CacheDirectoryCreationException, InvalidImageReferenceException { + String toImage = dockerHost + ":5000/docker-daemon-multi-platform"; + Jib.from( + RegistryImage.named( + "busybox@sha256:4f47c01fa91355af2865ac10fef5bf6ec9c7f42ad2321377c21e844427972977")) + .setPlatforms( + ImmutableSet.of(new Platform("arm64", "linux"), new Platform("amd64", "linux"))) + .setEntrypoint("echo", "Hello World") + .containerize( + Containerizer.to(DockerDaemonImage.named(toImage)).setAllowInsecureRegistries(true)); + + String output = new Command("docker", "run", "--rm", toImage).run(); + Assert.assertEquals("Hello World\n", output); + imageToDelete = toImage; + } } diff --git a/jib-core/src/main/java/com/google/cloud/tools/jib/builder/steps/StepsRunner.java b/jib-core/src/main/java/com/google/cloud/tools/jib/builder/steps/StepsRunner.java index ba35eea77d..4cfeb5c173 100644 --- a/jib-core/src/main/java/com/google/cloud/tools/jib/builder/steps/StepsRunner.java +++ b/jib-core/src/main/java/com/google/cloud/tools/jib/builder/steps/StepsRunner.java @@ -19,12 +19,14 @@ import com.google.cloud.tools.jib.api.DescriptorDigest; import com.google.cloud.tools.jib.api.DockerClient; import com.google.cloud.tools.jib.api.DockerInfoDetails; +import com.google.cloud.tools.jib.api.LogEvent; import com.google.cloud.tools.jib.blob.BlobDescriptor; import com.google.cloud.tools.jib.builder.ProgressEventDispatcher; import com.google.cloud.tools.jib.builder.steps.LocalBaseImageSteps.LocalImage; import com.google.cloud.tools.jib.builder.steps.PullBaseImageStep.ImagesAndRegistryClient; import com.google.cloud.tools.jib.configuration.BuildContext; import com.google.cloud.tools.jib.configuration.ImageConfiguration; +import com.google.cloud.tools.jib.event.EventHandlers; import com.google.cloud.tools.jib.filesystem.TempDirectoryProvider; import com.google.cloud.tools.jib.global.JibSystemProperties; import com.google.cloud.tools.jib.image.Image; @@ -53,7 +55,6 @@ import java.util.concurrent.ExecutorService; import java.util.concurrent.Future; import java.util.function.Consumer; -import java.util.logging.Logger; import java.util.stream.Collectors; import javax.annotation.Nullable; @@ -66,8 +67,6 @@ */ public class StepsRunner { - private static final Logger LOGGER = Logger.getLogger(StepsRunner.class.getName()); - /** Holds the individual step results. */ private static class StepResults { @@ -624,7 +623,9 @@ private void loadDocker( DockerInfoDetails dockerInfoDetails = dockerClient.info(); String osType = dockerInfoDetails.getOsType(); String architecture = normalizeArchitecture(dockerInfoDetails.getArchitecture()); - Image builtImage = fetchBuiltImageForLocalBuild(osType, architecture); + Image builtImage = + fetchBuiltImageForLocalBuild( + osType, architecture, buildContext.getEventHandlers()); return new LoadDockerStep( buildContext, progressDispatcherFactory, dockerClient, builtImage) .call(); @@ -664,14 +665,16 @@ String normalizeArchitecture(String architecture) { } @VisibleForTesting - Image fetchBuiltImageForLocalBuild(String osType, String architecture) + Image fetchBuiltImageForLocalBuild( + String osType, String architecture, EventHandlers eventHandlers) throws InterruptedException, ExecutionException { if (results.baseImagesAndBuiltImages.get().size() > 1) { - LOGGER.warning( - String.format( - "Detected multi-platform configuration, only building the one that matches the local Docker Engine's os and architecture (%s/%s) or " - + "the first platform specified", - osType, architecture)); + eventHandlers.dispatch( + LogEvent.warn( + String.format( + "Detected multi-platform configuration, only building image that matches the local Docker Engine's os and architecture (%s/%s) or " + + "the first platform specified", + osType, architecture))); for (Map.Entry> imageEntry : results.baseImagesAndBuiltImages.get().entrySet()) { Image image = imageEntry.getValue().get(); diff --git a/jib-core/src/test/java/com/google/cloud/tools/jib/builder/steps/StepsRunnerTest.java b/jib-core/src/test/java/com/google/cloud/tools/jib/builder/steps/StepsRunnerTest.java index 54154ff751..6468ee051b 100644 --- a/jib-core/src/test/java/com/google/cloud/tools/jib/builder/steps/StepsRunnerTest.java +++ b/jib-core/src/test/java/com/google/cloud/tools/jib/builder/steps/StepsRunnerTest.java @@ -23,6 +23,7 @@ import com.google.cloud.tools.jib.builder.ProgressEventDispatcher; import com.google.cloud.tools.jib.builder.steps.PullBaseImageStep.ImagesAndRegistryClient; import com.google.cloud.tools.jib.configuration.BuildContext; +import com.google.cloud.tools.jib.event.EventHandlers; import com.google.cloud.tools.jib.global.JibSystemProperties; import com.google.cloud.tools.jib.image.DigestOnlyLayer; import com.google.cloud.tools.jib.image.Image; @@ -84,6 +85,7 @@ protected ExecutorService delegate() { } @Mock private BuildContext buildContext; + @Mock private EventHandlers eventHandlers; @Mock private ProgressEventDispatcher.Factory progressDispatcherFactory; @Mock private ProgressEventDispatcher progressDispatcher; @Mock private ExecutorService executorService; @@ -203,7 +205,8 @@ public void testFetchBuildImageForLocalBuild_matchingOsAndArch() Futures.immediateFuture(builtAmd64AndWindowsImage)))); stepsRunner.buildImages(progressDispatcherFactory); - Image expectedImage = stepsRunner.fetchBuiltImageForLocalBuild("windows", "amd64"); + Image expectedImage = + stepsRunner.fetchBuiltImageForLocalBuild("windows", "amd64", eventHandlers); assertThat(expectedImage.getOs()).isEqualTo("windows"); assertThat(expectedImage.getArchitecture()).isEqualTo("amd64"); @@ -225,7 +228,7 @@ public void testFetchBuildImageForLocalBuild_differentOs_buildImageForFirstPlatf Futures.immediateFuture(builtAmd64AndWindowsImage)))); stepsRunner.buildImages(progressDispatcherFactory); - Image expectedImage = stepsRunner.fetchBuiltImageForLocalBuild("os", "arm64"); + Image expectedImage = stepsRunner.fetchBuiltImageForLocalBuild("os", "arm64", eventHandlers); assertThat(expectedImage.getOs()).isEqualTo("linux"); assertThat(expectedImage.getArchitecture()).isEqualTo("arm64"); @@ -246,7 +249,7 @@ public void testFetchBuildImageForLocalBuild_differentArch_buildImageForFirstPla Futures.immediateFuture(builtAmd64AndWindowsImage)))); stepsRunner.buildImages(progressDispatcherFactory); - Image expectedImage = stepsRunner.fetchBuiltImageForLocalBuild("linux", "arch"); + Image expectedImage = stepsRunner.fetchBuiltImageForLocalBuild("linux", "arch", eventHandlers); assertThat(expectedImage.getArchitecture()).isEqualTo("arm64"); } @@ -262,7 +265,7 @@ public void testFetchBuildImageForLocalBuild_singleImage_imagePlatformDifferentF ImmutableMap.of(baseImage1, Futures.immediateFuture(builtArm64AndLinuxImage)))); stepsRunner.buildImages(progressDispatcherFactory); - Image expectedImage = stepsRunner.fetchBuiltImageForLocalBuild("linux", "amd64"); + Image expectedImage = stepsRunner.fetchBuiltImageForLocalBuild("linux", "amd64", eventHandlers); assertThat(expectedImage.getOs()).isEqualTo("linux"); assertThat(expectedImage.getArchitecture()).isEqualTo("arm64"); From 841f207087df5c652d05ced781adff5d02bb9fe0 Mon Sep 17 00:00:00 2001 From: mpeddada1 Date: Fri, 21 Jun 2024 04:00:00 +0000 Subject: [PATCH 44/45] undo debugging logs --- .../java/com/google/cloud/tools/jib/registry/LocalRegistry.java | 1 - 1 file changed, 1 deletion(-) diff --git a/jib-core/src/integration-test/java/com/google/cloud/tools/jib/registry/LocalRegistry.java b/jib-core/src/integration-test/java/com/google/cloud/tools/jib/registry/LocalRegistry.java index cda1bc75c3..c6cb6a16c8 100644 --- a/jib-core/src/integration-test/java/com/google/cloud/tools/jib/registry/LocalRegistry.java +++ b/jib-core/src/integration-test/java/com/google/cloud/tools/jib/registry/LocalRegistry.java @@ -65,7 +65,6 @@ protected void before() throws IOException, InterruptedException { @Override protected void after() { - System.out.println("tear down"); stop(); } From 71772a6025cc0dfc84fcfb473e82f9217953d44d Mon Sep 17 00:00:00 2001 From: mpeddada1 Date: Mon, 24 Jun 2024 22:12:14 +0000 Subject: [PATCH 45/45] remove debugging comments --- .../java/com/google/cloud/tools/jib/api/JibIntegrationTest.java | 1 - 1 file changed, 1 deletion(-) diff --git a/jib-core/src/integration-test/java/com/google/cloud/tools/jib/api/JibIntegrationTest.java b/jib-core/src/integration-test/java/com/google/cloud/tools/jib/api/JibIntegrationTest.java index b748de6247..bf60f5d025 100644 --- a/jib-core/src/integration-test/java/com/google/cloud/tools/jib/api/JibIntegrationTest.java +++ b/jib-core/src/integration-test/java/com/google/cloud/tools/jib/api/JibIntegrationTest.java @@ -334,7 +334,6 @@ public void testDistroless_ociManifest() Jib.from("gcr.io/distroless/base@" + KNOWN_OCI_INDEX_SHA) .setPlatforms( ImmutableSet.of(new Platform("arm64", "linux"), new Platform("amd64", "linux"))) - // Pushing to registry causes next test to hang. .containerize( Containerizer.to( RegistryImage.named(dockerHost + ":5000/jib-distroless:multi-platform"))