Skip to content

Commit

Permalink
Fix platform configuration in Gradle plugin (#2783)
Browse files Browse the repository at this point in the history
* Fix platform configuration in Gradle plugin
* CHANGELOG
* Reset default platform when given "platforms" action
  • Loading branch information
chanseokoh committed Sep 24, 2020
1 parent 074bbc7 commit 212cc8a
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 9 deletions.
Expand Up @@ -39,8 +39,7 @@ public static class Builder {
private Instant creationTime = Instant.EPOCH;
private ImageFormat format = ImageFormat.Docker;

// note that a LinkedHashSet instead of HashSet has been used so as to preserve the platform
// order
// LinkedHashSet to preserve the order
private Set<Platform> platforms =
new LinkedHashSet<>(Collections.singleton(new Platform("amd64", "linux")));

Expand Down
Expand Up @@ -47,8 +47,7 @@ public static class Builder {
*/
private static final Instant DEFAULT_CREATION_TIME = Instant.EPOCH;

// note that a LinkedHashSet instead of HashSet has been used so as to preserve the platform
// order
// LinkedHashSet to preserve the order
private Set<Platform> platforms =
new LinkedHashSet<>(Collections.singleton(new Platform("amd64", "linux")));
private Instant creationTime = DEFAULT_CREATION_TIME;
Expand Down
1 change: 1 addition & 0 deletions jib-gradle-plugin/CHANGELOG.md
Expand Up @@ -14,6 +14,7 @@ All notable changes to this project will be documented in this file.
### Fixed

- Fixed `NullPointerException` during input validation (in Java 9+) when configuring Jib parameters using certain immutable collections (such as `List.of()`). ([#2702](https://github.com/GoogleContainerTools/jib/issues/2702))
- Fixed an issue that configuring `jib.from.platforms` was always additive to the default `amd64/linux` platform. ([#2783](https://github.com/GoogleContainerTools/jib/issues/2783))

## 2.5.0

Expand Down
Expand Up @@ -38,14 +38,14 @@ public class BaseImageParameters {
@Inject
public BaseImageParameters(ObjectFactory objectFactory) {
auth = objectFactory.newInstance(AuthParameters.class, "from.auth");
platforms = objectFactory.listProperty(PlatformParameters.class).empty();
platforms = objectFactory.listProperty(PlatformParameters.class);
platformParametersSpec =
objectFactory.newInstance(PlatformParametersSpec.class, objectFactory, platforms);

PlatformParameters platform = new PlatformParameters();
platform.setOs("linux");
platform.setArchitecture("amd64");
platforms.add(platform);
PlatformParameters amd64Linux = new PlatformParameters();
amd64Linux.setArchitecture("amd64");
amd64Linux.setOs("linux");
platforms.add(amd64Linux);
}

@Nested
Expand All @@ -55,6 +55,7 @@ public ListProperty<PlatformParameters> getPlatforms() {
}

public void platforms(Action<? super PlatformParametersSpec> action) {
platforms.empty();
action.execute(platformParametersSpec);
}

Expand Down
Expand Up @@ -25,6 +25,7 @@
import java.nio.file.Paths;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import java.util.Properties;
import org.gradle.api.Project;
import org.gradle.testfixtures.ProjectBuilder;
Expand Down Expand Up @@ -56,17 +57,35 @@ public void testFrom() {
Assert.assertNull(testJibExtension.getFrom().getImage());
Assert.assertNull(testJibExtension.getFrom().getCredHelper());

List<PlatformParameters> defaultPlatforms = testJibExtension.getFrom().getPlatforms().get();
Assert.assertEquals(1, defaultPlatforms.size());
Assert.assertEquals("amd64", defaultPlatforms.get(0).getArchitecture());
Assert.assertEquals("linux", defaultPlatforms.get(0).getOs());

testJibExtension.from(
from -> {
from.setImage("some image");
from.setCredHelper("some cred helper");
from.auth(auth -> auth.setUsername("some username"));
from.auth(auth -> auth.setPassword("some password"));
from.platforms(
platformSpec -> {
platformSpec.platform(
platform -> {
platform.setArchitecture("arm");
platform.setOs("windows");
});
});
});
Assert.assertEquals("some image", testJibExtension.getFrom().getImage());
Assert.assertEquals("some cred helper", testJibExtension.getFrom().getCredHelper());
Assert.assertEquals("some username", testJibExtension.getFrom().getAuth().getUsername());
Assert.assertEquals("some password", testJibExtension.getFrom().getAuth().getPassword());

List<PlatformParameters> platforms = testJibExtension.getFrom().getPlatforms().get();
Assert.assertEquals(1, platforms.size());
Assert.assertEquals("arm", platforms.get(0).getArchitecture());
Assert.assertEquals("windows", platforms.get(0).getOs());
}

@Test
Expand Down

0 comments on commit 212cc8a

Please sign in to comment.