Search in sources :

Example 1 with BuildContext

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();
}
Also used : BuildContext(com.google.cloud.tools.jib.configuration.BuildContext) ImageConfiguration(com.google.cloud.tools.jib.configuration.ImageConfiguration) JibContainerBuilder(com.google.cloud.tools.jib.api.JibContainerBuilder) Test(org.junit.Test)

Example 2 with BuildContext

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);
}
Also used : ArrayListMultimap(com.google.common.collect.ArrayListMultimap) ImageConfiguration(com.google.cloud.tools.jib.configuration.ImageConfiguration) ListMultimap(com.google.common.collect.ListMultimap) BuildContext(com.google.cloud.tools.jib.configuration.BuildContext) Function(java.util.function.Function) HashSet(java.util.HashSet) DockerClient(com.google.cloud.tools.jib.docker.DockerClient) XdgDirectories(com.google.cloud.tools.jib.filesystem.XdgDirectories) Path(java.nio.file.Path) ExecutorService(java.util.concurrent.ExecutorService) Nullable(javax.annotation.Nullable) ImmutableSet(com.google.common.collect.ImmutableSet) Files(java.nio.file.Files) Set(java.util.Set) IOException(java.io.IOException) StepsRunner(com.google.cloud.tools.jib.builder.steps.StepsRunner) BuildResult(com.google.cloud.tools.jib.builder.steps.BuildResult) Executors(java.util.concurrent.Executors) ExecutionException(java.util.concurrent.ExecutionException) Consumer(java.util.function.Consumer) List(java.util.List) Paths(java.nio.file.Paths) ImmutableListMultimap(com.google.common.collect.ImmutableListMultimap) EventHandlers(com.google.cloud.tools.jib.event.EventHandlers) Optional(java.util.Optional) Preconditions(com.google.common.base.Preconditions) DockerClient(com.google.cloud.tools.jib.docker.DockerClient) BuildContext(com.google.cloud.tools.jib.configuration.BuildContext) ImageConfiguration(com.google.cloud.tools.jib.configuration.ImageConfiguration) StepsRunner(com.google.cloud.tools.jib.builder.steps.StepsRunner)

Example 3 with BuildContext

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"));
}
Also used : BuildContext(com.google.cloud.tools.jib.configuration.BuildContext) Test(org.junit.Test)

Example 4 with BuildContext

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);
    }
}
Also used : BuildContext(com.google.cloud.tools.jib.configuration.BuildContext) CredentialRetrievalException(com.google.cloud.tools.jib.registry.credentials.CredentialRetrievalException) Test(org.junit.Test)

Example 5 with BuildContext

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));
}
Also used : BuildContext(com.google.cloud.tools.jib.configuration.BuildContext) Test(org.junit.Test)

Aggregations

BuildContext (com.google.cloud.tools.jib.configuration.BuildContext)45 Test (org.junit.Test)31 ImageConfiguration (com.google.cloud.tools.jib.configuration.ImageConfiguration)23 EventHandlers (com.google.cloud.tools.jib.event.EventHandlers)12 IOException (java.io.IOException)12 Set (java.util.Set)12 BuildResult (com.google.cloud.tools.jib.builder.steps.BuildResult)9 JibContainerBuilder (com.google.cloud.tools.jib.api.JibContainerBuilder)8 AbsoluteUnixPath (com.google.cloud.tools.jib.api.buildplan.AbsoluteUnixPath)8 Platform (com.google.cloud.tools.jib.api.buildplan.Platform)8 TimerEventDispatcher (com.google.cloud.tools.jib.builder.TimerEventDispatcher)8 Preconditions (com.google.common.base.Preconditions)8 List (java.util.List)8 Optional (java.util.Optional)8 ExecutionException (java.util.concurrent.ExecutionException)8 Nullable (javax.annotation.Nullable)8 LogEvent (com.google.cloud.tools.jib.api.LogEvent)6 RegistryException (com.google.cloud.tools.jib.api.RegistryException)6 StepsRunner (com.google.cloud.tools.jib.builder.steps.StepsRunner)6 DockerClient (com.google.cloud.tools.jib.docker.DockerClient)6