use of io.fabric8.maven.docker.service.RegistryService.RegistryConfig 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
* @throws DockerAccessException
* @throws MojoExecutionException
*/
public void pushImages(Collection<ImageConfiguration> imageConfigs, int retries, RegistryConfig registryConfig) throws DockerAccessException, MojoExecutionException {
for (ImageConfiguration imageConfig : imageConfigs) {
BuildImageConfiguration buildConfig = imageConfig.getBuildConfiguration();
String name = imageConfig.getName();
if (buildConfig != null) {
String configuredRegistry = EnvUtil.fistRegistryOf(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));
for (String tag : imageConfig.getBuildConfiguration().getTags()) {
if (tag != null) {
docker.pushImage(new ImageName(name, tag).getFullName(), authConfig, configuredRegistry, retries);
}
}
}
}
}
use of io.fabric8.maven.docker.service.RegistryService.RegistryConfig 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 registryConfig registry configuration
*
* @throws DockerAccessException
* @throws MojoExecutionException
*/
public void pullImageWithPolicy(String image, ImagePullManager pullManager, RegistryConfig registryConfig, boolean hasImage) 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(hasImage, pullManager.getImagePullPolicy(), image)) {
return;
}
ImageName imageName = new ImageName(image);
long time = System.currentTimeMillis();
String actualRegistry = EnvUtil.fistRegistryOf(imageName.getRegistry(), registryConfig.getRegistry());
docker.pullImage(imageName.getFullName(), createAuthConfig(false, null, actualRegistry, registryConfig), actualRegistry);
log.info("Pulled %s in %s", imageName.getFullName(), EnvUtil.formatDurationTill(time));
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.docker.service.RegistryService.RegistryConfig in project docker-maven-plugin by fabric8io.
the class AbstractDockerMojo method pullImage.
protected void pullImage(RegistryService registryService, ImageConfiguration imageConfig, String pullRegistry) throws MojoExecutionException, DockerAccessException {
String imageName = imageConfig.getName();
RunImageConfiguration runConfiguration = imageConfig.getRunConfiguration();
ImagePullManager pullManager = getImagePullManager(determinePullPolicy(runConfiguration), autoPull);
RegistryConfig registryConfig = getRegistryConfig(pullRegistry);
registryService.pullImageWithPolicy(imageName, pullManager, registryConfig, imageConfig.getBuildConfiguration());
}
use of io.fabric8.maven.docker.service.RegistryService.RegistryConfig in project docker-maven-plugin by fabric8io.
the class JibBuildService method build.
public void build(String jibImageFormat, ImageConfiguration imageConfig, RegistryService.RegistryConfig registryConfig) throws MojoExecutionException {
try {
log.info("[[B]]JIB[[B]] image build started");
if (imageConfig.getBuildConfiguration().isDockerFileMode()) {
throw new MojoExecutionException("Dockerfile mode is not supported with JIB build strategy");
}
prependRegistry(imageConfig, mojoParameters.getProject().getProperties().getProperty(PUSH_REGISTRY));
BuildDirs buildDirs = new BuildDirs(imageConfig.getName(), mojoParameters);
final Credential pullRegistryCredential = getRegistryCredentials(registryConfig, false, imageConfig, log);
final JibContainerBuilder containerBuilder = containerFromImageConfiguration(jibImageFormat, imageConfig, pullRegistryCredential);
File dockerTarArchive = getAssemblyTarArchive(imageConfig, serviceHub, mojoParameters, log);
for (AssemblyConfiguration assemblyConfiguration : imageConfig.getBuildConfiguration().getAssemblyConfigurations()) {
// TODO: Improve Assembly Manager so that the effective assemblyFileEntries computed can be properly shared
// the call to DockerAssemblyManager.getInstance().createDockerTarArchive should not be necessary,
// files should be added using the AssemblyFileEntry list. DockerAssemblyManager, should provide
// a common way to achieve this so that both the tar builder and any other builder could get a hold of
// archive customizers, file entries, etc.
AssemblyFiles assemblyFiles = serviceHub.getDockerAssemblyManager().getAssemblyFiles(imageConfig.getName(), assemblyConfiguration, mojoParameters, log);
final Map<File, AssemblyFiles.Entry> files = assemblyFiles.getUpdatedEntriesAndRefresh().stream().collect(Collectors.toMap(AssemblyFiles.Entry::getDestFile, Function.identity(), (oldV, newV) -> newV));
JibServiceUtil.copyToContainer(containerBuilder, buildDirs.getOutputDirectory(), buildDirs.getOutputDirectory().getAbsolutePath(), files);
}
JibServiceUtil.buildContainer(containerBuilder, TarImage.at(dockerTarArchive.toPath()).named(imageConfig.getName()), log);
log.info(" %s successfully built", dockerTarArchive.getAbsolutePath());
} catch (Exception ex) {
throw new MojoExecutionException("Error when building JIB image", ex);
}
}
use of io.fabric8.maven.docker.service.RegistryService.RegistryConfig in project docker-maven-plugin by fabric8io.
the class JibBuildService method push.
public void push(Collection<ImageConfiguration> imageConfigs, int retries, RegistryService.RegistryConfig registryConfig, boolean skipTag) throws MojoExecutionException {
try {
for (ImageConfiguration imageConfiguration : imageConfigs) {
prependRegistry(imageConfiguration, registryConfig.getRegistry());
log.info("This push refers to: %s", imageConfiguration.getName());
JibServiceUtil.jibPush(imageConfiguration, getRegistryCredentials(registryConfig, true, imageConfiguration, log), getBuildTarArchive(imageConfiguration, mojoParameters), log);
}
} catch (Exception ex) {
throw new MojoExecutionException("Error when push JIB image", ex);
}
}
Aggregations