Search in sources :

Example 1 with StepsRunner

use of com.google.cloud.tools.jib.builder.steps.StepsRunner 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 2 with StepsRunner

use of com.google.cloud.tools.jib.builder.steps.StepsRunner in project jib by google.

the class Containerizer method to.

/**
 * Gets a new {@link Containerizer} that containerizes to a container registry.
 *
 * @param registryImage the {@link RegistryImage} that defines target container registry and
 *     credentials
 * @return a new {@link Containerizer}
 */
public static Containerizer to(RegistryImage registryImage) {
    ImageConfiguration imageConfiguration = ImageConfiguration.builder(registryImage.getImageReference()).setCredentialRetrievers(registryImage.getCredentialRetrievers()).build();
    Function<BuildContext, StepsRunner> stepsRunnerFactory = buildContext -> StepsRunner.begin(buildContext).registryPushSteps();
    return new Containerizer(DESCRIPTION_FOR_DOCKER_REGISTRY, imageConfiguration, stepsRunnerFactory, true);
}
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) 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 StepsRunner

use of com.google.cloud.tools.jib.builder.steps.StepsRunner in project jib by google.

the class Containerizer method to.

/**
 * Gets a new {@link Containerizer} that containerizes to a tarball archive.
 *
 * @param tarImage the {@link TarImage} that defines target output file
 * @return a new {@link Containerizer}
 */
public static Containerizer to(TarImage tarImage) {
    Optional<ImageReference> imageReference = tarImage.getImageReference();
    if (!imageReference.isPresent()) {
        throw new IllegalArgumentException("Image name must be set when building a TarImage; use TarImage#named(...) to set the name" + " of the target image");
    }
    ImageConfiguration imageConfiguration = ImageConfiguration.builder(imageReference.get()).build();
    Function<BuildContext, StepsRunner> stepsRunnerFactory = buildContext -> StepsRunner.begin(buildContext).tarBuildSteps(tarImage.getPath());
    return new Containerizer(DESCRIPTION_FOR_TARBALL, 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) 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 4 with StepsRunner

use of com.google.cloud.tools.jib.builder.steps.StepsRunner in project component-runtime by Talend.

the class RemoteEngineCustomizer method loadImage.

private Image loadImage(final String from, final String to, final ExecutorService executor, final Path baseCache, final Path appCache, final DockerConfiguration dockerConfiguration, final ImageType fromImageType) throws Exception {
    final StepsRunner steps = StepsRunner.begin(BuildContext.builder().setBaseImageConfiguration(createBaseImage(from, dockerConfiguration, fromImageType)).setTargetFormat(ImageFormat.OCI).setTargetImageConfiguration(ImageConfiguration.builder(ImageReference.parse(to)).build()).setToolName("Talend Component Kit Remote Engine Customizer " + Versions.VERSION).setExecutorService(executor).setBaseImageLayersCacheDirectory(baseCache).setApplicationLayersCacheDirectory(appCache).build());
    final String description = "Extracting registry properties";
    final Field rootProgressDescription = asAccessible(StepsRunner.class.getDeclaredField("rootProgressDescription"));
    rootProgressDescription.set(steps, description);
    final List<Runnable> stepsInstance = (List<Runnable>) asAccessible(StepsRunner.class.getDeclaredField("stepsToRun")).get(steps);
    try {
        asAccessible(StepsRunner.class.getDeclaredMethod("addRetrievalSteps", boolean.class)).invoke(steps, true);
    } catch (final IllegalAccessException | NoSuchMethodException e) {
        throw new IllegalStateException(e);
    } catch (final InvocationTargetException e) {
        throw new IllegalStateException(e.getTargetException());
    }
    Stream.of("buildAndCacheApplicationLayers", "buildImage").forEach(method -> {
        stepsInstance.add(() -> {
            try {
                asAccessible(StepsRunner.class.getDeclaredMethod(method)).invoke(steps);
            } catch (final IllegalAccessException | NoSuchMethodException e) {
                throw new IllegalStateException(e);
            } catch (final InvocationTargetException e) {
                throw new IllegalStateException(e.getTargetException());
            }
        });
    });
    try (final ProgressEventDispatcher progressEventDispatcher = ProgressEventDispatcher.newRoot(EventHandlers.builder().add(LogEvent.class, le -> {
        switch(le.getLevel()) {
            case WARN:
                log.warn(le.getMessage());
                break;
            case DEBUG:
                log.debug(le.getMessage());
                break;
            case ERROR:
                log.error(le.getMessage());
                break;
            case INFO:
                log.error(le.getMessage());
                break;
            default:
                log.info("(" + le.getLevel() + ") " + le.getMessage());
                break;
        }
    }).build(), description, stepsInstance.size())) {
        asAccessible(StepsRunner.class.getDeclaredField("rootProgressDispatcher")).set(steps, progressEventDispatcher);
        stepsInstance.forEach(Runnable::run);
    }
    final Object stepResult = asAccessible(StepsRunner.class.getDeclaredField("results")).get(steps);
    return ((Future<Image>) asAccessible(stepResult.getClass().getDeclaredField("builtImage")).get(stepResult)).get();
}
Also used : ProgressEventDispatcher(com.google.cloud.tools.jib.builder.ProgressEventDispatcher) InvocationTargetException(java.lang.reflect.InvocationTargetException) Field(java.lang.reflect.Field) StepsRunner(com.google.cloud.tools.jib.builder.steps.StepsRunner) Future(java.util.concurrent.Future) List(java.util.List) Collectors.toList(java.util.stream.Collectors.toList)

Example 5 with StepsRunner

use of com.google.cloud.tools.jib.builder.steps.StepsRunner 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);
}
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)

Aggregations

StepsRunner (com.google.cloud.tools.jib.builder.steps.StepsRunner)7 List (java.util.List)7 BuildResult (com.google.cloud.tools.jib.builder.steps.BuildResult)6 BuildContext (com.google.cloud.tools.jib.configuration.BuildContext)6 ImageConfiguration (com.google.cloud.tools.jib.configuration.ImageConfiguration)6 DockerClient (com.google.cloud.tools.jib.docker.DockerClient)6 EventHandlers (com.google.cloud.tools.jib.event.EventHandlers)6 XdgDirectories (com.google.cloud.tools.jib.filesystem.XdgDirectories)6 Preconditions (com.google.common.base.Preconditions)6 ArrayListMultimap (com.google.common.collect.ArrayListMultimap)6 ImmutableListMultimap (com.google.common.collect.ImmutableListMultimap)6 ImmutableSet (com.google.common.collect.ImmutableSet)6 ListMultimap (com.google.common.collect.ListMultimap)6 IOException (java.io.IOException)6 Files (java.nio.file.Files)6 Path (java.nio.file.Path)6 Paths (java.nio.file.Paths)6 HashSet (java.util.HashSet)6 Optional (java.util.Optional)6 Set (java.util.Set)6