use of com.google.cloud.tools.jib.api.buildplan.Platform in project jib by GoogleContainerTools.
the class PluginConfigurationProcessor method getPlatformsSet.
/**
* Parses the list of platforms to a set of {@link Platform}.
*
* @param rawConfiguration raw configuration data
* @return the set of parsed platforms
* @throws InvalidPlatformException if there exists a {@link PlatformConfiguration} in the
* specified platforms list that is missing required fields or has invalid values
*/
@VisibleForTesting
static Set<Platform> getPlatformsSet(RawConfiguration rawConfiguration) throws InvalidPlatformException {
Set<Platform> platforms = new LinkedHashSet<>();
for (PlatformConfiguration platformConfiguration : rawConfiguration.getPlatforms()) {
Optional<String> architecture = platformConfiguration.getArchitectureName();
Optional<String> os = platformConfiguration.getOsName();
String platformToString = "architecture=" + architecture.orElse("<missing>") + ", os=" + os.orElse("<missing>");
if (!architecture.isPresent()) {
throw new InvalidPlatformException("platform configuration is missing an architecture value", platformToString);
}
if (!os.isPresent()) {
throw new InvalidPlatformException("platform configuration is missing an OS value", platformToString);
}
platforms.add(new Platform(architecture.get(), os.get()));
}
return platforms;
}
use of com.google.cloud.tools.jib.api.buildplan.Platform in project jib by google.
the class PlatformChecker method checkManifestPlatform.
/**
* Assuming the base image is not a manifest list, checks and warns misconfigured platforms.
*
* @param buildContext the {@link BuildContext}
* @param containerConfig container configuration JSON of the base image
*/
static void checkManifestPlatform(BuildContext buildContext, ContainerConfigurationTemplate containerConfig) {
EventHandlers eventHandlers = buildContext.getEventHandlers();
Optional<Path> path = buildContext.getBaseImageConfiguration().getTarPath();
String baseImageName = path.map(Path::toString).orElse(buildContext.getBaseImageConfiguration().getImage().toString());
Set<Platform> platforms = buildContext.getContainerConfiguration().getPlatforms();
Verify.verify(!platforms.isEmpty());
if (platforms.size() != 1) {
eventHandlers.dispatch(LogEvent.warn("platforms configured, but '" + baseImageName + "' is not a manifest list"));
} else {
Platform platform = platforms.iterator().next();
if (!platform.getArchitecture().equals(containerConfig.getArchitecture()) || !platform.getOs().equals(containerConfig.getOs())) {
// configure it. Skip reporting to suppress false alarm.
if (!(platform.getArchitecture().equals("amd64") && platform.getOs().equals("linux"))) {
String warning = "the configured platform (%s/%s) doesn't match the platform (%s/%s) of the base " + "image (%s)";
eventHandlers.dispatch(LogEvent.warn(String.format(warning, platform.getArchitecture(), platform.getOs(), containerConfig.getArchitecture(), containerConfig.getOs(), baseImageName)));
}
}
}
}
use of com.google.cloud.tools.jib.api.buildplan.Platform in project jib by google.
the class JibIntegrationTest method testScratch_defaultPlatform.
@Test
public void testScratch_defaultPlatform() throws IOException, InterruptedException, ExecutionException, RegistryException, CacheDirectoryCreationException, InvalidImageReferenceException {
Jib.fromScratch().containerize(Containerizer.to(RegistryImage.named("localhost:5000/jib-scratch:default-platform")).setAllowInsecureRegistries(true));
V22ManifestTemplate manifestTemplate = registryClient.pullManifest("default-platform", V22ManifestTemplate.class).getManifest();
String containerConfig = Blobs.writeToString(registryClient.pullBlob(manifestTemplate.getContainerConfiguration().getDigest(), ignored -> {
}, ignored -> {
}));
Assert.assertTrue(manifestTemplate.getLayers().isEmpty());
Assert.assertTrue(containerConfig.contains("\"architecture\":\"amd64\""));
Assert.assertTrue(containerConfig.contains("\"os\":\"linux\""));
}
use of com.google.cloud.tools.jib.api.buildplan.Platform in project jib by google.
the class JibIntegrationTest method testScratch_singlePlatform.
@Test
public void testScratch_singlePlatform() throws IOException, InterruptedException, ExecutionException, RegistryException, CacheDirectoryCreationException, InvalidImageReferenceException {
Jib.fromScratch().setPlatforms(ImmutableSet.of(new Platform("arm64", "windows"))).containerize(Containerizer.to(RegistryImage.named("localhost:5000/jib-scratch:single-platform")).setAllowInsecureRegistries(true));
V22ManifestTemplate manifestTemplate = registryClient.pullManifest("single-platform", V22ManifestTemplate.class).getManifest();
String containerConfig = Blobs.writeToString(registryClient.pullBlob(manifestTemplate.getContainerConfiguration().getDigest(), ignored -> {
}, ignored -> {
}));
Assert.assertTrue(manifestTemplate.getLayers().isEmpty());
Assert.assertTrue(containerConfig.contains("\"architecture\":\"arm64\""));
Assert.assertTrue(containerConfig.contains("\"os\":\"windows\""));
}
use of com.google.cloud.tools.jib.api.buildplan.Platform in project jib by google.
the class JibIntegrationTest method testScratch_multiPlatform.
@Test
public void testScratch_multiPlatform() throws IOException, InterruptedException, ExecutionException, RegistryException, CacheDirectoryCreationException, InvalidImageReferenceException {
Jib.fromScratch().setPlatforms(ImmutableSet.of(new Platform("arm64", "windows"), new Platform("amd32", "windows"))).containerize(Containerizer.to(RegistryImage.named("localhost:5000/jib-scratch:multi-platform")).setAllowInsecureRegistries(true));
V22ManifestListTemplate manifestList = (V22ManifestListTemplate) registryClient.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("windows", platform1.getOs());
Assert.assertEquals("amd32", platform2.getArchitecture());
Assert.assertEquals("windows", platform2.getOs());
}
Aggregations