use of io.fabric8.maven.docker.config.CleanupMode in project docker-maven-plugin by fabric8io.
the class BuildService method tagImage.
public void tagImage(String imageName, String tag, String repo, CleanupMode cleanupMode) throws DockerAccessException {
if (tag != null) {
String fullImageName = new ImageName(imageName, tag).getNameWithOptionalRepository(repo);
String oldImageId = null;
if (cleanupMode.isRemove()) {
oldImageId = queryService.getImageId(fullImageName);
}
docker.tag(imageName, fullImageName, true);
log.info("Tagging image %s successful!", fullImageName);
String newImageId = queryService.getImageId(fullImageName);
removeDanglingImage(fullImageName, oldImageId, newImageId, cleanupMode, false);
}
}
use of io.fabric8.maven.docker.config.CleanupMode 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.CleanupMode 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