Search in sources :

Example 1 with ImageNameFormatter

use of io.fabric8.maven.docker.util.ImageNameFormatter in project fabric8-maven-plugin by fabric8io.

the class ResourceMojo method getResolvedImages.

private List<ImageConfiguration> getResolvedImages(List<ImageConfiguration> images, final Logger log) throws MojoExecutionException {
    List<ImageConfiguration> ret;
    ret = ConfigHelper.resolveImages(log, images, new ConfigHelper.Resolver() {

        @Override
        public List<ImageConfiguration> resolve(ImageConfiguration image) {
            return imageConfigResolver.resolve(image, project, session);
        }
    }, // no filter on image name yet (TODO: Maybe add this, too ?)
    null, new ConfigHelper.Customizer() {

        @Override
        public List<ImageConfiguration> customizeConfig(List<ImageConfiguration> configs) {
            try {
                GeneratorContext ctx = new GeneratorContext.Builder().config(extractGeneratorConfig()).project(project).session(session).goalFinder(goalFinder).goalName("fabric8:resource").logger(log).mode(mode).strategy(buildStrategy).useProjectClasspath(useProjectClasspath).build();
                return GeneratorManager.generate(configs, ctx, true);
            } catch (Exception e) {
                throw new IllegalArgumentException("Cannot extract generator: " + e, e);
            }
        }
    });
    Date now = getBuildReferenceDate();
    storeReferenceDateInPluginContext(now);
    String minimalApiVersion = ConfigHelper.initAndValidate(ret, null, /* no minimal api version */
    new ImageNameFormatter(project, now), log);
    return ret;
}
Also used : ImageConfigResolver(io.fabric8.maven.docker.config.handler.ImageConfigResolver) ImageConfiguration(io.fabric8.maven.docker.config.ImageConfiguration) ImageNameFormatter(io.fabric8.maven.docker.util.ImageNameFormatter) List(java.util.List) ArrayList(java.util.ArrayList) GeneratorContext(io.fabric8.maven.generator.api.GeneratorContext) MavenFilteringException(org.apache.maven.shared.filtering.MavenFilteringException) Fabric8ServiceException(io.fabric8.maven.core.service.Fabric8ServiceException) IOException(java.io.IOException) MojoExecutionException(org.apache.maven.plugin.MojoExecutionException) MojoFailureException(org.apache.maven.plugin.MojoFailureException) ConstraintViolationException(javax.validation.ConstraintViolationException) Date(java.util.Date)

Example 2 with ImageNameFormatter

use of io.fabric8.maven.docker.util.ImageNameFormatter in project fabric8-maven-plugin by fabric8io.

the class DockerImageWatcher method buildImage.

protected void buildImage(ImageConfiguration imageConfig) throws DockerAccessException, MojoExecutionException {
    String imageName = imageConfig.getName();
    // lets regenerate the label
    try {
        String imagePrefix = getImagePrefix(imageName);
        imageName = imagePrefix + "%t";
        ImageNameFormatter formatter = new ImageNameFormatter(getContext().getProject(), new Date());
        imageName = formatter.format(imageName);
        imageConfig.setName(imageName);
        log.info("New image name: " + imageConfig.getName());
    } catch (Exception e) {
        log.error("Caught: " + e, e);
    }
}
Also used : ImageNameFormatter(io.fabric8.maven.docker.util.ImageNameFormatter) Date(java.util.Date) DockerAccessException(io.fabric8.maven.docker.access.DockerAccessException) KubernetesClientException(io.fabric8.kubernetes.client.KubernetesClientException) MojoExecutionException(org.apache.maven.plugin.MojoExecutionException) MojoFailureException(org.apache.maven.plugin.MojoFailureException)

Example 3 with ImageNameFormatter

use of io.fabric8.maven.docker.util.ImageNameFormatter in project docker-maven-plugin by fabric8io.

the class AbstractDockerMojo method initImageConfiguration.

// Resolve and customize image configuration
private String initImageConfiguration(Date buildTimeStamp) {
    // Resolve images
    resolvedImages = ConfigHelper.resolveImages(log, // Unresolved images
    getAllImages(), new ConfigHelper.Resolver() {

        @Override
        public List<ImageConfiguration> resolve(ImageConfiguration image) {
            return imageConfigResolver.resolve(image, project, session);
        }
    }, // A filter which image to process
    filter, // customizer (can be overwritten by a subclass)
    this);
    // Check for simple Dockerfile mode
    File topDockerfile = new File(project.getBasedir(), "Dockerfile");
    if (topDockerfile.exists()) {
        if (resolvedImages.isEmpty()) {
            resolvedImages.add(createSimpleDockerfileConfig(topDockerfile));
        } else if (resolvedImages.size() == 1 && resolvedImages.get(0).getBuildConfiguration() == null) {
            resolvedImages.set(0, addSimpleDockerfileConfig(resolvedImages.get(0), topDockerfile));
        }
    }
    // Initialize configuration and detect minimal API version
    return ConfigHelper.initAndValidate(resolvedImages, apiVersion, new ImageNameFormatter(project, buildTimeStamp), log);
}
Also used : ImageConfigResolver(io.fabric8.maven.docker.config.handler.ImageConfigResolver) BuildImageConfiguration(io.fabric8.maven.docker.config.BuildImageConfiguration) ImageConfiguration(io.fabric8.maven.docker.config.ImageConfiguration) RunImageConfiguration(io.fabric8.maven.docker.config.RunImageConfiguration) ImageNameFormatter(io.fabric8.maven.docker.util.ImageNameFormatter) File(java.io.File)

Aggregations

ImageNameFormatter (io.fabric8.maven.docker.util.ImageNameFormatter)3 ImageConfiguration (io.fabric8.maven.docker.config.ImageConfiguration)2 ImageConfigResolver (io.fabric8.maven.docker.config.handler.ImageConfigResolver)2 Date (java.util.Date)2 MojoExecutionException (org.apache.maven.plugin.MojoExecutionException)2 MojoFailureException (org.apache.maven.plugin.MojoFailureException)2 KubernetesClientException (io.fabric8.kubernetes.client.KubernetesClientException)1 Fabric8ServiceException (io.fabric8.maven.core.service.Fabric8ServiceException)1 DockerAccessException (io.fabric8.maven.docker.access.DockerAccessException)1 BuildImageConfiguration (io.fabric8.maven.docker.config.BuildImageConfiguration)1 RunImageConfiguration (io.fabric8.maven.docker.config.RunImageConfiguration)1 GeneratorContext (io.fabric8.maven.generator.api.GeneratorContext)1 File (java.io.File)1 IOException (java.io.IOException)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1 ConstraintViolationException (javax.validation.ConstraintViolationException)1 MavenFilteringException (org.apache.maven.shared.filtering.MavenFilteringException)1