Search in sources :

Example 1 with DockerDaemonImage

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

the class PluginConfigurationProcessor method getJavaContainerBuilderWithBaseImage.

/**
 * Returns a {@link JavaContainerBuilder} with the correctly parsed base image configuration.
 *
 * @param rawConfiguration contains the base image configuration
 * @param projectProperties used for providing additional information
 * @param inferredAuthProvider provides inferred auths for registry images
 * @return a new {@link JavaContainerBuilder} with the configured base image
 * @throws IncompatibleBaseImageJavaVersionException when the Java version in the base image is
 *     incompatible with the Java version of the application to be containerized
 * @throws InvalidImageReferenceException if the base image configuration can't be parsed
 * @throws FileNotFoundException if a credential helper can't be found
 */
@VisibleForTesting
static JavaContainerBuilder getJavaContainerBuilderWithBaseImage(RawConfiguration rawConfiguration, ProjectProperties projectProperties, InferredAuthProvider inferredAuthProvider) throws IncompatibleBaseImageJavaVersionException, InvalidImageReferenceException, FileNotFoundException {
    // Use image configuration as-is if it's a local base image
    Optional<String> image = rawConfiguration.getFromImage();
    String baseImageConfig = image.isPresent() ? image.get() : getDefaultBaseImage(projectProperties);
    if (baseImageConfig.startsWith(Jib.TAR_IMAGE_PREFIX)) {
        return JavaContainerBuilder.from(baseImageConfig);
    }
    // Verify Java version is compatible
    List<String> splits = Splitter.on("://").splitToList(baseImageConfig);
    String prefixRemoved = splits.get(splits.size() - 1);
    int javaVersion = projectProperties.getMajorJavaVersion();
    if (isKnownJava8Image(prefixRemoved) && javaVersion > 8) {
        throw new IncompatibleBaseImageJavaVersionException(8, javaVersion);
    }
    if (isKnownJava11Image(prefixRemoved) && javaVersion > 11) {
        throw new IncompatibleBaseImageJavaVersionException(11, javaVersion);
    }
    if (isKnownJava17Image(prefixRemoved) && javaVersion > 17) {
        throw new IncompatibleBaseImageJavaVersionException(17, javaVersion);
    }
    ImageReference baseImageReference = ImageReference.parse(prefixRemoved);
    if (baseImageConfig.startsWith(Jib.DOCKER_DAEMON_IMAGE_PREFIX)) {
        DockerDaemonImage dockerDaemonImage = DockerDaemonImage.named(baseImageReference).setDockerEnvironment(rawConfiguration.getDockerEnvironment());
        Optional<Path> dockerExecutable = rawConfiguration.getDockerExecutable();
        if (dockerExecutable.isPresent()) {
            dockerDaemonImage.setDockerExecutable(dockerExecutable.get());
        }
        return JavaContainerBuilder.from(dockerDaemonImage);
    }
    RegistryImage baseImage = RegistryImage.named(baseImageReference);
    configureCredentialRetrievers(rawConfiguration, projectProperties, baseImage, baseImageReference, PropertyNames.FROM_AUTH_USERNAME, PropertyNames.FROM_AUTH_PASSWORD, rawConfiguration.getFromAuth(), inferredAuthProvider, rawConfiguration.getFromCredHelper());
    return JavaContainerBuilder.from(baseImage);
}
Also used : Path(java.nio.file.Path) AbsoluteUnixPath(com.google.cloud.tools.jib.api.buildplan.AbsoluteUnixPath) ImageReference(com.google.cloud.tools.jib.api.ImageReference) DockerDaemonImage(com.google.cloud.tools.jib.api.DockerDaemonImage) RegistryImage(com.google.cloud.tools.jib.api.RegistryImage) VisibleForTesting(com.google.common.annotations.VisibleForTesting)

Example 2 with DockerDaemonImage

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

the class DockerConfiguration method toImage.

public DockerDaemonImage toImage(final String toConnectorsImage) throws InvalidImageReferenceException {
    final DockerDaemonImage docker = DockerDaemonImage.named(toConnectorsImage);
    environment().ifPresent(docker::setDockerEnvironment);
    ofNullable(path).ifPresent(p -> docker.setDockerExecutable(PathFactory.get(p)));
    return docker;
}
Also used : DockerDaemonImage(com.google.cloud.tools.jib.api.DockerDaemonImage)

Example 3 with DockerDaemonImage

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

the class JibHelper method toLocalDocker.

public void toLocalDocker(final ExecutorService executor, final JibContainerBuilder builder, final String tag, final String imageName, final String toolName) throws InvalidImageReferenceException, InterruptedException, ExecutionException, IOException, CacheDirectoryCreationException, RegistryException {
    final DockerDaemonImage docker = DockerDaemonImage.named(imageName);
    if (dockerEnvironment != null) {
        docker.setDockerEnvironment(dockerEnvironment);
    }
    if (dockerExecutable != null) {
        docker.setDockerExecutable(dockerExecutable.toPath());
    }
    builder.containerize(configureContainer(Containerizer.to(docker), executor, toolName));
    log.info("Built local image='" + imageName + "', tag='" + tag + "'");
}
Also used : DockerDaemonImage(com.google.cloud.tools.jib.api.DockerDaemonImage)

Example 4 with DockerDaemonImage

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

the class PluginConfigurationProcessor method createJibBuildRunnerForDockerDaemonImage.

/**
 * Generate a runner for image builds to docker daemon.
 *
 * @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 createJibBuildRunnerForDockerDaemonImage(RawConfiguration rawConfiguration, InferredAuthProvider inferredAuthProvider, ProjectProperties projectProperties, GlobalConfig globalConfig, HelpfulSuggestions helpfulSuggestions) throws InvalidImageReferenceException, MainClassInferenceException, InvalidAppRootException, IOException, InvalidWorkingDirectoryException, InvalidPlatformException, InvalidContainerVolumeException, IncompatibleBaseImageJavaVersionException, NumberFormatException, InvalidContainerizingModeException, InvalidFilesModificationTimeException, InvalidCreationTimeException, ExtraDirectoryNotFoundException, JibPluginExtensionException {
    ImageReference targetImageReference = getGeneratedTargetDockerTag(rawConfiguration, projectProperties, helpfulSuggestions);
    DockerDaemonImage targetImage = DockerDaemonImage.named(targetImageReference);
    Optional<Path> dockerExecutable = rawConfiguration.getDockerExecutable();
    if (dockerExecutable.isPresent()) {
        targetImage.setDockerExecutable(dockerExecutable.get());
    }
    targetImage.setDockerEnvironment(rawConfiguration.getDockerEnvironment());
    Containerizer containerizer = Containerizer.to(targetImage);
    Multimaps.asMap(globalConfig.getRegistryMirrors()).forEach(containerizer::addRegistryMirrors);
    JibContainerBuilder jibContainerBuilder = processCommonConfiguration(rawConfiguration, inferredAuthProvider, projectProperties, containerizer);
    JibContainerBuilder updatedContainerBuilder = projectProperties.runPluginExtensions(rawConfiguration.getPluginExtensions(), jibContainerBuilder).setFormat(ImageFormat.Docker);
    return JibBuildRunner.forBuildToDockerDaemon(updatedContainerBuilder, containerizer, projectProperties::log, helpfulSuggestions, targetImageReference, rawConfiguration.getToTags()).writeImageDigest(rawConfiguration.getDigestOutputPath()).writeImageId(rawConfiguration.getImageIdOutputPath()).writeImageJson(rawConfiguration.getImageJsonOutputPath());
}
Also used : Path(java.nio.file.Path) AbsoluteUnixPath(com.google.cloud.tools.jib.api.buildplan.AbsoluteUnixPath) ImageReference(com.google.cloud.tools.jib.api.ImageReference) Containerizer(com.google.cloud.tools.jib.api.Containerizer) DockerDaemonImage(com.google.cloud.tools.jib.api.DockerDaemonImage) JibContainerBuilder(com.google.cloud.tools.jib.api.JibContainerBuilder)

Example 5 with DockerDaemonImage

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

the class PluginConfigurationProcessor method createJibBuildRunnerForDockerDaemonImage.

/**
 * Generate a runner for image builds to docker daemon.
 *
 * @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 createJibBuildRunnerForDockerDaemonImage(RawConfiguration rawConfiguration, InferredAuthProvider inferredAuthProvider, ProjectProperties projectProperties, GlobalConfig globalConfig, HelpfulSuggestions helpfulSuggestions) throws InvalidImageReferenceException, MainClassInferenceException, InvalidAppRootException, IOException, InvalidWorkingDirectoryException, InvalidPlatformException, InvalidContainerVolumeException, IncompatibleBaseImageJavaVersionException, NumberFormatException, InvalidContainerizingModeException, InvalidFilesModificationTimeException, InvalidCreationTimeException, ExtraDirectoryNotFoundException, JibPluginExtensionException {
    ImageReference targetImageReference = getGeneratedTargetDockerTag(rawConfiguration, projectProperties, helpfulSuggestions);
    DockerDaemonImage targetImage = DockerDaemonImage.named(targetImageReference);
    Optional<Path> dockerExecutable = rawConfiguration.getDockerExecutable();
    if (dockerExecutable.isPresent()) {
        targetImage.setDockerExecutable(dockerExecutable.get());
    }
    targetImage.setDockerEnvironment(rawConfiguration.getDockerEnvironment());
    Containerizer containerizer = Containerizer.to(targetImage);
    Multimaps.asMap(globalConfig.getRegistryMirrors()).forEach(containerizer::addRegistryMirrors);
    JibContainerBuilder jibContainerBuilder = processCommonConfiguration(rawConfiguration, inferredAuthProvider, projectProperties, containerizer);
    JibContainerBuilder updatedContainerBuilder = projectProperties.runPluginExtensions(rawConfiguration.getPluginExtensions(), jibContainerBuilder).setFormat(ImageFormat.Docker);
    return JibBuildRunner.forBuildToDockerDaemon(updatedContainerBuilder, containerizer, projectProperties::log, helpfulSuggestions, targetImageReference, rawConfiguration.getToTags()).writeImageDigest(rawConfiguration.getDigestOutputPath()).writeImageId(rawConfiguration.getImageIdOutputPath()).writeImageJson(rawConfiguration.getImageJsonOutputPath());
}
Also used : Path(java.nio.file.Path) AbsoluteUnixPath(com.google.cloud.tools.jib.api.buildplan.AbsoluteUnixPath) ImageReference(com.google.cloud.tools.jib.api.ImageReference) Containerizer(com.google.cloud.tools.jib.api.Containerizer) DockerDaemonImage(com.google.cloud.tools.jib.api.DockerDaemonImage) JibContainerBuilder(com.google.cloud.tools.jib.api.JibContainerBuilder)

Aggregations

DockerDaemonImage (com.google.cloud.tools.jib.api.DockerDaemonImage)7 ImageReference (com.google.cloud.tools.jib.api.ImageReference)5 AbsoluteUnixPath (com.google.cloud.tools.jib.api.buildplan.AbsoluteUnixPath)4 Path (java.nio.file.Path)4 Containerizer (com.google.cloud.tools.jib.api.Containerizer)3 RegistryImage (com.google.cloud.tools.jib.api.RegistryImage)3 JibContainerBuilder (com.google.cloud.tools.jib.api.JibContainerBuilder)2 VisibleForTesting (com.google.common.annotations.VisibleForTesting)2