Skip to content

Expose jib.from.platforms as property. #3526

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
import java.util.Optional;
import java.util.Set;
import java.util.stream.Collectors;
import java.util.stream.Stream;
import javax.annotation.Nullable;
import javax.inject.Inject;
import org.apache.maven.execution.MavenSession;
Expand Down Expand Up @@ -146,6 +147,16 @@ public Optional<String> getOsName() {
public Optional<String> getArchitectureName() {
return Optional.ofNullable(architecture);
}

private static PlatformParameters ofString(String osArchitecture) {
if (osArchitecture == null || !osArchitecture.matches("[^/]+/[^/]+")) {
throw new IllegalArgumentException("osArchitecture must be of form os/architecture");
}
PlatformParameters platformParameters = new PlatformParameters();
platformParameters.os = osArchitecture.split("/")[0].trim();
platformParameters.architecture = osArchitecture.split("/")[1].trim();
return platformParameters;
}
}

/** Configuration for {@code from} parameter. */
Expand All @@ -158,10 +169,7 @@ public static class FromConfiguration {

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

Expand Down Expand Up @@ -354,6 +362,12 @@ protected void checkJibVersion() throws MojoExecutionException {
* @return the specified platforms
*/
List<PlatformParameters> getPlatforms() {
String property = getProperty(PropertyNames.FROM_PLATFORMS);
if (property != null) {
return Stream.of(property.split(","))
.map(PlatformParameters::ofString)
.collect(Collectors.toList());
}
return from.platforms;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ public class PropertyNames {
public static final String FROM_CRED_HELPER = "jib.from.credHelper";
public static final String FROM_AUTH_USERNAME = "jib.from.auth.username";
public static final String FROM_AUTH_PASSWORD = "jib.from.auth.password";
public static final String FROM_PLATFORMS = "jib.from.platforms";
public static final String TO_IMAGE = "jib.to.image";
public static final String TO_IMAGE_ALTERNATE = "image";
public static final String TO_TAGS = "jib.to.tags";
Expand Down