use of io.fabric8.maven.core.model.Configuration in project docker-maven-plugin by fabric8io.
the class DockerAssemblyManager method createDockerTarArchive.
/**
* Create an docker tar archive from the given configuration which can be send to the Docker host for
* creating the image.
*
* @param imageName Name of the image to create (used for creating build directories)
* @param params Mojos parameters (used for finding the directories)
* @param buildConfig configuration for how to build the image
* @param log Logger used to display warning if permissions are to be normalized
* @param finalCustomizer finalCustomizer to be applied to the tar archive
* @return file holding the path to the created assembly tar file
* @throws MojoExecutionException
*/
public File createDockerTarArchive(String imageName, final MojoParameters params, final BuildImageConfiguration buildConfig, Logger log, ArchiverCustomizer finalCustomizer) throws MojoExecutionException {
final BuildDirs buildDirs = createBuildDirs(imageName, params);
final List<AssemblyConfiguration> assemblyConfigurations = buildConfig.getAssemblyConfigurations();
final List<ArchiverCustomizer> archiveCustomizers = new ArrayList<>();
// Build up assembly. In dockerfile mode this must be added explicitly in the Dockerfile with an ADD
if (hasAssemblyConfiguration(assemblyConfigurations)) {
createAssemblyArchives(assemblyConfigurations, params, buildDirs);
}
try {
if (buildConfig.isDockerFileMode()) {
// Use specified docker directory which must include a Dockerfile.
final File dockerFile = buildConfig.getAbsoluteDockerFilePath(params);
if (!dockerFile.exists()) {
throw new MojoExecutionException("Configured Dockerfile \"" + buildConfig.getDockerFile() + "\" (resolved to \"" + dockerFile + "\") doesn't exist");
}
FixedStringSearchInterpolator interpolator = DockerFileUtil.createInterpolator(params, buildConfig.getFilter());
verifyGivenDockerfile(dockerFile, buildConfig, interpolator, log);
interpolateDockerfile(dockerFile, buildDirs, interpolator);
// User dedicated Dockerfile from extra directory
archiveCustomizers.add(new ArchiverCustomizer() {
@Override
public TarArchiver customize(TarArchiver archiver) throws IOException {
DefaultFileSet fileSet = DefaultFileSet.fileSet(buildConfig.getAbsoluteContextDirPath(params));
addDockerIncludesExcludesIfPresent(fileSet, params);
// Exclude non-interpolated dockerfile from source tree
// Interpolated Dockerfile is already added as it was created into the output directory when
// using dir dir mode
excludeDockerfile(fileSet, dockerFile);
// directly to docker.tar (as the output builddir is not picked up in archive mode)
if (isArchive(assemblyConfigurations)) {
String name = dockerFile.getName();
archiver.addFile(new File(buildDirs.getOutputDirectory(), name), name);
}
archiver.addFileSet(fileSet);
return archiver;
}
});
} else {
// Create custom docker file in output dir
DockerFileBuilder builder = createDockerFileBuilder(buildConfig, assemblyConfigurations);
builder.write(buildDirs.getOutputDirectory());
// Add own Dockerfile
final File dockerFile = new File(buildDirs.getOutputDirectory(), DOCKERFILE_NAME);
archiveCustomizers.add(new ArchiverCustomizer() {
@Override
public TarArchiver customize(TarArchiver archiver) throws IOException {
archiver.addFile(dockerFile, DOCKERFILE_NAME);
return archiver;
}
});
}
// If required make all files in the assembly executable
if (assemblyConfigurations.stream().anyMatch(assemblyConfig -> assemblyConfig.getPermissions() == AssemblyConfiguration.PermissionMode.exec || assemblyConfig.getPermissions() == AssemblyConfiguration.PermissionMode.auto && EnvUtil.isWindows())) {
archiveCustomizers.add(new AllFilesExecCustomizer(log));
}
if (finalCustomizer != null) {
archiveCustomizers.add(finalCustomizer);
}
return createBuildTarBall(buildDirs, archiveCustomizers, assemblyConfigurations, buildConfig.getCompression());
} catch (IOException e) {
throw new MojoExecutionException(String.format("Cannot create %s in %s", DOCKERFILE_NAME, buildDirs.getOutputDirectory()), e);
}
}
use of io.fabric8.maven.core.model.Configuration in project docker-maven-plugin by fabric8io.
the class VolumeRemoveMojo method executeInternal.
@Override
protected void executeInternal(ServiceHub serviceHub) throws DockerAccessException, MojoExecutionException {
if (getVolumes() == null) {
log.info("No volume configuration found.");
return;
}
VolumeService volService = serviceHub.getVolumeService();
for (VolumeConfiguration volume : getVolumes()) {
log.info("Removing volume %s", volume.getName());
volService.removeVolume(volume.getName());
}
}
use of io.fabric8.maven.core.model.Configuration in project docker-maven-plugin by fabric8io.
the class CopyMojo method copyFromTemporaryContainers.
private void copyFromTemporaryContainers(DockerAccess dockerAccess, RunService runService, RegistryService registryService, ArchiveService archiveService, QueryService queryService, GavLabel gavLabel) throws IOException, MojoExecutionException {
List<ImageConfiguration> imageConfigurations = getResolvedImages();
for (ImageConfiguration imageConfiguration : imageConfigurations) {
CopyConfiguration copyConfiguration = imageConfiguration.getCopyConfiguration();
String imageName = imageConfiguration.getName();
if (isEmpty(copyConfiguration)) {
log.debug("Copy configuration is not defined for %s image, skipping coping", imageName);
continue;
}
try (ContainerRemover containerRemover = new ContainerRemover(log, runService, removeVolumes)) {
String containerId = createContainer(runService, registryService, imageConfiguration, gavLabel);
containerRemover.setContainerId(containerId);
log.debug("Created %s container from %s image", containerId, imageName);
copy(dockerAccess, archiveService, containerId, imageName, copyConfiguration);
}
}
}
use of io.fabric8.maven.core.model.Configuration in project docker-maven-plugin by fabric8io.
the class CopyMojo method copyFromStartedContainers.
private void copyFromStartedContainers(DockerAccess dockerAccess, RunService runService, ArchiveService archiveService, GavLabel gavLabel) throws IOException, MojoExecutionException {
List<ContainerDescriptor> containerDescriptors = runService.getContainers(gavLabel);
for (ContainerDescriptor containerDescriptor : containerDescriptors) {
ImageConfiguration imageConfiguration = containerDescriptor.getImageConfig();
CopyConfiguration copyConfiguration = imageConfiguration.getCopyConfiguration();
String imageName = imageConfiguration.getName();
if (isEmpty(copyConfiguration)) {
log.debug("Copy configuration is not defined for %s image, skipping coping", imageName);
continue;
}
String containerId = containerDescriptor.getContainerId();
log.debug("Found %s container of %s image started by start mojo", containerId, imageName);
copy(dockerAccess, archiveService, containerId, imageName, copyConfiguration);
}
}
use of io.fabric8.maven.core.model.Configuration in project docker-maven-plugin by fabric8io.
the class CopyMojo method copyFromExistingContainers.
private void copyFromExistingContainers(DockerAccess dockerAccess, ArchiveService archiveService, QueryService queryService) throws IOException, MojoExecutionException {
List<ImageConfiguration> imageConfigurations = getResolvedImages();
for (ImageConfiguration imageConfiguration : imageConfigurations) {
CopyConfiguration copyConfiguration = imageConfiguration.getCopyConfiguration();
String imageName = imageConfiguration.getName();
if (isEmpty(copyConfiguration)) {
log.debug("Copy configuration is not defined for %s image, skipping coping", imageName);
continue;
}
Collection<Container> containers = getContainersForImage(queryService, imageConfiguration);
if (containers.isEmpty()) {
log.warn("Found no containers of %s image", imageName);
continue;
}
if (containers.size() > 1) {
log.warn("Found more than one container of %s image", imageName);
}
for (Container container : containers) {
String containerId = container.getId();
log.debug("Found %s container of %s image", containerId, imageName);
copy(dockerAccess, archiveService, containerId, imageName, copyConfiguration);
}
}
}
Aggregations