Search in sources :

Example 61 with Configuration

use of io.fabric8.maven.core.model.Configuration in project docker-maven-plugin by fabric8io.

the class ArchiveService method getAssemblyFiles.

/**
 * Get a mapping of original to destination files which a covered by an assembly. This can be used
 * to watch the source files for changes in order to update the target (either by recreating a docker image
 * or by copying it into a running container)
 *
 * @param imageConfig image config for which to get files. The build- and assembly configuration in this image
 *                    config must not be null.
 * @param mojoParameters needed for tracking the assembly
 * @return mapping of assembly files
 * @throws MojoExecutionException
 */
public AssemblyFiles getAssemblyFiles(ImageConfiguration imageConfig, String assemblyName, MojoParameters mojoParameters) throws MojoExecutionException {
    String name = imageConfig.getName();
    try {
        List<AssemblyConfiguration> assemblyConfigurations = imageConfig.getBuildConfiguration().getAssemblyConfigurations();
        AssemblyConfiguration assemblyConfig = assemblyConfigurations.stream().filter(a -> a.getName().equals(assemblyName)).findFirst().orElse(null);
        if (assemblyConfig == null) {
            throw new IllegalArgumentException(String.format("Provided assembly name \"%s\" does not match any configured assemblies.", assemblyName));
        }
        return dockerAssemblyManager.getAssemblyFiles(name, assemblyConfig, mojoParameters, log);
    } catch (InvalidAssemblerConfigurationException | ArchiveCreationException | AssemblyFormattingException e) {
        throw new MojoExecutionException("Cannot extract assembly files for image " + name + ": " + e, e);
    }
}
Also used : AssemblyFormattingException(org.apache.maven.plugins.assembly.format.AssemblyFormattingException) AssemblyConfiguration(io.fabric8.maven.docker.config.AssemblyConfiguration) MojoExecutionException(org.apache.maven.plugin.MojoExecutionException) ArchiveCreationException(org.apache.maven.plugins.assembly.archive.ArchiveCreationException) InvalidAssemblerConfigurationException(org.apache.maven.plugins.assembly.InvalidAssemblerConfigurationException)

Example 62 with Configuration

use of io.fabric8.maven.core.model.Configuration in project docker-maven-plugin by fabric8io.

the class RegistryService method pullImageWithPolicy.

/**
 *  Check an image, and, if <code>autoPull</code> is set to true, fetch it. Otherwise if the image
 *  is not existent, throw an error
 *
 * @param image image which is required to be pulled
 * @param pullManager image pull manager
 * @param registryConfig registry configuration
 * @param buildImageConfiguration image build configuration
 * @throws DockerAccessException in case of error in contacting docker daemon
 * @throws MojoExecutionException in case of any other misc failure
 */
public void pullImageWithPolicy(String image, ImagePullManager pullManager, RegistryConfig registryConfig, BuildImageConfiguration buildImageConfiguration) throws DockerAccessException, MojoExecutionException {
    // Already pulled, so we don't need to take care
    if (pullManager.hasAlreadyPulled(image)) {
        return;
    }
    // Check if a pull is required
    if (!imageRequiresPull(queryService.hasImage(image), pullManager.getImagePullPolicy(), image)) {
        return;
    }
    final ImageName imageName = new ImageName(image);
    final long pullStartTime = System.currentTimeMillis();
    final String actualRegistry = EnvUtil.firstRegistryOf(imageName.getRegistry(), registryConfig.getRegistry());
    final CreateImageOptions createImageOptions = new CreateImageOptions(buildImageConfiguration != null ? buildImageConfiguration.getCreateImageOptions() : Collections.emptyMap()).fromImage(imageName.getNameWithoutTag(actualRegistry)).tag(imageName.getDigest() != null ? imageName.getDigest() : imageName.getTag());
    docker.pullImage(imageName.getFullName(), createAuthConfig(false, null, actualRegistry, registryConfig), actualRegistry, createImageOptions);
    log.info("Pulled %s in %s", imageName.getFullName(), EnvUtil.formatDurationTill(pullStartTime));
    pullManager.pulled(image);
    if (actualRegistry != null && !imageName.hasRegistry()) {
        // If coming from a registry which was not contained in the original name, add a tag from the
        // full name with the registry to the short name with no-registry.
        docker.tag(imageName.getFullName(actualRegistry), image, false);
    }
}
Also used : ImageName(io.fabric8.maven.docker.util.ImageName) CreateImageOptions(io.fabric8.maven.docker.access.CreateImageOptions)

Example 63 with Configuration

use of io.fabric8.maven.core.model.Configuration in project docker-maven-plugin by fabric8io.

the class DockerComposeServiceWrapper method getVolumeConfig.

RunVolumeConfiguration getVolumeConfig() {
    RunVolumeConfiguration.Builder builder = new RunVolumeConfiguration.Builder();
    List<String> volumes = asList("volumes");
    boolean added = false;
    if (volumes.size() > 0) {
        builder.bind(volumes);
        added = true;
    }
    List<String> volumesFrom = asList("volumes_from");
    if (volumesFrom.size() > 0) {
        builder.from(volumesFrom);
        added = true;
    }
    if (added) {
        RunVolumeConfiguration configuration = builder.build();
        VolumeBindingUtil.resolveRelativeVolumeBindings(baseDir, configuration);
        return configuration;
    }
    return null;
}
Also used : RunVolumeConfiguration(io.fabric8.maven.docker.config.RunVolumeConfiguration)

Example 64 with Configuration

use of io.fabric8.maven.core.model.Configuration in project docker-maven-plugin by fabric8io.

the class BuildService method buildImage.

/**
 * Build an image
 *
 * @param imageConfig the image configuration
 * @param params      mojo params for the project
 * @param noCache     if not null, dictate the caching behaviour. Otherwise its taken from the build configuration
 * @param buildArgs   docker build args
 * @throws DockerAccessException
 * @throws MojoExecutionException
 */
protected void buildImage(ImageConfiguration imageConfig, MojoParameters params, boolean noCache, boolean squash, Map<String, String> buildArgs, File dockerArchive) throws DockerAccessException, MojoExecutionException {
    String imageName = imageConfig.getName();
    ImageName.validate(imageName);
    BuildImageConfiguration buildConfig = imageConfig.getBuildConfiguration();
    String oldImageId = null;
    CleanupMode cleanupMode = buildConfig.cleanupMode();
    if (cleanupMode.isRemove()) {
        oldImageId = queryService.getImageId(imageName);
    }
    if (buildConfig.getDockerArchive() != null) {
        File tarArchive = buildConfig.getAbsoluteDockerTarPath(params);
        String archiveImageName = getArchiveImageName(buildConfig, tarArchive);
        long time = System.currentTimeMillis();
        docker.loadImage(imageName, tarArchive);
        log.info("%s: Loaded tarball in %s", buildConfig.getDockerArchive(), EnvUtil.formatDurationTill(time));
        if (archiveImageName != null && !archiveImageName.equals(imageName)) {
            docker.tag(archiveImageName, imageName, true);
        }
        return;
    }
    Map<String, String> mergedBuildMap = prepareBuildArgs(buildArgs, buildConfig);
    // auto is now supported by docker, consider switching?
    BuildOptions opts = new BuildOptions(buildConfig.getBuildOptions()).dockerfile(getDockerfileName(buildConfig)).forceRemove(cleanupMode.isRemove()).noCache(noCache).squash(squash).cacheFrom(buildConfig.getCacheFrom()).network(buildConfig.getNetwork()).buildArgs(mergedBuildMap);
    String newImageId = doBuildImage(imageName, dockerArchive, opts);
    log.info("%s: Built image %s", imageConfig.getDescription(), newImageId);
    removeDanglingImage(imageName, oldImageId, newImageId, cleanupMode, true);
}
Also used : BuildOptions(io.fabric8.maven.docker.access.BuildOptions) CleanupMode(io.fabric8.maven.docker.config.CleanupMode) File(java.io.File) BuildImageConfiguration(io.fabric8.maven.docker.config.BuildImageConfiguration)

Example 65 with Configuration

use of io.fabric8.maven.core.model.Configuration in project docker-maven-plugin by fabric8io.

the class BuildService method buildArchive.

/**
 * Create docker archive for building image
 *
 * @param imageConfiguration image configuration
 * @param buildContext       docker build context
 * @param archivePath        build archive only flag, it can have values TRUE or FALSE and also
 *                           it can hold path to archive where it might get copied over
 * @return tarball for docker image
 * @throws MojoExecutionException in case any exception comes during building tarball
 */
public File buildArchive(ImageConfiguration imageConfiguration, BuildContext buildContext, String archivePath) throws MojoExecutionException {
    String imageName = imageConfiguration.getName();
    ImageName.validate(imageName);
    BuildImageConfiguration buildConfig = imageConfiguration.getBuildConfiguration();
    MojoParameters params = buildContext.getMojoParameters();
    if (buildConfig.getDockerArchive() != null) {
        return buildConfig.getAbsoluteDockerTarPath(params);
    }
    long time = System.currentTimeMillis();
    File dockerArchive = archiveService.createArchive(imageName, buildConfig, params, log);
    log.info("%s: Created %s in %s", imageConfiguration.getDescription(), dockerArchive.getName(), EnvUtil.formatDurationTill(time));
    // Copy created tarball to directory if specified
    try {
        copyDockerArchive(imageConfiguration, dockerArchive, archivePath);
    } catch (IOException exception) {
        throw new MojoExecutionException("Error while copying created tar to specified buildArchive path: " + archivePath, exception);
    }
    return dockerArchive;
}
Also used : MojoExecutionException(org.apache.maven.plugin.MojoExecutionException) MojoParameters(io.fabric8.maven.docker.util.MojoParameters) IOException(java.io.IOException) File(java.io.File) BuildImageConfiguration(io.fabric8.maven.docker.config.BuildImageConfiguration)

Aggregations

ParallelTest (io.strimzi.test.annotations.ParallelTest)142 Kafka (io.strimzi.api.kafka.model.Kafka)138 KafkaBuilder (io.strimzi.api.kafka.model.KafkaBuilder)132 HashMap (java.util.HashMap)97 IOException (java.io.IOException)86 IntOrString (io.fabric8.kubernetes.api.model.IntOrString)83 ConfigMap (io.fabric8.kubernetes.api.model.ConfigMap)80 Map (java.util.Map)79 StatefulSet (io.fabric8.kubernetes.api.model.apps.StatefulSet)76 ArrayList (java.util.ArrayList)76 List (java.util.List)70 TopologySpreadConstraint (io.fabric8.kubernetes.api.model.TopologySpreadConstraint)66 GenericKafkaListenerBuilder (io.strimzi.api.kafka.model.listener.arraylistener.GenericKafkaListenerBuilder)66 Matchers.containsString (org.hamcrest.Matchers.containsString)58 Service (io.fabric8.kubernetes.api.model.Service)55 Collectors (java.util.stream.Collectors)55 Container (io.fabric8.kubernetes.api.model.Container)54 PersistentVolumeClaim (io.fabric8.kubernetes.api.model.PersistentVolumeClaim)50 Quantity (io.fabric8.kubernetes.api.model.Quantity)48 File (java.io.File)47