use of com.google.cloud.tools.jib.api.JibContainerBuilder in project docker-maven-plugin by fabric8io.
the class JibBuildService method build.
public void build(String jibImageFormat, ImageConfiguration imageConfig, RegistryService.RegistryConfig registryConfig) throws MojoExecutionException {
try {
log.info("[[B]]JIB[[B]] image build started");
if (imageConfig.getBuildConfiguration().isDockerFileMode()) {
throw new MojoExecutionException("Dockerfile mode is not supported with JIB build strategy");
}
prependRegistry(imageConfig, mojoParameters.getProject().getProperties().getProperty(PUSH_REGISTRY));
BuildDirs buildDirs = new BuildDirs(imageConfig.getName(), mojoParameters);
final Credential pullRegistryCredential = getRegistryCredentials(registryConfig, false, imageConfig, log);
final JibContainerBuilder containerBuilder = containerFromImageConfiguration(jibImageFormat, imageConfig, pullRegistryCredential);
File dockerTarArchive = getAssemblyTarArchive(imageConfig, serviceHub, mojoParameters, log);
for (AssemblyConfiguration assemblyConfiguration : imageConfig.getBuildConfiguration().getAssemblyConfigurations()) {
// TODO: Improve Assembly Manager so that the effective assemblyFileEntries computed can be properly shared
// the call to DockerAssemblyManager.getInstance().createDockerTarArchive should not be necessary,
// files should be added using the AssemblyFileEntry list. DockerAssemblyManager, should provide
// a common way to achieve this so that both the tar builder and any other builder could get a hold of
// archive customizers, file entries, etc.
AssemblyFiles assemblyFiles = serviceHub.getDockerAssemblyManager().getAssemblyFiles(imageConfig.getName(), assemblyConfiguration, mojoParameters, log);
final Map<File, AssemblyFiles.Entry> files = assemblyFiles.getUpdatedEntriesAndRefresh().stream().collect(Collectors.toMap(AssemblyFiles.Entry::getDestFile, Function.identity(), (oldV, newV) -> newV));
JibServiceUtil.copyToContainer(containerBuilder, buildDirs.getOutputDirectory(), buildDirs.getOutputDirectory().getAbsolutePath(), files);
}
JibServiceUtil.buildContainer(containerBuilder, TarImage.at(dockerTarArchive.toPath()).named(imageConfig.getName()), log);
log.info(" %s successfully built", dockerTarArchive.getAbsolutePath());
} catch (Exception ex) {
throw new MojoExecutionException("Error when building JIB image", ex);
}
}
use of com.google.cloud.tools.jib.api.JibContainerBuilder in project docker-maven-plugin by fabric8io.
the class JibServiceUtilTest method testContainerFromImageConfiguration.
@Test
public void testContainerFromImageConfiguration(@Mocked JibContainerBuilder containerBuilder) throws Exception {
// Given
ImageConfiguration imageConfiguration = getSampleImageConfiguration();
// When
JibContainerBuilder jibContainerBuilder = containerFromImageConfiguration(ImageFormat.Docker.name(), imageConfiguration, null);
// Then
// @formatter:off
new Verifications() {
{
jibContainerBuilder.addLabel("foo", "bar");
times = 1;
jibContainerBuilder.setEntrypoint(Arrays.asList("java", "-jar", "foo.jar"));
times = 1;
jibContainerBuilder.setExposedPorts(new HashSet<>(Collections.singletonList(Port.tcp(8080))));
times = 1;
jibContainerBuilder.setUser("root");
times = 1;
jibContainerBuilder.setWorkingDirectory(AbsoluteUnixPath.get("/home/foo"));
times = 1;
jibContainerBuilder.setVolumes(new HashSet<>(Collections.singletonList(AbsoluteUnixPath.get("/mnt/volume1"))));
times = 1;
jibContainerBuilder.setFormat(ImageFormat.Docker);
times = 1;
}
};
// @formatter:on
}
Aggregations