use of com.google.cloud.tools.jib.api.Credential 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 com.google.cloud.tools.jib.api.Credential in project docker-maven-plugin by fabric8io.
the class JibBuildServiceTest method testGetRegistryCredentialsForPush.
@Test
@java.lang.SuppressWarnings("squid:S00112")
public void testGetRegistryCredentialsForPush() throws MojoExecutionException {
// Given
ImageConfiguration imageConfiguration = getImageConfiguration();
RegistryService.RegistryConfig registryConfig = new RegistryService.RegistryConfig.Builder().authConfig(Collections.emptyMap()).authConfigFactory(authConfigFactory).settings(settings).build();
mockAuthConfigFactory(true, registryConfig);
// When
Credential credential = JibBuildService.getRegistryCredentials(registryConfig, true, imageConfiguration, logger);
// Then
assertNotNull(credential);
assertEquals("testuserpush", credential.getUsername());
assertEquals("testpass", credential.getPassword());
}
use of com.google.cloud.tools.jib.api.Credential in project docker-maven-plugin by fabric8io.
the class JibBuildService method getRegistryCredentials.
static Credential getRegistryCredentials(RegistryService.RegistryConfig registryConfig, boolean isPush, ImageConfiguration imageConfiguration, Logger log) throws MojoExecutionException {
String registry;
if (isPush) {
registry = EnvUtil.firstRegistryOf(new ImageName(imageConfiguration.getName()).getRegistry(), imageConfiguration.getRegistry(), registryConfig.getRegistry());
} else {
registry = EnvUtil.firstRegistryOf(new ImageName(getBaseImage(imageConfiguration)).getRegistry(), registryConfig.getRegistry());
}
if (registry == null || DEFAULT_DOCKER_REGISTRIES.contains(registry)) {
// Let's assume docker is default registry.
registry = DOCKER_LOGIN_DEFAULT_REGISTRY;
}
AuthConfigFactory authConfigFactory = registryConfig.getAuthConfigFactory();
AuthConfig standardAuthConfig = authConfigFactory.createAuthConfig(isPush, registryConfig.isSkipExtendedAuth(), registryConfig.getAuthConfig(), registryConfig.getSettings(), null, registry);
Credential credentials = null;
if (standardAuthConfig != null) {
credentials = Credential.from(standardAuthConfig.getUsername(), standardAuthConfig.getPassword());
}
return credentials;
}
use of com.google.cloud.tools.jib.api.Credential in project docker-maven-plugin by fabric8io.
the class JibBuildServiceTest method testGetRegistryCredentialsForPull.
@Test
@java.lang.SuppressWarnings("squid:S00112")
public void testGetRegistryCredentialsForPull() throws MojoExecutionException {
// Given
ImageConfiguration imageConfiguration = getImageConfiguration();
RegistryService.RegistryConfig registryConfig = new RegistryService.RegistryConfig.Builder().authConfig(Collections.emptyMap()).authConfigFactory(authConfigFactory).settings(settings).build();
mockAuthConfigFactory(false, registryConfig);
// When
Credential credential = JibBuildService.getRegistryCredentials(registryConfig, false, imageConfiguration, logger);
// Then
assertNotNull(credential);
assertEquals("testuserpull", credential.getUsername());
assertEquals("testpass", credential.getPassword());
}
Aggregations