Skip to content

Commit

Permalink
Adding the from.platforms Jib config parameter to jib-maven-plugin …
Browse files Browse the repository at this point in the history
…and to the jib-gradle-plugin (#2568)

* Adding the plugins tag for Jib-Maven-Plugin

* Adding the plugins tag

* Solved Style Issues

* Added the getPlatforms test

* Style Fixes

* Comment Fixes

* Making inner classes private

* New option to skip pushing images (manifests) if the image (manifest) already exists in the target registry (#2531)

* Adds proposal to control the pushing of tags on existing images in target registry.

* Updates proposal with more detail.

* Work for tags-on-existing-images.md

* Cleanup.

* * Simplified implementation:
  * Removed newly added class ManifestDescriptor, replaced it with already existing ManifestAndDigest.
  * Removed the CheckImageStep and incorporated the check within the PushImageStep. Implementation now follows similar checks, eg, in PushBlopStep.
* Adds unit and integration tests.
* Fixes resulting from testing.

* Code formatting changes.

* Code cleanup, post-review.

* Code cleanup, post-review.

* * Adds a new CheckImageStep and integrates it in the StepsRunner.
* Reverts PushImageStep to the state before the PR started, apart from the manifest existence check.

* Refactor code

* CHANGELOG

* Update comments

* Improve test

Co-authored-by: Chanseok Oh <[email protected]>

* Making the os/platform nullable

* Style Fixes

* Adding getPlatforms() to RawConfiguration

* Adding the  Jib config parameter to jib-gradle-plugin

* Style Fixes

* Making Platforms Parameter Singular

* Style FIxes

* SMALL FIX

* Fix Gradle platforms config

* Rename PlatformConfiguration interface

* Small style changes

Co-authored-by: Karl <[email protected]>
Co-authored-by: Chanseok Oh <[email protected]>
  • Loading branch information
3 people authored Jul 10, 2020
1 parent 00dbfee commit daed808
Show file tree
Hide file tree
Showing 9 changed files with 193 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import javax.inject.Inject;
import org.gradle.api.Action;
import org.gradle.api.model.ObjectFactory;
import org.gradle.api.provider.ListProperty;
import org.gradle.api.tasks.Input;
import org.gradle.api.tasks.Nested;
import org.gradle.api.tasks.Optional;
Expand All @@ -29,13 +30,32 @@
public class BaseImageParameters {

private final AuthParameters auth;

@Nullable private String image;
@Nullable private String credHelper;
private final PlatformParametersSpec platformParametersSpec;
private final ListProperty<PlatformParameters> platforms;

@Inject
public BaseImageParameters(ObjectFactory objectFactory) {
auth = objectFactory.newInstance(AuthParameters.class, "from.auth");
platforms = objectFactory.listProperty(PlatformParameters.class).empty();
platformParametersSpec =
objectFactory.newInstance(PlatformParametersSpec.class, objectFactory, platforms);

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

@Nested
@Optional
public ListProperty<PlatformParameters> getPlatforms() {
return platforms;
}

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

@Input
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -215,4 +215,9 @@ public Path getImageJsonOutputPath() {
public List<? extends ExtensionConfiguration> getPluginExtensions() {
return jibExtension.getPluginExtensions().get();
}

@Override
public List<? extends PlatformConfiguration> getPlatforms() {
return jibExtension.getFrom().getPlatforms().get();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,12 @@
* from {
* image = 'gcr.io/my-gcp-project/my-base-image'
* credHelper = 'gcr'
* platforms {
* platform {
* os = 'linux'
* architecture = 'amd64'
* }
* }
* }
* to {
* image = 'gcr.io/gcp-project/my-app:built-with-jib'
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
/*
* Copyright 2020 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.gradle;

import com.google.cloud.tools.jib.plugins.common.RawConfiguration.PlatformConfiguration;
import java.util.Optional;
import javax.annotation.Nullable;
import org.gradle.api.tasks.Input;
import org.gradle.api.tasks.Internal;

/** Configuration of a platform. */
public class PlatformParameters implements PlatformConfiguration {
@Nullable private String os;
@Nullable private String architecture;

@Input
@Nullable
public String getOs() {
return os;
}

@Internal
@Override
public Optional<String> getOsName() {
return Optional.ofNullable(os);
}

public void setOs(String os) {
this.os = os;
}

@Input
@Nullable
public String getArchitecture() {
return architecture;
}

@Internal
@Override
public Optional<String> getArchitectureName() {
return Optional.ofNullable(architecture);
}

public void setArchitecture(String architecture) {
this.architecture = architecture;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
/*
* Copyright 2020 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.gradle;

import javax.inject.Inject;
import org.gradle.api.Action;
import org.gradle.api.model.ObjectFactory;
import org.gradle.api.provider.ListProperty;

/** Allows to add {@link PlatformParameters} objects to the list property of the same type. */
public class PlatformParametersSpec {

private final ObjectFactory objectFactory;
private final ListProperty<PlatformParameters> platforms;

@Inject
public PlatformParametersSpec(
ObjectFactory objectFactory, ListProperty<PlatformParameters> platforms) {
this.platforms = platforms;
this.objectFactory = objectFactory;
}

/**
* Adds a new platform configuration to the platforms list.
*
* @param action closure representing a platform configuration
*/
public void platform(Action<? super PlatformParameters> action) {
PlatformParameters platform = objectFactory.newInstance(PlatformParameters.class);
action.execute(platform);
platforms.add(platform);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import com.google.cloud.tools.jib.plugins.common.ConfigurationPropertyValidator;
import com.google.cloud.tools.jib.plugins.common.PropertyNames;
import com.google.cloud.tools.jib.plugins.common.RawConfiguration.ExtensionConfiguration;
import com.google.cloud.tools.jib.plugins.common.RawConfiguration.PlatformConfiguration;
import com.google.common.annotations.VisibleForTesting;
import com.google.common.base.Preconditions;
import com.google.common.base.Strings;
Expand Down Expand Up @@ -127,6 +128,22 @@ Optional<String> getMode() {
}
}

/** Configuration for {@code platform} parameter. */
public static class PlatformParameters implements PlatformConfiguration {
@Nullable @Parameter private String os;
@Nullable @Parameter private String architecture;

@Override
public Optional<String> getOsName() {
return Optional.ofNullable(os);
}

@Override
public Optional<String> getArchitectureName() {
return Optional.ofNullable(architecture);
}
}

/** Configuration for {@code from} parameter. */
public static class FromConfiguration {

Expand All @@ -135,6 +152,16 @@ public static class FromConfiguration {
@Nullable @Parameter private String credHelper;

@Parameter private FromAuthConfiguration auth = new FromAuthConfiguration();

@Parameter private List<PlatformParameters> platforms;

/** Constructor for defaults. */
public FromConfiguration() {
PlatformParameters platform = new PlatformParameters();
platform.os = "linux";
platform.architecture = "amd64";
platforms = Collections.singletonList(platform);
}
}

/** Configuration for {@code to} parameter, where image is required. */
Expand Down Expand Up @@ -330,6 +357,15 @@ protected void checkJibVersion() throws MojoExecutionException {
MojoCommon.checkJibVersion(descriptor);
}

/**
* Gets the specified platforms.
*
* @return the specified platforms
*/
List<PlatformParameters> getPlatforms() {
return from.platforms;
}

/**
* Gets the base image reference.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -217,4 +217,9 @@ public Path getImageJsonOutputPath() {
public List<? extends ExtensionConfiguration> getPluginExtensions() {
return jibPluginConfiguration.getPluginExtensions();
}

@Override
public List<? extends PlatformConfiguration> getPlatforms() {
return jibPluginConfiguration.getPlatforms();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,9 @@ public Log getLog() {

@Test
public void testDefaults() {
Assert.assertEquals("linux", testPluginConfiguration.getPlatforms().get(0).getOsName().get());
Assert.assertEquals(
"amd64", testPluginConfiguration.getPlatforms().get(0).getArchitectureName().get());
Assert.assertEquals("", testPluginConfiguration.getAppRoot());
Assert.assertNull(testPluginConfiguration.getWorkingDirectory());
Assert.assertTrue(testPluginConfiguration.getExtraClasspath().isEmpty());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,13 @@ static interface ExtensionConfiguration {
Optional<Object> getExtraConfiguration();
}

static interface PlatformConfiguration {

Optional<String> getOsName();

Optional<String> getArchitectureName();
}

Optional<String> getFromImage();

Optional<String> getToImage();
Expand Down Expand Up @@ -107,4 +114,6 @@ static interface ExtensionConfiguration {
Path getImageJsonOutputPath();

List<? extends ExtensionConfiguration> getPluginExtensions();

List<? extends PlatformConfiguration> getPlatforms();
}

0 comments on commit daed808

Please sign in to comment.