Search in sources :

Example 66 with BuildImageConfiguration

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());
        }
    }
}
Also used : BuildImageConfiguration(io.fabric8.maven.docker.config.BuildImageConfiguration)

Example 67 with BuildImageConfiguration

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);
                    }
                }
            }
        }
    }
}
Also used : ImageName(io.fabric8.maven.docker.util.ImageName) BuildImageConfiguration(io.fabric8.maven.docker.config.BuildImageConfiguration) ImageConfiguration(io.fabric8.maven.docker.config.ImageConfiguration) AuthConfig(io.fabric8.maven.docker.access.AuthConfig) BuildImageConfiguration(io.fabric8.maven.docker.config.BuildImageConfiguration)

Example 68 with BuildImageConfiguration

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();
}
Also used : BuildImageConfiguration(io.fabric8.maven.docker.config.BuildImageConfiguration) ImageConfiguration(io.fabric8.maven.docker.config.ImageConfiguration) RunImageConfiguration(io.fabric8.maven.docker.config.RunImageConfiguration) BuildImageConfiguration(io.fabric8.maven.docker.config.BuildImageConfiguration)

Example 69 with BuildImageConfiguration

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());
    }
}
Also used : BuildImageConfiguration(io.fabric8.maven.docker.config.BuildImageConfiguration) ImageConfiguration(io.fabric8.maven.docker.config.ImageConfiguration) BuildImageConfiguration(io.fabric8.maven.docker.config.BuildImageConfiguration)

Example 70 with BuildImageConfiguration

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);
        }
    }
}
Also used : MojoParameters(io.fabric8.maven.docker.util.MojoParameters) BuildImageConfiguration(io.fabric8.maven.docker.config.BuildImageConfiguration) ImageConfiguration(io.fabric8.maven.docker.config.ImageConfiguration) ArrayList(java.util.ArrayList) File(java.io.File) BuildImageConfiguration(io.fabric8.maven.docker.config.BuildImageConfiguration)

Aggregations

BuildImageConfiguration (io.fabric8.maven.docker.config.BuildImageConfiguration)68 Test (org.junit.Test)40 ImageConfiguration (io.fabric8.maven.docker.config.ImageConfiguration)34 File (java.io.File)19 Verifications (mockit.Verifications)15 RunImageConfiguration (io.fabric8.maven.docker.config.RunImageConfiguration)12 ArrayList (java.util.ArrayList)11 AssemblyConfiguration (io.fabric8.maven.docker.config.AssemblyConfiguration)10 AbstractConfigHandlerTest (io.fabric8.maven.docker.config.handler.AbstractConfigHandlerTest)10 Expectations (mockit.Expectations)9 MojoParameters (io.fabric8.maven.docker.util.MojoParameters)8 Properties (java.util.Properties)7 Before (org.junit.Before)7 VolumeConfig (io.fabric8.maven.core.config.VolumeConfig)6 ArchivedFileSet (org.codehaus.plexus.archiver.ArchivedFileSet)6 Assembly (org.apache.maven.plugins.assembly.model.Assembly)5 Arguments (io.fabric8.maven.docker.config.Arguments)4 CleanupMode (io.fabric8.maven.docker.config.CleanupMode)4 FileSet (org.codehaus.plexus.archiver.FileSet)4 ProcessorConfig (io.fabric8.maven.core.config.ProcessorConfig)3