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);
}
}
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);
}
}
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;
}
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);
}
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;
}
Aggregations