Search in sources :

Example 6 with RegistryImage

use of com.google.cloud.tools.jib.api.RegistryImage in project component-runtime by Talend.

the class JibHelper method build.

public void build(final String toolName, final Supplier<Server> credentialsSupplier) throws InvalidImageReferenceException, InterruptedException, ExecutionException, IOException, CacheDirectoryCreationException, RegistryException, MojoExecutionException {
    if (builder == null) {
        throw new IllegalStateException("prepare had not been called");
    }
    if (repository != null) {
        // push
        final Server credentials = credentialsSupplier.get();
        if (laggyPushWorkaround > 0) {
            toLocalDocker(executor, builder, tag, imageName, toolName);
            hackyPush(tag, repository, imageName, credentials);
        } else {
            final RegistryImage registryImage = RegistryImage.named(imageName);
            if (credentials != null) {
                registryImage.addCredential(credentials.getUsername(), credentials.getPassword());
            }
            builder.containerize(configureContainer(Containerizer.to(registryImage), executor, "Talend Singer Maven Plugin"));
            log.info("Pushed image='" + imageName + "', tag='" + tag + "'");
        }
    } else {
        toLocalDocker(executor, builder, tag, imageName, toolName);
    }
}
Also used : Server(org.apache.maven.settings.Server) RegistryImage(com.google.cloud.tools.jib.api.RegistryImage)

Example 7 with RegistryImage

use of com.google.cloud.tools.jib.api.RegistryImage in project jib by google.

the class ContainerBuilders method create.

/**
 * Creates a {@link JibContainerBuilder} depending on the base image specified.
 *
 * @param baseImageReference base image reference
 * @param platforms platforms for multi-platform support in build command
 * @param commonCliOptions common cli options
 * @param logger console logger
 * @return a {@link JibContainerBuilder}
 * @throws InvalidImageReferenceException if the baseImage reference cannot be parsed
 * @throws FileNotFoundException if credential helper file cannot be found
 */
public static JibContainerBuilder create(String baseImageReference, Set<Platform> platforms, CommonCliOptions commonCliOptions, ConsoleLogger logger) throws InvalidImageReferenceException, FileNotFoundException {
    if (baseImageReference.startsWith(DOCKER_DAEMON_IMAGE_PREFIX)) {
        return Jib.from(DockerDaemonImage.named(baseImageReference.replaceFirst(DOCKER_DAEMON_IMAGE_PREFIX, "")));
    }
    if (baseImageReference.startsWith(TAR_IMAGE_PREFIX)) {
        return Jib.from(TarImage.at(Paths.get(baseImageReference.replaceFirst(TAR_IMAGE_PREFIX, ""))));
    }
    ImageReference imageReference = ImageReference.parse(baseImageReference.replaceFirst(REGISTRY_IMAGE_PREFIX, ""));
    RegistryImage registryImage = RegistryImage.named(imageReference);
    DefaultCredentialRetrievers defaultCredentialRetrievers = DefaultCredentialRetrievers.init(CredentialRetrieverFactory.forImage(imageReference, logEvent -> logger.log(logEvent.getLevel(), logEvent.getMessage())));
    Credentials.getFromCredentialRetrievers(commonCliOptions, defaultCredentialRetrievers).forEach(registryImage::addCredentialRetriever);
    JibContainerBuilder containerBuilder = Jib.from(registryImage);
    if (!platforms.isEmpty()) {
        containerBuilder.setPlatforms(platforms);
    }
    return containerBuilder;
}
Also used : DockerDaemonImage(com.google.cloud.tools.jib.api.DockerDaemonImage) ImageReference(com.google.cloud.tools.jib.api.ImageReference) JibContainerBuilder(com.google.cloud.tools.jib.api.JibContainerBuilder) TAR_IMAGE_PREFIX(com.google.cloud.tools.jib.api.Jib.TAR_IMAGE_PREFIX) RegistryImage(com.google.cloud.tools.jib.api.RegistryImage) Set(java.util.Set) TarImage(com.google.cloud.tools.jib.api.TarImage) DefaultCredentialRetrievers(com.google.cloud.tools.jib.plugins.common.DefaultCredentialRetrievers) DOCKER_DAEMON_IMAGE_PREFIX(com.google.cloud.tools.jib.api.Jib.DOCKER_DAEMON_IMAGE_PREFIX) InvalidImageReferenceException(com.google.cloud.tools.jib.api.InvalidImageReferenceException) FileNotFoundException(java.io.FileNotFoundException) REGISTRY_IMAGE_PREFIX(com.google.cloud.tools.jib.api.Jib.REGISTRY_IMAGE_PREFIX) Jib(com.google.cloud.tools.jib.api.Jib) Paths(java.nio.file.Paths) Platform(com.google.cloud.tools.jib.api.buildplan.Platform) CredentialRetrieverFactory(com.google.cloud.tools.jib.frontend.CredentialRetrieverFactory) ConsoleLogger(com.google.cloud.tools.jib.plugins.common.logging.ConsoleLogger) ImageReference(com.google.cloud.tools.jib.api.ImageReference) JibContainerBuilder(com.google.cloud.tools.jib.api.JibContainerBuilder) DefaultCredentialRetrievers(com.google.cloud.tools.jib.plugins.common.DefaultCredentialRetrievers) RegistryImage(com.google.cloud.tools.jib.api.RegistryImage)

Example 8 with RegistryImage

use of com.google.cloud.tools.jib.api.RegistryImage in project jib by google.

the class Containerizers method create.

private static Containerizer create(CommonCliOptions commonCliOptions, ConsoleLogger logger) throws InvalidImageReferenceException, FileNotFoundException {
    String imageSpec = commonCliOptions.getTargetImage();
    if (imageSpec.startsWith(DOCKER_DAEMON_IMAGE_PREFIX)) {
        // TODO: allow setting docker env and docker executable (along with path/env)
        return Containerizer.to(DockerDaemonImage.named(imageSpec.replaceFirst(DOCKER_DAEMON_IMAGE_PREFIX, "")));
    }
    if (imageSpec.startsWith(TAR_IMAGE_PREFIX)) {
        return Containerizer.to(TarImage.at(Paths.get(imageSpec.replaceFirst(TAR_IMAGE_PREFIX, ""))).named(commonCliOptions.getName()));
    }
    ImageReference imageReference = ImageReference.parse(imageSpec.replaceFirst(REGISTRY_IMAGE_PREFIX, ""));
    RegistryImage registryImage = RegistryImage.named(imageReference);
    DefaultCredentialRetrievers defaultCredentialRetrievers = DefaultCredentialRetrievers.init(CredentialRetrieverFactory.forImage(imageReference, logEvent -> logger.log(logEvent.getLevel(), logEvent.getMessage())));
    Credentials.getToCredentialRetrievers(commonCliOptions, defaultCredentialRetrievers).forEach(registryImage::addCredentialRetriever);
    return Containerizer.to(registryImage);
}
Also used : DockerDaemonImage(com.google.cloud.tools.jib.api.DockerDaemonImage) ImageReference(com.google.cloud.tools.jib.api.ImageReference) TAR_IMAGE_PREFIX(com.google.cloud.tools.jib.api.Jib.TAR_IMAGE_PREFIX) RegistryImage(com.google.cloud.tools.jib.api.RegistryImage) ProgressEvent(com.google.cloud.tools.jib.event.events.ProgressEvent) TarImage(com.google.cloud.tools.jib.api.TarImage) DefaultCredentialRetrievers(com.google.cloud.tools.jib.plugins.common.DefaultCredentialRetrievers) DOCKER_DAEMON_IMAGE_PREFIX(com.google.cloud.tools.jib.api.Jib.DOCKER_DAEMON_IMAGE_PREFIX) InvalidImageReferenceException(com.google.cloud.tools.jib.api.InvalidImageReferenceException) ProgressEventHandler(com.google.cloud.tools.jib.event.progress.ProgressEventHandler) FileNotFoundException(java.io.FileNotFoundException) REGISTRY_IMAGE_PREFIX(com.google.cloud.tools.jib.api.Jib.REGISTRY_IMAGE_PREFIX) LogEvent(com.google.cloud.tools.jib.api.LogEvent) List(java.util.List) Containerizer(com.google.cloud.tools.jib.api.Containerizer) Paths(java.nio.file.Paths) JibSystemProperties(com.google.cloud.tools.jib.global.JibSystemProperties) ProgressDisplayGenerator(com.google.cloud.tools.jib.plugins.common.logging.ProgressDisplayGenerator) CredentialRetrieverFactory(com.google.cloud.tools.jib.frontend.CredentialRetrieverFactory) ConsoleLogger(com.google.cloud.tools.jib.plugins.common.logging.ConsoleLogger) ImageReference(com.google.cloud.tools.jib.api.ImageReference) DefaultCredentialRetrievers(com.google.cloud.tools.jib.plugins.common.DefaultCredentialRetrievers) RegistryImage(com.google.cloud.tools.jib.api.RegistryImage)

Example 9 with RegistryImage

use of com.google.cloud.tools.jib.api.RegistryImage in project jib by google.

the class PluginConfigurationProcessor method createJibBuildRunnerForRegistryImage.

/**
 * Generate a runner for image builds to registries.
 *
 * @param rawConfiguration the raw configuration from the plugin
 * @param inferredAuthProvider the plugin specific auth provider
 * @param projectProperties an plugin specific implementation of {@link ProjectProperties}
 * @param globalConfig the Jib global config
 * @param helpfulSuggestions a plugin specific instance of {@link HelpfulSuggestions}
 * @return new {@link JibBuildRunner} to execute a build
 * @throws InvalidImageReferenceException if the image reference is invalid
 * @throws MainClassInferenceException if a main class could not be found
 * @throws InvalidAppRootException if the specific path for application root is invalid
 * @throws IOException if an error occurs creating the container builder
 * @throws InvalidWorkingDirectoryException if the working directory specified for the build is
 *     invalid
 * @throws InvalidPlatformException if there exists a {@link PlatformConfiguration} in the
 *     specified platforms list that is missing required fields or has invalid values
 * @throws InvalidContainerVolumeException if a specific container volume is invalid
 * @throws IncompatibleBaseImageJavaVersionException if the base image java version cannot support
 *     this build
 * @throws NumberFormatException if a string to number conversion operation fails
 * @throws InvalidContainerizingModeException if an invalid {@link ContainerizingMode} was
 *     specified
 * @throws InvalidFilesModificationTimeException if configured modification time could not be
 *     parsed
 * @throws InvalidCreationTimeException if configured creation time could not be parsed
 * @throws JibPluginExtensionException if an error occurred while running plugin extensions
 * @throws ExtraDirectoryNotFoundException if the extra directory specified for the build is not
 *     found
 */
public static JibBuildRunner createJibBuildRunnerForRegistryImage(RawConfiguration rawConfiguration, InferredAuthProvider inferredAuthProvider, ProjectProperties projectProperties, GlobalConfig globalConfig, HelpfulSuggestions helpfulSuggestions) throws InvalidImageReferenceException, MainClassInferenceException, InvalidAppRootException, IOException, InvalidWorkingDirectoryException, InvalidPlatformException, InvalidContainerVolumeException, IncompatibleBaseImageJavaVersionException, NumberFormatException, InvalidContainerizingModeException, InvalidFilesModificationTimeException, InvalidCreationTimeException, JibPluginExtensionException, ExtraDirectoryNotFoundException {
    Optional<String> image = rawConfiguration.getToImage();
    Preconditions.checkArgument(image.isPresent());
    ImageReference targetImageReference = ImageReference.parse(image.get());
    RegistryImage targetImage = RegistryImage.named(targetImageReference);
    configureCredentialRetrievers(rawConfiguration, projectProperties, targetImage, targetImageReference, PropertyNames.TO_AUTH_USERNAME, PropertyNames.TO_AUTH_PASSWORD, rawConfiguration.getToAuth(), inferredAuthProvider, rawConfiguration.getToCredHelper());
    boolean alwaysCacheBaseImage = Boolean.parseBoolean(rawConfiguration.getProperty(PropertyNames.ALWAYS_CACHE_BASE_IMAGE).orElse("false"));
    Containerizer containerizer = Containerizer.to(targetImage).setAlwaysCacheBaseImage(alwaysCacheBaseImage);
    Multimaps.asMap(globalConfig.getRegistryMirrors()).forEach(containerizer::addRegistryMirrors);
    JibContainerBuilder jibContainerBuilder = processCommonConfiguration(rawConfiguration, inferredAuthProvider, projectProperties, containerizer);
    JibContainerBuilder updatedContainerBuilder = projectProperties.runPluginExtensions(rawConfiguration.getPluginExtensions(), jibContainerBuilder);
    return JibBuildRunner.forBuildImage(updatedContainerBuilder, containerizer, projectProperties::log, helpfulSuggestions, targetImageReference, rawConfiguration.getToTags()).writeImageDigest(rawConfiguration.getDigestOutputPath()).writeImageId(rawConfiguration.getImageIdOutputPath()).writeImageJson(rawConfiguration.getImageJsonOutputPath());
}
Also used : ImageReference(com.google.cloud.tools.jib.api.ImageReference) Containerizer(com.google.cloud.tools.jib.api.Containerizer) JibContainerBuilder(com.google.cloud.tools.jib.api.JibContainerBuilder) RegistryImage(com.google.cloud.tools.jib.api.RegistryImage)

Example 10 with RegistryImage

use of com.google.cloud.tools.jib.api.RegistryImage in project jib by GoogleContainerTools.

the class ContainerBuilders method create.

/**
 * Creates a {@link JibContainerBuilder} depending on the base image specified.
 *
 * @param baseImageReference base image reference
 * @param platforms platforms for multi-platform support in build command
 * @param commonCliOptions common cli options
 * @param logger console logger
 * @return a {@link JibContainerBuilder}
 * @throws InvalidImageReferenceException if the baseImage reference cannot be parsed
 * @throws FileNotFoundException if credential helper file cannot be found
 */
public static JibContainerBuilder create(String baseImageReference, Set<Platform> platforms, CommonCliOptions commonCliOptions, ConsoleLogger logger) throws InvalidImageReferenceException, FileNotFoundException {
    if (baseImageReference.startsWith(DOCKER_DAEMON_IMAGE_PREFIX)) {
        return Jib.from(DockerDaemonImage.named(baseImageReference.replaceFirst(DOCKER_DAEMON_IMAGE_PREFIX, "")));
    }
    if (baseImageReference.startsWith(TAR_IMAGE_PREFIX)) {
        return Jib.from(TarImage.at(Paths.get(baseImageReference.replaceFirst(TAR_IMAGE_PREFIX, ""))));
    }
    ImageReference imageReference = ImageReference.parse(baseImageReference.replaceFirst(REGISTRY_IMAGE_PREFIX, ""));
    RegistryImage registryImage = RegistryImage.named(imageReference);
    DefaultCredentialRetrievers defaultCredentialRetrievers = DefaultCredentialRetrievers.init(CredentialRetrieverFactory.forImage(imageReference, logEvent -> logger.log(logEvent.getLevel(), logEvent.getMessage())));
    Credentials.getFromCredentialRetrievers(commonCliOptions, defaultCredentialRetrievers).forEach(registryImage::addCredentialRetriever);
    JibContainerBuilder containerBuilder = Jib.from(registryImage);
    if (!platforms.isEmpty()) {
        containerBuilder.setPlatforms(platforms);
    }
    return containerBuilder;
}
Also used : DockerDaemonImage(com.google.cloud.tools.jib.api.DockerDaemonImage) ImageReference(com.google.cloud.tools.jib.api.ImageReference) JibContainerBuilder(com.google.cloud.tools.jib.api.JibContainerBuilder) TAR_IMAGE_PREFIX(com.google.cloud.tools.jib.api.Jib.TAR_IMAGE_PREFIX) RegistryImage(com.google.cloud.tools.jib.api.RegistryImage) Set(java.util.Set) TarImage(com.google.cloud.tools.jib.api.TarImage) DefaultCredentialRetrievers(com.google.cloud.tools.jib.plugins.common.DefaultCredentialRetrievers) DOCKER_DAEMON_IMAGE_PREFIX(com.google.cloud.tools.jib.api.Jib.DOCKER_DAEMON_IMAGE_PREFIX) InvalidImageReferenceException(com.google.cloud.tools.jib.api.InvalidImageReferenceException) FileNotFoundException(java.io.FileNotFoundException) REGISTRY_IMAGE_PREFIX(com.google.cloud.tools.jib.api.Jib.REGISTRY_IMAGE_PREFIX) Jib(com.google.cloud.tools.jib.api.Jib) Paths(java.nio.file.Paths) Platform(com.google.cloud.tools.jib.api.buildplan.Platform) CredentialRetrieverFactory(com.google.cloud.tools.jib.frontend.CredentialRetrieverFactory) ConsoleLogger(com.google.cloud.tools.jib.plugins.common.logging.ConsoleLogger) ImageReference(com.google.cloud.tools.jib.api.ImageReference) JibContainerBuilder(com.google.cloud.tools.jib.api.JibContainerBuilder) DefaultCredentialRetrievers(com.google.cloud.tools.jib.plugins.common.DefaultCredentialRetrievers) RegistryImage(com.google.cloud.tools.jib.api.RegistryImage)

Aggregations

RegistryImage (com.google.cloud.tools.jib.api.RegistryImage)13 ImageReference (com.google.cloud.tools.jib.api.ImageReference)10 DockerDaemonImage (com.google.cloud.tools.jib.api.DockerDaemonImage)7 Containerizer (com.google.cloud.tools.jib.api.Containerizer)5 InvalidImageReferenceException (com.google.cloud.tools.jib.api.InvalidImageReferenceException)5 CredentialRetrieverFactory (com.google.cloud.tools.jib.frontend.CredentialRetrieverFactory)5 DOCKER_DAEMON_IMAGE_PREFIX (com.google.cloud.tools.jib.api.Jib.DOCKER_DAEMON_IMAGE_PREFIX)4 REGISTRY_IMAGE_PREFIX (com.google.cloud.tools.jib.api.Jib.REGISTRY_IMAGE_PREFIX)4 TAR_IMAGE_PREFIX (com.google.cloud.tools.jib.api.Jib.TAR_IMAGE_PREFIX)4 JibContainerBuilder (com.google.cloud.tools.jib.api.JibContainerBuilder)4 TarImage (com.google.cloud.tools.jib.api.TarImage)4 DefaultCredentialRetrievers (com.google.cloud.tools.jib.plugins.common.DefaultCredentialRetrievers)4 ConsoleLogger (com.google.cloud.tools.jib.plugins.common.logging.ConsoleLogger)4 FileNotFoundException (java.io.FileNotFoundException)4 Paths (java.nio.file.Paths)4 LogEvent (com.google.cloud.tools.jib.api.LogEvent)3 ProgressEvent (com.google.cloud.tools.jib.event.events.ProgressEvent)3 ProgressEventHandler (com.google.cloud.tools.jib.event.progress.ProgressEventHandler)3 Jib (com.google.cloud.tools.jib.api.Jib)2 AbsoluteUnixPath (com.google.cloud.tools.jib.api.buildplan.AbsoluteUnixPath)2