Skip to content

Commit

Permalink
Merge branch 'master' into asm-9.7
Browse files Browse the repository at this point in the history
  • Loading branch information
markusheiden authored Jun 5, 2024
2 parents b65d21b + b06b001 commit 507ff6f
Show file tree
Hide file tree
Showing 33 changed files with 415 additions and 37 deletions.
2 changes: 1 addition & 1 deletion config/checkstyle/copyright-java.header
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
^/\*$
^ \* Copyright 20(17|18|19|20|21|22|23) Google LLC\.$
^ \* Copyright 20(17|18|19|20|21|22|23|24) 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$
Expand Down
2 changes: 1 addition & 1 deletion examples/dropwizard/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
<dropwizard-template-config.version>1.5.0</dropwizard-template-config.version>

<jib.container.appRoot>/app</jib.container.appRoot>
<jib-maven-plugin.version>3.4.2</jib-maven-plugin.version>
<jib-maven-plugin.version>3.4.3</jib-maven-plugin.version>
</properties>

<dependencyManagement>
Expand Down
2 changes: 1 addition & 1 deletion examples/helloworld/build.gradle
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
plugins {
id 'java'
id 'com.google.cloud.tools.jib' version '3.4.2'
id 'com.google.cloud.tools.jib' version '3.4.3'
}

sourceCompatibility = 1.8
Expand Down
2 changes: 1 addition & 1 deletion examples/helloworld/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<jib-maven-plugin.version>3.4.2</jib-maven-plugin.version>
<jib-maven-plugin.version>3.4.3</jib-maven-plugin.version>
<maven-compiler-plugin.version>3.8.0</maven-compiler-plugin.version>
</properties>

Expand Down
2 changes: 1 addition & 1 deletion examples/java-agent/build.gradle
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
plugins {
id 'java'
id 'com.google.cloud.tools.jib' version '3.4.2'
id 'com.google.cloud.tools.jib' version '3.4.3'
id 'de.undercouch.download' version '4.0.0'
id 'com.gorylenko.gradle-git-properties' version '2.2.0'
}
Expand Down
2 changes: 1 addition & 1 deletion examples/java-agent/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<jib-maven-plugin.version>3.4.2</jib-maven-plugin.version>
<jib-maven-plugin.version>3.4.3</jib-maven-plugin.version>
<maven-compiler-plugin.version>3.8.0</maven-compiler-plugin.version>
<download-maven-plugin.version>1.4.2</download-maven-plugin.version>
<git-commit-id-plugin.version>3.0.1</git-commit-id-plugin.version>
Expand Down
2 changes: 1 addition & 1 deletion examples/ktor/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
plugins {
application
kotlin("jvm") version "1.3.10"
id("com.google.cloud.tools.jib") version "3.4.2"
id("com.google.cloud.tools.jib") version "3.4.3"
}

group = "example"
Expand Down
2 changes: 1 addition & 1 deletion examples/micronaut/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ plugins {
id "groovy"
id "com.github.johnrengelman.shadow" version "5.2.0"
id "application"
id 'com.google.cloud.tools.jib' version '3.4.2'
id 'com.google.cloud.tools.jib' version '3.4.3'
}

version "0.1"
Expand Down
2 changes: 1 addition & 1 deletion examples/multi-module/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@
plugins {
id 'org.springframework.boot' version '2.0.3.RELEASE' apply false
id 'io.spring.dependency-management' version '1.0.6.RELEASE' apply false
id 'com.google.cloud.tools.jib' version '3.4.2' apply false
id 'com.google.cloud.tools.jib' version '3.4.3' apply false
}
2 changes: 1 addition & 1 deletion examples/multi-module/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
<plugin>
<groupId>com.google.cloud.tools</groupId>
<artifactId>jib-maven-plugin</artifactId>
<version>3.4.2</version>
<version>3.4.3</version>
</plugin>
</plugins>
</pluginManagement>
Expand Down
2 changes: 1 addition & 1 deletion examples/spring-boot/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ plugins {
id 'idea'
id 'org.springframework.boot' version '2.1.6.RELEASE'
id 'io.spring.dependency-management' version '1.0.6.RELEASE'
id 'com.google.cloud.tools.jib' version '3.4.2'
id 'com.google.cloud.tools.jib' version '3.4.3'
}

repositories {
Expand Down
2 changes: 1 addition & 1 deletion examples/spring-boot/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
<plugin>
<groupId>com.google.cloud.tools</groupId>
<artifactId>jib-maven-plugin</artifactId>
<version>3.4.2</version>
<version>3.4.3</version>
</plugin>
</plugins>
</build>
Expand Down
2 changes: 1 addition & 1 deletion examples/vertx/build.gradle
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
plugins {
id 'io.vertx.vertx-plugin' version '0.1.0'
id 'com.google.cloud.tools.jib' version '3.4.2'
id 'com.google.cloud.tools.jib' version '3.4.3'
}

repositories {
Expand Down
6 changes: 6 additions & 0 deletions jib-core/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,12 @@ All notable changes to this project will be documented in this file.

### Fixed

## 0.27.1

### Fixed
- fix: When building to the local docker daemon with multiple platforms configured, Jib will now automatically select the image that matches the OS type and architecture of the local Docker environment. ([#4249](https://github.com/GoogleContainerTools/jib/pull/4249))


## 0.27.0

### Changed
Expand Down
4 changes: 2 additions & 2 deletions jib-core/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,15 @@ Add Jib Core as a dependency using Maven:
<dependency>
<groupId>com.google.cloud.tools</groupId>
<artifactId>jib-core</artifactId>
<version>0.27.0</version>
<version>0.27.1</version>
</dependency>
```

Add Jib Core as a dependency using Gradle:

```groovy
dependencies {
compile 'com.google.cloud.tools:jib-core:0.27.0'
compile 'com.google.cloud.tools:jib-core:0.27.1'
}
```

Expand Down
2 changes: 1 addition & 1 deletion jib-core/gradle.properties
Original file line number Diff line number Diff line change
@@ -1 +1 @@
version = 0.27.1-SNAPSHOT
version = 0.27.2-SNAPSHOT
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@

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;
import com.google.cloud.tools.jib.blob.Blobs;
Expand Down Expand Up @@ -304,6 +307,65 @@ public void testScratch_multiPlatform()
Assert.assertEquals("windows", platform2.getOs());
}

@Test
public void testBasic_jibImageToDockerDaemon()
throws IOException, InterruptedException, InvalidImageReferenceException, ExecutionException,
RegistryException, CacheDirectoryCreationException {
Jib.from(DockerDaemonImage.named(dockerHost + ":5000/busybox"))
.setEntrypoint("echo", "Hello World")
.containerize(
Containerizer.to(DockerDaemonImage.named(dockerHost + ":5000/docker-to-docker")));

String output =
new Command("docker", "run", "--rm", dockerHost + ":5000/docker-to-docker").run();
Assert.assertEquals("Hello World\n", output);
}

@Test
public void testBasicMultiPlatform_toDockerDaemon()
throws IOException, InterruptedException, ExecutionException, RegistryException,
CacheDirectoryCreationException, InvalidImageReferenceException {
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(dockerHost + ":5000/docker-daemon-multi-platform"))
.setAllowInsecureRegistries(true));

String output =
new Command("docker", "run", "--rm", dockerHost + ":5000/docker-daemon-multi-platform")
.run();
Assert.assertEquals("Hello World\n", output);
}

@Test
public void testBasicMultiPlatform_toDockerDaemon_noMatchingImage() {
ExecutionException exception =
assertThrows(
ExecutionException.class,
() ->
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)));
assertThat(exception)
.hasCauseThat()
.hasMessageThat()
.startsWith("The configured platforms don't match the Docker Engine's OS and architecture");
}

@Test
public void testDistroless_ociManifest()
throws IOException, InterruptedException, ExecutionException, RegistryException,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,4 +69,15 @@ void save(ImageReference imageReference, Path outputPath, Consumer<Long> written
* @throws InterruptedException if the {@code docker inspect} process was interrupted
*/
ImageDetails inspect(ImageReference imageReference) throws IOException, InterruptedException;

/**
* Gets docker info details of local docker installation.
*
* @return docker info details.
* @throws IOException if an I/O exception occurs or {@code docker info} failed
* @throws InterruptedException if the {@code docker info} process was interrupted
*/
default DockerInfoDetails info() throws IOException, InterruptedException {
return new DockerInfoDetails();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
/*
* 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 com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.google.cloud.tools.jib.json.JsonTemplate;

/** Contains docker info details outputted by {@code docker info}. */
@JsonIgnoreProperties(ignoreUnknown = true)
public class DockerInfoDetails implements JsonTemplate {

@JsonProperty("OSType")
private String osType = "";

@JsonProperty("Architecture")
private String architecture = "";

public String getOsType() {
return osType;
}

public String getArchitecture() {
return architecture;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@

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.blob.BlobDescriptor;
import com.google.cloud.tools.jib.builder.ProgressEventDispatcher;
import com.google.cloud.tools.jib.builder.steps.LocalBaseImageSteps.LocalImage;
Expand Down Expand Up @@ -52,6 +53,7 @@
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;

Expand All @@ -64,6 +66,8 @@
*/
public class StepsRunner {

private static final Logger LOGGER = Logger.getLogger(StepsRunner.class.getName());

/** Holds the individual step results. */
private static class StepResults {

Expand Down Expand Up @@ -413,7 +417,8 @@ private void buildAndCacheApplicationLayers(
BuildAndCacheApplicationLayerStep.makeList(buildContext, progressDispatcherFactory));
}

private void buildImages(ProgressEventDispatcher.Factory progressDispatcherFactory) {
@VisibleForTesting
void buildImages(ProgressEventDispatcher.Factory progressDispatcherFactory) {
results.baseImagesAndBuiltImages =
executorService.submit(
() -> {
Expand Down Expand Up @@ -616,13 +621,17 @@ private void loadDocker(
results.buildResult =
executorService.submit(
() -> {
Verify.verify(
results.baseImagesAndBuiltImages.get().size() == 1,
"multi-platform image building not supported when pushing to Docker engine");
Image builtImage =
results.baseImagesAndBuiltImages.get().values().iterator().next().get();
DockerInfoDetails dockerInfoDetails = dockerClient.info();
String osType = dockerInfoDetails.getOsType();
String architecture = normalizeArchitecture(dockerInfoDetails.getArchitecture());
Optional<Image> 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));
return new LoadDockerStep(
buildContext, progressDispatcherFactory, dockerClient, builtImage)
buildContext, progressDispatcherFactory, dockerClient, builtImage.get())
.call();
});
}
Expand All @@ -647,4 +656,34 @@ private void writeTarFile(
private <E> List<Future<E>> scheduleCallables(ImmutableList<? extends Callable<E>> callables) {
return callables.stream().map(executorService::submit).collect(Collectors.toList());
}

@VisibleForTesting
String normalizeArchitecture(String architecture) {
// Create mapping based on https://docs.docker.com/engine/install/#supported-platforms
if (architecture.equals("x86_64")) {
return "amd64";
} else if (architecture.equals("aarch64")) {
return "arm64";
}
return architecture;
}

@VisibleForTesting
Optional<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)",
osType, architecture));
}
for (Map.Entry<Image, Future<Image>> imageEntry :
results.baseImagesAndBuiltImages.get().entrySet()) {
Image image = imageEntry.getValue().get();
if (image.getArchitecture().equals(architecture) && image.getOs().equals(osType)) {
return Optional.of(image);
}
}
return Optional.empty();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import com.fasterxml.jackson.annotation.JsonProperty;
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.ImageDetails;
import com.google.cloud.tools.jib.api.ImageReference;
import com.google.cloud.tools.jib.http.NotifyingOutputStream;
Expand Down Expand Up @@ -184,6 +185,17 @@ public boolean supported(Map<String, String> parameters) {
return true;
}

@Override
public DockerInfoDetails info() throws IOException, InterruptedException {
// Runs 'docker info'.
Process infoProcess = docker("info", "-f", "{{json .}}");
if (infoProcess.waitFor() != 0) {
throw new IOException(
"'docker info' command failed with error: " + getStderrOutput(infoProcess));
}
return JsonTemplateMapper.readJson(infoProcess.getInputStream(), DockerInfoDetails.class);
}

@Override
public String load(ImageTarball imageTarball, Consumer<Long> writtenByteCountListener)
throws InterruptedException, IOException {
Expand Down
Loading

0 comments on commit 507ff6f

Please sign in to comment.