Search in sources :

Example 1 with ExtraDirectoriesConfiguration

use of com.google.cloud.tools.jib.plugins.common.RawConfiguration.ExtraDirectoriesConfiguration in project jib by GoogleContainerTools.

the class PluginConfigurationProcessor method processCommonConfiguration.

@VisibleForTesting
static JibContainerBuilder processCommonConfiguration(RawConfiguration rawConfiguration, InferredAuthProvider inferredAuthProvider, ProjectProperties projectProperties) throws InvalidFilesModificationTimeException, InvalidAppRootException, IncompatibleBaseImageJavaVersionException, IOException, InvalidImageReferenceException, InvalidContainerizingModeException, MainClassInferenceException, InvalidPlatformException, InvalidContainerVolumeException, InvalidWorkingDirectoryException, InvalidCreationTimeException, ExtraDirectoryNotFoundException {
    // Create and configure JibContainerBuilder
    ModificationTimeProvider modificationTimeProvider = createModificationTimeProvider(rawConfiguration.getFilesModificationTime());
    JavaContainerBuilder javaContainerBuilder = getJavaContainerBuilderWithBaseImage(rawConfiguration, projectProperties, inferredAuthProvider).setAppRoot(getAppRootChecked(rawConfiguration, projectProperties)).setModificationTimeProvider(modificationTimeProvider);
    JibContainerBuilder jibContainerBuilder = projectProperties.createJibContainerBuilder(javaContainerBuilder, getContainerizingModeChecked(rawConfiguration, projectProperties));
    jibContainerBuilder.setFormat(rawConfiguration.getImageFormat()).setPlatforms(getPlatformsSet(rawConfiguration)).setEntrypoint(computeEntrypoint(rawConfiguration, projectProperties, jibContainerBuilder)).setProgramArguments(rawConfiguration.getProgramArguments().orElse(null)).setEnvironment(rawConfiguration.getEnvironment()).setExposedPorts(Ports.parse(rawConfiguration.getPorts())).setVolumes(getVolumesSet(rawConfiguration)).setLabels(rawConfiguration.getLabels()).setUser(rawConfiguration.getUser().orElse(null)).setCreationTime(getCreationTime(rawConfiguration.getCreationTime(), projectProperties));
    getWorkingDirectoryChecked(rawConfiguration).ifPresent(jibContainerBuilder::setWorkingDirectory);
    // Adds all the extra files.
    for (ExtraDirectoriesConfiguration extraDirectory : rawConfiguration.getExtraDirectories()) {
        Path from = extraDirectory.getFrom();
        if (Files.exists(from)) {
            jibContainerBuilder.addFileEntriesLayer(JavaContainerBuilderHelper.extraDirectoryLayerConfiguration(from, AbsoluteUnixPath.get(extraDirectory.getInto()), extraDirectory.getIncludesList(), extraDirectory.getExcludesList(), rawConfiguration.getExtraDirectoryPermissions(), modificationTimeProvider));
        } else if (!from.endsWith(DEFAULT_JIB_DIR)) {
            throw new ExtraDirectoryNotFoundException(from.toString(), from.toString());
        }
    }
    return jibContainerBuilder;
}
Also used : Path(java.nio.file.Path) AbsoluteUnixPath(com.google.cloud.tools.jib.api.buildplan.AbsoluteUnixPath) JavaContainerBuilder(com.google.cloud.tools.jib.api.JavaContainerBuilder) ModificationTimeProvider(com.google.cloud.tools.jib.api.buildplan.ModificationTimeProvider) JibContainerBuilder(com.google.cloud.tools.jib.api.JibContainerBuilder) ExtraDirectoriesConfiguration(com.google.cloud.tools.jib.plugins.common.RawConfiguration.ExtraDirectoriesConfiguration) VisibleForTesting(com.google.common.annotations.VisibleForTesting)

Example 2 with ExtraDirectoriesConfiguration

use of com.google.cloud.tools.jib.plugins.common.RawConfiguration.ExtraDirectoriesConfiguration in project jib by google.

the class PluginConfigurationProcessor method processCommonConfiguration.

@VisibleForTesting
static JibContainerBuilder processCommonConfiguration(RawConfiguration rawConfiguration, InferredAuthProvider inferredAuthProvider, ProjectProperties projectProperties) throws InvalidFilesModificationTimeException, InvalidAppRootException, IncompatibleBaseImageJavaVersionException, IOException, InvalidImageReferenceException, InvalidContainerizingModeException, MainClassInferenceException, InvalidPlatformException, InvalidContainerVolumeException, InvalidWorkingDirectoryException, InvalidCreationTimeException, ExtraDirectoryNotFoundException {
    // Create and configure JibContainerBuilder
    ModificationTimeProvider modificationTimeProvider = createModificationTimeProvider(rawConfiguration.getFilesModificationTime());
    JavaContainerBuilder javaContainerBuilder = getJavaContainerBuilderWithBaseImage(rawConfiguration, projectProperties, inferredAuthProvider).setAppRoot(getAppRootChecked(rawConfiguration, projectProperties)).setModificationTimeProvider(modificationTimeProvider);
    JibContainerBuilder jibContainerBuilder = projectProperties.createJibContainerBuilder(javaContainerBuilder, getContainerizingModeChecked(rawConfiguration, projectProperties));
    jibContainerBuilder.setFormat(rawConfiguration.getImageFormat()).setPlatforms(getPlatformsSet(rawConfiguration)).setEntrypoint(computeEntrypoint(rawConfiguration, projectProperties, jibContainerBuilder)).setProgramArguments(rawConfiguration.getProgramArguments().orElse(null)).setEnvironment(rawConfiguration.getEnvironment()).setExposedPorts(Ports.parse(rawConfiguration.getPorts())).setVolumes(getVolumesSet(rawConfiguration)).setLabels(rawConfiguration.getLabels()).setUser(rawConfiguration.getUser().orElse(null)).setCreationTime(getCreationTime(rawConfiguration.getCreationTime(), projectProperties));
    getWorkingDirectoryChecked(rawConfiguration).ifPresent(jibContainerBuilder::setWorkingDirectory);
    // Adds all the extra files.
    for (ExtraDirectoriesConfiguration extraDirectory : rawConfiguration.getExtraDirectories()) {
        Path from = extraDirectory.getFrom();
        if (Files.exists(from)) {
            jibContainerBuilder.addFileEntriesLayer(JavaContainerBuilderHelper.extraDirectoryLayerConfiguration(from, AbsoluteUnixPath.get(extraDirectory.getInto()), extraDirectory.getIncludesList(), extraDirectory.getExcludesList(), rawConfiguration.getExtraDirectoryPermissions(), modificationTimeProvider));
        } else if (!from.endsWith(DEFAULT_JIB_DIR)) {
            throw new ExtraDirectoryNotFoundException(from.toString(), from.toString());
        }
    }
    return jibContainerBuilder;
}
Also used : Path(java.nio.file.Path) AbsoluteUnixPath(com.google.cloud.tools.jib.api.buildplan.AbsoluteUnixPath) JavaContainerBuilder(com.google.cloud.tools.jib.api.JavaContainerBuilder) ModificationTimeProvider(com.google.cloud.tools.jib.api.buildplan.ModificationTimeProvider) JibContainerBuilder(com.google.cloud.tools.jib.api.JibContainerBuilder) ExtraDirectoriesConfiguration(com.google.cloud.tools.jib.plugins.common.RawConfiguration.ExtraDirectoriesConfiguration) VisibleForTesting(com.google.common.annotations.VisibleForTesting)

Aggregations

JavaContainerBuilder (com.google.cloud.tools.jib.api.JavaContainerBuilder)2 JibContainerBuilder (com.google.cloud.tools.jib.api.JibContainerBuilder)2 AbsoluteUnixPath (com.google.cloud.tools.jib.api.buildplan.AbsoluteUnixPath)2 ModificationTimeProvider (com.google.cloud.tools.jib.api.buildplan.ModificationTimeProvider)2 ExtraDirectoriesConfiguration (com.google.cloud.tools.jib.plugins.common.RawConfiguration.ExtraDirectoriesConfiguration)2 VisibleForTesting (com.google.common.annotations.VisibleForTesting)2 Path (java.nio.file.Path)2