use of com.google.cloud.tools.jib.configuration.BuildContext in project jib by GoogleContainerTools.
the class ContainerBuildersTest method testCreate_dockerBaseImage.
@Test
public void testCreate_dockerBaseImage() throws IOException, InvalidImageReferenceException, CacheDirectoryCreationException {
JibContainerBuilder containerBuilder = ContainerBuilders.create("docker://docker-image-ref", Collections.emptySet(), mockCommonCliOptions, mockLogger);
BuildContext buildContext = JibContainerBuilderTestHelper.toBuildContext(containerBuilder, Containerizer.to(RegistryImage.named("ignored")));
ImageConfiguration imageConfiguration = buildContext.getBaseImageConfiguration();
assertThat(imageConfiguration.getImage().toString()).isEqualTo("docker-image-ref");
assertThat(imageConfiguration.getDockerClient().isPresent()).isTrue();
assertThat(imageConfiguration.getTarPath().isPresent()).isFalse();
}
use of com.google.cloud.tools.jib.configuration.BuildContext in project jib by GoogleContainerTools.
the class Containerizer method to.
/**
* Gets a new {@link Containerizer} that containerizes to a Docker daemon.
*
* @param dockerDaemonImage the {@link DockerDaemonImage} that defines target Docker daemon
* @return a new {@link Containerizer}
*/
public static Containerizer to(DockerDaemonImage dockerDaemonImage) {
ImageConfiguration imageConfiguration = ImageConfiguration.builder(dockerDaemonImage.getImageReference()).build();
DockerClient dockerClient = new DockerClient(dockerDaemonImage.getDockerExecutable(), dockerDaemonImage.getDockerEnvironment());
Function<BuildContext, StepsRunner> stepsRunnerFactory = buildContext -> StepsRunner.begin(buildContext).dockerLoadSteps(dockerClient);
return new Containerizer(DESCRIPTION_FOR_DOCKER_DAEMON, imageConfiguration, stepsRunnerFactory, false);
}
use of com.google.cloud.tools.jib.configuration.BuildContext in project jib by GoogleContainerTools.
the class RegistryCredentialRetrieverTest method testCall_none.
@Test
public void testCall_none() throws CredentialRetrievalException, CacheDirectoryCreationException {
BuildContext buildContext = makeFakeBuildContext(Arrays.asList(Optional::empty, Optional::empty), Collections.emptyList());
Assert.assertFalse(RegistryCredentialRetriever.getBaseImageCredential(buildContext).isPresent());
Mockito.verify(mockEventHandlers).dispatch(LogEvent.info("No credentials could be retrieved for baseregistry/baserepo"));
Assert.assertFalse(RegistryCredentialRetriever.getTargetImageCredential(buildContext).isPresent());
Mockito.verify(mockEventHandlers).dispatch(LogEvent.info("No credentials could be retrieved for targetregistry/targetrepo"));
}
use of com.google.cloud.tools.jib.configuration.BuildContext in project jib by GoogleContainerTools.
the class RegistryCredentialRetrieverTest method testCall_exception.
@Test
public void testCall_exception() throws CacheDirectoryCreationException {
CredentialRetrievalException credentialRetrievalException = Mockito.mock(CredentialRetrievalException.class);
BuildContext buildContext = makeFakeBuildContext(Collections.singletonList(() -> {
throw credentialRetrievalException;
}), Collections.emptyList());
try {
RegistryCredentialRetriever.getBaseImageCredential(buildContext);
Assert.fail("Should have thrown exception");
} catch (CredentialRetrievalException ex) {
Assert.assertSame(credentialRetrievalException, ex);
}
}
use of com.google.cloud.tools.jib.configuration.BuildContext in project jib by GoogleContainerTools.
the class RegistryCredentialRetrieverTest method testCall_retrieved.
@Test
public void testCall_retrieved() throws CredentialRetrievalException, CacheDirectoryCreationException {
BuildContext buildContext = makeFakeBuildContext(Arrays.asList(Optional::empty, () -> Optional.of(Credential.from("baseusername", "basepassword"))), Arrays.asList(() -> Optional.of(Credential.from("targetusername", "targetpassword")), () -> Optional.of(Credential.from("ignored", "ignored"))));
Assert.assertEquals(Optional.of(Credential.from("baseusername", "basepassword")), RegistryCredentialRetriever.getBaseImageCredential(buildContext));
Assert.assertEquals(Optional.of(Credential.from("targetusername", "targetpassword")), RegistryCredentialRetriever.getTargetImageCredential(buildContext));
}
Aggregations