use of com.google.cloud.tools.jib.configuration.BuildContext in project jib by google.
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 google.
the class PushImageStep method makeList.
static ImmutableList<PushImageStep> makeList(BuildContext buildContext, ProgressEventDispatcher.Factory progressEventDispatcherFactory, RegistryClient registryClient, BlobDescriptor containerConfigurationDigestAndSize, Image builtImage, boolean manifestAlreadyExists) throws IOException {
// Gets the image manifest to push.
BuildableManifestTemplate manifestTemplate = new ImageToJsonTranslator(builtImage).getManifestTemplate(buildContext.getTargetFormat(), containerConfigurationDigestAndSize);
DescriptorDigest manifestDigest = Digests.computeJsonDigest(manifestTemplate);
Set<String> imageQualifiers = getImageQualifiers(buildContext, builtImage, manifestDigest);
EventHandlers eventHandlers = buildContext.getEventHandlers();
try (TimerEventDispatcher ignored = new TimerEventDispatcher(eventHandlers, "Preparing manifest pushers");
ProgressEventDispatcher progressDispatcher = progressEventDispatcherFactory.create("launching manifest pushers", imageQualifiers.size())) {
if (JibSystemProperties.skipExistingImages() && manifestAlreadyExists) {
eventHandlers.dispatch(LogEvent.info("Skipping pushing manifest; already exists."));
return ImmutableList.of();
}
return imageQualifiers.stream().map(qualifier -> new PushImageStep(buildContext, progressDispatcher.newChildProducer(), registryClient, manifestTemplate, qualifier, manifestDigest, containerConfigurationDigestAndSize.getDigest())).collect(ImmutableList.toImmutableList());
}
}
use of com.google.cloud.tools.jib.configuration.BuildContext in project jib by google.
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 google.
the class JavaContainerBuilderHelperTest method testFromExplodedWar.
@Test
public void testFromExplodedWar() throws URISyntaxException, IOException, InvalidImageReferenceException, CacheDirectoryCreationException {
// Copy test files to a temporary directory that we can safely operate on
Path resourceExplodedWar = Paths.get(Resources.getResource("plugins-common/exploded-war").toURI());
FileOperations.copy(ImmutableList.of(resourceExplodedWar), temporaryFolder.getRoot().toPath());
Path temporaryExplodedWar = temporaryFolder.getRoot().toPath().resolve("exploded-war");
Files.createDirectories(temporaryExplodedWar.resolve("WEB-INF/classes/empty_dir"));
Files.createFile(temporaryExplodedWar.resolve("WEB-INF/lib/project-dependency-1.0.0.jar"));
Set<String> projectArtifacts = ImmutableSet.of("project-dependency-1.0.0.jar");
JavaContainerBuilder javaContainerBuilder = JavaContainerBuilder.from(RegistryImage.named("base")).setAppRoot(AbsoluteUnixPath.get("/my/app"));
JibContainerBuilder jibContainerBuilder = JavaContainerBuilderHelper.fromExplodedWar(javaContainerBuilder, temporaryExplodedWar, projectArtifacts);
BuildContext buildContext = JibContainerBuilderTestHelper.toBuildContext(jibContainerBuilder, Containerizer.to(RegistryImage.named("target")).setExecutorService(MoreExecutors.newDirectExecutorService()));
FileEntriesLayer resourcesLayerConfigurations = getLayerConfigurationByName(buildContext, LayerType.RESOURCES.getName());
FileEntriesLayer classesLayerConfigurations = getLayerConfigurationByName(buildContext, LayerType.CLASSES.getName());
FileEntriesLayer dependenciesLayerConfigurations = getLayerConfigurationByName(buildContext, LayerType.DEPENDENCIES.getName());
FileEntriesLayer snapshotsLayerConfigurations = getLayerConfigurationByName(buildContext, LayerType.SNAPSHOT_DEPENDENCIES.getName());
FileEntriesLayer projectDependenciesLayerConfigurations = getLayerConfigurationByName(buildContext, LayerType.PROJECT_DEPENDENCIES.getName());
assertThat(projectDependenciesLayerConfigurations.getEntries()).comparingElementsUsing(SOURCE_FILE_OF).containsExactly(temporaryExplodedWar.resolve("WEB-INF/lib/project-dependency-1.0.0.jar"));
assertThat(dependenciesLayerConfigurations.getEntries()).comparingElementsUsing(SOURCE_FILE_OF).containsExactly(temporaryExplodedWar.resolve("WEB-INF/lib/dependency-1.0.0.jar"));
assertThat(snapshotsLayerConfigurations.getEntries()).comparingElementsUsing(SOURCE_FILE_OF).containsExactly(temporaryExplodedWar.resolve("WEB-INF/lib/dependencyX-1.0.0-SNAPSHOT.jar"));
assertThat(resourcesLayerConfigurations.getEntries()).comparingElementsUsing(SOURCE_FILE_OF).containsExactly(temporaryExplodedWar.resolve("META-INF"), temporaryExplodedWar.resolve("META-INF/context.xml"), temporaryExplodedWar.resolve("Test.jsp"), temporaryExplodedWar.resolve("WEB-INF"), temporaryExplodedWar.resolve("WEB-INF/classes"), temporaryExplodedWar.resolve("WEB-INF/classes/empty_dir"), temporaryExplodedWar.resolve("WEB-INF/classes/package"), temporaryExplodedWar.resolve("WEB-INF/classes/package/test.properties"), temporaryExplodedWar.resolve("WEB-INF/lib"), temporaryExplodedWar.resolve("WEB-INF/web.xml"));
assertThat(classesLayerConfigurations.getEntries()).comparingElementsUsing(SOURCE_FILE_OF).containsExactly(temporaryExplodedWar.resolve("WEB-INF/classes/HelloWorld.class"), temporaryExplodedWar.resolve("WEB-INF/classes/empty_dir"), temporaryExplodedWar.resolve("WEB-INF/classes/package"), temporaryExplodedWar.resolve("WEB-INF/classes/package/Other.class"));
assertThat(dependenciesLayerConfigurations.getEntries()).comparingElementsUsing(EXTRACTION_PATH_OF).containsExactly("/my/app/WEB-INF/lib/dependency-1.0.0.jar");
assertThat(snapshotsLayerConfigurations.getEntries()).comparingElementsUsing(EXTRACTION_PATH_OF).containsExactly("/my/app/WEB-INF/lib/dependencyX-1.0.0-SNAPSHOT.jar");
assertThat(resourcesLayerConfigurations.getEntries()).comparingElementsUsing(EXTRACTION_PATH_OF).containsExactly("/my/app/META-INF", "/my/app/META-INF/context.xml", "/my/app/Test.jsp", "/my/app/WEB-INF", "/my/app/WEB-INF/classes", "/my/app/WEB-INF/classes/empty_dir", "/my/app/WEB-INF/classes/package", "/my/app/WEB-INF/classes/package/test.properties", "/my/app/WEB-INF/lib", "/my/app/WEB-INF/web.xml");
assertThat(classesLayerConfigurations.getEntries()).comparingElementsUsing(EXTRACTION_PATH_OF).containsExactly("/my/app/WEB-INF/classes/HelloWorld.class", "/my/app/WEB-INF/classes/empty_dir", "/my/app/WEB-INF/classes/package", "/my/app/WEB-INF/classes/package/Other.class");
}
use of com.google.cloud.tools.jib.configuration.BuildContext in project jib by google.
the class ContainerBuildersTest method testCreate_registry.
@Test
public void testCreate_registry() throws IOException, InvalidImageReferenceException, CacheDirectoryCreationException {
JibContainerBuilder containerBuilder = ContainerBuilders.create("registry://registry-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("registry-image-ref");
assertThat(imageConfiguration.getDockerClient().isPresent()).isFalse();
assertThat(imageConfiguration.getTarPath().isPresent()).isFalse();
}
Aggregations