use of io.fabric8.maven.docker.config.BuildImageConfiguration in project docker-maven-plugin by fabric8io.
the class DockerAssemblyManager method createDockerFileBuilder.
// visible for testing
@SuppressWarnings("deprecation")
DockerFileBuilder createDockerFileBuilder(BuildImageConfiguration buildConfig, List<AssemblyConfiguration> assemblyConfigs) {
DockerFileBuilder builder = new DockerFileBuilder().env(buildConfig.getEnv()).labels(buildConfig.getLabels()).expose(buildConfig.getPorts()).shell(buildConfig.getShell()).run(buildConfig.getRunCmds()).volumes(buildConfig.getVolumes()).user(buildConfig.getUser());
if (buildConfig.getMaintainer() != null) {
builder.maintainer(buildConfig.getMaintainer());
}
if (buildConfig.getWorkdir() != null) {
builder.workdir(buildConfig.getWorkdir());
}
if (assemblyConfigs != null && !assemblyConfigs.isEmpty() && assemblyConfigs.stream().anyMatch(Objects::nonNull)) {
for (AssemblyConfiguration assemblyConfig : assemblyConfigs) {
if (assemblyConfig != null) {
builder.add(assemblyConfig.getName(), "", assemblyConfig.getTargetDir(), assemblyConfig.getUser(), assemblyConfig.exportTargetDir()).basedir(assemblyConfig.getTargetDir()).assemblyUser(assemblyConfig.getUser()).exportTargetDir(assemblyConfig.exportTargetDir());
}
}
} else {
builder.exportTargetDir(false);
}
builder.baseImage(buildConfig.getFrom());
if (buildConfig.getHealthCheck() != null) {
builder.healthCheck(buildConfig.getHealthCheck());
}
if (buildConfig.getCmd() != null) {
builder.cmd(buildConfig.getCmd());
} else if (buildConfig.getCommand() != null) {
Arguments args = Arguments.Builder.get().withShell(buildConfig.getCommand()).build();
builder.cmd(args);
}
if (buildConfig.getEntryPoint() != null) {
builder.entryPoint(buildConfig.getEntryPoint());
}
if (buildConfig.optimise()) {
builder.optimise();
}
return builder;
}
use of io.fabric8.maven.docker.config.BuildImageConfiguration in project docker-maven-plugin by fabric8io.
the class JibServiceUtilTest method getSampleImageConfiguration.
private ImageConfiguration getSampleImageConfiguration() {
Assembly assembly = new Assembly();
FileItem fileItem = new FileItem();
fileItem.setSource("${project.basedir}/foo");
fileItem.setOutputDirectory("/deployments");
assembly.addFile(fileItem);
BuildImageConfiguration bc = new BuildImageConfiguration.Builder().from("quay.io/test/testimage:testtag").assembly(new AssemblyConfiguration.Builder().assemblyDef(assembly).build()).entryPoint(new Arguments.Builder().withParam("java").withParam("-jar").withParam("foo.jar").build()).labels(Collections.singletonMap("foo", "bar")).user("root").workdir("/home/foo").ports(Collections.singletonList("8080")).volumes(Collections.singletonList("/mnt/volume1")).build();
return new ImageConfiguration.Builder().name("test/test-project").buildConfig(bc).build();
}
use of io.fabric8.maven.docker.config.BuildImageConfiguration in project docker-maven-plugin by fabric8io.
the class JibServiceUtil method jibPush.
/**
* Push Image to registry using JIB
*
* @param imageConfiguration ImageConfiguration
* @param pushCredentials push credentials
* @param tarArchive tar archive built during build goal
* @param log Logger
*/
public static void jibPush(ImageConfiguration imageConfiguration, Credential pushCredentials, File tarArchive, Logger log) {
BuildImageConfiguration buildImageConfiguration = imageConfiguration.getBuildConfiguration();
String imageName = getFullImageName(imageConfiguration, null);
try {
for (String tag : getAllImageTags(buildImageConfiguration.getTags(), imageName)) {
String imageNameWithTag = getFullImageName(imageConfiguration, tag);
log.info("Pushing image: %s", imageNameWithTag);
pushImage(TarImage.at(tarArchive.toPath()), imageNameWithTag, pushCredentials, log);
}
} catch (IllegalStateException e) {
log.error("Exception occurred while pushing the image: %s", imageConfiguration.getName());
throw new IllegalStateException(e.getMessage(), e);
} catch (InterruptedException e) {
log.error("Thread interrupted", e);
Thread.currentThread().interrupt();
}
}
use of io.fabric8.maven.docker.config.BuildImageConfiguration in project docker-maven-plugin by fabric8io.
the class BuildService method autoPullBaseImage.
private void autoPullBaseImage(ImageConfiguration imageConfig, ImagePullManager imagePullManager, BuildContext buildContext) throws DockerAccessException, MojoExecutionException {
BuildImageConfiguration buildConfig = imageConfig.getBuildConfiguration();
CleanupMode cleanupMode = buildConfig.cleanupMode();
if (buildConfig.getDockerArchive() != null) {
// No auto pull needed in archive mode
return;
}
List<String> fromImages;
if (buildConfig.isDockerFileMode()) {
fromImages = extractBaseFromDockerfile(buildConfig, buildContext);
} else {
fromImages = new LinkedList<>();
String baseImage = extractBaseFromConfiguration(buildConfig);
if (baseImage != null) {
fromImages.add(extractBaseFromConfiguration(buildConfig));
}
}
for (String fromImage : fromImages) {
if (fromImage != null && !DockerAssemblyManager.SCRATCH_IMAGE.equals(fromImage)) {
String oldImageId = null;
if (cleanupMode.isRemove()) {
oldImageId = queryService.getImageId(fromImage);
}
registryService.pullImageWithPolicy(fromImage, imagePullManager, buildContext.getRegistryConfig(), buildConfig);
String newImageId = queryService.getImageId(fromImage);
removeDanglingImage(fromImage, oldImageId, newImageId, cleanupMode, false);
}
}
}
use of io.fabric8.maven.docker.config.BuildImageConfiguration in project docker-maven-plugin by fabric8io.
the class BuildService method autoPullCacheFromImage.
private void autoPullCacheFromImage(ImageConfiguration imageConfig, ImagePullManager imagePullManager, BuildContext buildContext) throws DockerAccessException, MojoExecutionException {
if (imageConfig.getBuildConfiguration().getCacheFrom() == null) {
return;
}
BuildImageConfiguration buildConfig = imageConfig.getBuildConfiguration();
CleanupMode cleanupMode = buildConfig.cleanupMode();
for (String cacheFromImage : buildConfig.getCacheFrom()) {
String oldImageId = null;
if (cleanupMode.isRemove()) {
oldImageId = queryService.getImageId(cacheFromImage);
}
try {
registryService.pullImageWithPolicy(cacheFromImage, imagePullManager, buildContext.getRegistryConfig(), buildConfig);
} catch (DockerAccessException e) {
log.warn("Could not pull cacheFrom image: '%s'. Reason: %s", cacheFromImage, e.getMessage());
}
String newImageId = queryService.getImageId(cacheFromImage);
removeDanglingImage(cacheFromImage, oldImageId, newImageId, cleanupMode, false);
}
}
Aggregations