use of io.fabric8.maven.docker.config.BuildImageConfiguration in project docker-maven-plugin by fabric8io.
the class BuildService method tagImage.
public void tagImage(ImageConfiguration imageConfig) throws DockerAccessException {
List<String> tags = imageConfig.getBuildConfiguration().getTags();
if (!tags.isEmpty()) {
String imageName = imageConfig.getName();
log.info("%s: Tag with %s", imageConfig.getDescription(), EnvUtil.stringJoin(tags, ","));
BuildImageConfiguration buildConfig = imageConfig.getBuildConfiguration();
for (String tag : tags) {
tagImage(imageName, tag, null, buildConfig.cleanupMode());
}
}
}
use of io.fabric8.maven.docker.config.BuildImageConfiguration in project docker-maven-plugin by fabric8io.
the class RegistryService method pushImages.
/**
* Push a set of images to a registry
*
* @param imageConfigs images to push (but only if they have a build configuration)
* @param retries how often to retry
* @param registryConfig a global registry configuration
* @param skipTag flag to skip pushing tagged images
* @throws DockerAccessException
* @throws MojoExecutionException
*/
public void pushImages(Collection<ImageConfiguration> imageConfigs, int retries, RegistryConfig registryConfig, boolean skipTag) throws DockerAccessException, MojoExecutionException {
for (ImageConfiguration imageConfig : imageConfigs) {
BuildImageConfiguration buildConfig = imageConfig.getBuildConfiguration();
String name = imageConfig.getName();
if (buildConfig != null) {
if (buildConfig.skipPush()) {
log.info("%s : Skipped pushing", imageConfig.getDescription());
continue;
}
String configuredRegistry = EnvUtil.firstRegistryOf(new ImageName(imageConfig.getName()).getRegistry(), imageConfig.getRegistry(), registryConfig.getRegistry());
AuthConfig authConfig = createAuthConfig(true, new ImageName(name).getUser(), configuredRegistry, registryConfig);
long start = System.currentTimeMillis();
docker.pushImage(name, authConfig, configuredRegistry, retries);
log.info("Pushed %s in %s", name, EnvUtil.formatDurationTill(start));
if (!skipTag) {
for (String tag : imageConfig.getBuildConfiguration().getTags()) {
if (tag != null) {
docker.pushImage(new ImageName(name, tag).getFullName(), authConfig, configuredRegistry, retries);
}
}
}
}
}
}
use of io.fabric8.maven.docker.config.BuildImageConfiguration in project docker-maven-plugin by fabric8io.
the class AbstractDockerMojo method createSimpleDockerfileConfig.
private ImageConfiguration createSimpleDockerfileConfig(File dockerFile) {
// No configured name, so create one from maven GAV
String name = EnvUtil.getPropertiesWithSystemOverrides(project).getProperty("docker.name");
if (name == null) {
// Default name group/artifact:version (or 'latest' if SNAPSHOT)
name = "%g/%a:%l";
}
BuildImageConfiguration buildConfig = new BuildImageConfiguration.Builder().dockerFile(dockerFile.getPath()).build();
return new ImageConfiguration.Builder().name(name).buildConfig(buildConfig).build();
}
use of io.fabric8.maven.docker.config.BuildImageConfiguration in project docker-maven-plugin by fabric8io.
the class TagMojo method executeInternal.
@Override
public void executeInternal(ServiceHub hub) throws DockerAccessException, MojoExecutionException {
if (skipTag) {
return;
}
List<ImageConfiguration> imageConfigs = getResolvedImages();
for (ImageConfiguration imageConfig : imageConfigs) {
BuildImageConfiguration buildConfig = imageConfig.getBuildConfiguration();
hub.getBuildService().tagImage(imageConfig.getName(), tagName, repo, buildConfig.cleanupMode());
}
}
use of io.fabric8.maven.docker.config.BuildImageConfiguration in project docker-maven-plugin by fabric8io.
the class SourceMojo method executeInternal.
@Override
protected void executeInternal(ServiceHub hub) throws DockerAccessException, MojoExecutionException {
MojoParameters params = createMojoParameters();
List<ImageConfiguration> imageConfigs = new ArrayList<>();
for (ImageConfiguration imageConfig : getResolvedImages()) {
BuildImageConfiguration buildConfig = imageConfig.getBuildConfiguration();
if (buildConfig != null) {
if (buildConfig.skip()) {
log.info("%s: Skipped creating source", imageConfig.getDescription());
} else {
imageConfigs.add(imageConfig);
}
}
}
if (sourceMode == BuildImageSelectMode.first && imageConfigs.size() > 0) {
ImageConfiguration imageConfig = imageConfigs.get(0);
File dockerTar = hub.getArchiveService().createDockerBuildArchive(imageConfig, params);
projectHelper.attachArtifact(project, getArchiveType(imageConfig), getClassifier(null), dockerTar);
} else {
for (ImageConfiguration imageConfig : imageConfigs) {
File dockerTar = hub.getArchiveService().createDockerBuildArchive(imageConfig, params);
String alias = imageConfig.getAlias();
if (alias == null) {
throw new IllegalArgumentException("Image " + imageConfig.getDescription() + " must have an 'alias' configured to be " + "used as a classifier for attaching a docker build tar as source to the maven build");
}
projectHelper.attachArtifact(project, getArchiveType(imageConfig), getClassifier(alias), dockerTar);
}
}
}
Aggregations