Search in sources :

Example 1 with PlatformConfiguration

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

the class PluginConfigurationProcessor method getSkaffoldSyncMap.

/**
 * Generate a skaffold syncmap JSON string for an image build configuration.
 *
 * @param rawConfiguration the raw configuration from the plugin
 * @param projectProperties an plugin specific implementation of {@link ProjectProperties}
 * @param excludes a set of paths to exclude, directories include in this list will be expanded
 * @return new json string representation of the Sync Map
 * @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 ExtraDirectoryNotFoundException if the extra directory specified for the build is not
 *     found
 */
public static String getSkaffoldSyncMap(RawConfiguration rawConfiguration, ProjectProperties projectProperties, Set<Path> excludes) throws IOException, InvalidCreationTimeException, InvalidImageReferenceException, IncompatibleBaseImageJavaVersionException, InvalidPlatformException, InvalidContainerVolumeException, MainClassInferenceException, InvalidAppRootException, InvalidWorkingDirectoryException, InvalidFilesModificationTimeException, InvalidContainerizingModeException, ExtraDirectoryNotFoundException {
    JibContainerBuilder jibContainerBuilder = processCommonConfiguration(rawConfiguration, ignored -> Optional.empty(), projectProperties);
    SkaffoldSyncMapTemplate syncMap = new SkaffoldSyncMapTemplate();
    // since jib has already expanded out directories after processing everything, we just
    // ignore directories and provide only files to watch
    Set<Path> excludesExpanded = getAllFiles(excludes);
    for (LayerObject layerObject : jibContainerBuilder.toContainerBuildPlan().getLayers()) {
        Verify.verify(layerObject instanceof FileEntriesLayer, "layer types other than FileEntriesLayer not yet supported in build plan layers");
        FileEntriesLayer layer = (FileEntriesLayer) layerObject;
        if (CONST_LAYERS.contains(layer.getName())) {
            continue;
        }
        if (GENERATED_LAYERS.contains(layer.getName())) {
            layer.getEntries().stream().filter(layerEntry -> Files.isRegularFile(layerEntry.getSourceFile())).filter(layerEntry -> !excludesExpanded.contains(layerEntry.getSourceFile().toAbsolutePath())).forEach(syncMap::addGenerated);
        } else {
            // this is a direct layer
            layer.getEntries().stream().filter(layerEntry -> Files.isRegularFile(layerEntry.getSourceFile())).filter(layerEntry -> !excludesExpanded.contains(layerEntry.getSourceFile().toAbsolutePath())).forEach(syncMap::addDirect);
        }
    }
    return syncMap.getJsonString();
}
Also used : Path(java.nio.file.Path) AbsoluteUnixPath(com.google.cloud.tools.jib.api.buildplan.AbsoluteUnixPath) CredHelperConfiguration(com.google.cloud.tools.jib.plugins.common.RawConfiguration.CredHelperConfiguration) Arrays(java.util.Arrays) ImageReference(com.google.cloud.tools.jib.api.ImageReference) PlatformConfiguration(com.google.cloud.tools.jib.plugins.common.RawConfiguration.PlatformConfiguration) JavaContainerBuilder(com.google.cloud.tools.jib.api.JavaContainerBuilder) ExtraDirectoriesConfiguration(com.google.cloud.tools.jib.plugins.common.RawConfiguration.ExtraDirectoriesConfiguration) Credential(com.google.cloud.tools.jib.api.Credential) LayerType(com.google.cloud.tools.jib.api.JavaContainerBuilder.LayerType) Map(java.util.Map) Splitter(com.google.common.base.Splitter) Path(java.nio.file.Path) AbsoluteUnixPath(com.google.cloud.tools.jib.api.buildplan.AbsoluteUnixPath) Verify(com.google.common.base.Verify) GlobalConfig(com.google.cloud.tools.jib.plugins.common.globalconfig.GlobalConfig) Set(java.util.Set) InvalidImageReferenceException(com.google.cloud.tools.jib.api.InvalidImageReferenceException) Instant(java.time.Instant) Collectors(java.util.stream.Collectors) FileNotFoundException(java.io.FileNotFoundException) StandardCharsets(java.nio.charset.StandardCharsets) DateTimeParseException(java.time.format.DateTimeParseException) List(java.util.List) LayerObject(com.google.cloud.tools.jib.api.buildplan.LayerObject) Stream(java.util.stream.Stream) ImageFormat(com.google.cloud.tools.jib.api.buildplan.ImageFormat) JibSystemProperties(com.google.cloud.tools.jib.global.JibSystemProperties) Optional(java.util.Optional) Platform(com.google.cloud.tools.jib.api.buildplan.Platform) DateTimeFormatterBuilder(java.time.format.DateTimeFormatterBuilder) Ports(com.google.cloud.tools.jib.api.Ports) DockerDaemonImage(com.google.cloud.tools.jib.api.DockerDaemonImage) JibContainerBuilder(com.google.cloud.tools.jib.api.JibContainerBuilder) RegistryImage(com.google.cloud.tools.jib.api.RegistryImage) FileEntriesLayer(com.google.cloud.tools.jib.api.buildplan.FileEntriesLayer) JibPluginExtensionException(com.google.cloud.tools.jib.plugins.extension.JibPluginExtensionException) Multimaps(com.google.common.collect.Multimaps) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) Jib(com.google.cloud.tools.jib.api.Jib) ImmutableList(com.google.common.collect.ImmutableList) CredentialRetrieverFactory(com.google.cloud.tools.jib.frontend.CredentialRetrieverFactory) LinkedHashSet(java.util.LinkedHashSet) Nullable(javax.annotation.Nullable) Files(java.nio.file.Files) TarImage(com.google.cloud.tools.jib.api.TarImage) IOException(java.io.IOException) ModificationTimeProvider(com.google.cloud.tools.jib.api.buildplan.ModificationTimeProvider) LogEvent(com.google.cloud.tools.jib.api.LogEvent) Containerizer(com.google.cloud.tools.jib.api.Containerizer) Paths(java.nio.file.Paths) DateTimeFormatter(java.time.format.DateTimeFormatter) Preconditions(com.google.common.base.Preconditions) VisibleForTesting(com.google.common.annotations.VisibleForTesting) LayerObject(com.google.cloud.tools.jib.api.buildplan.LayerObject) FileEntriesLayer(com.google.cloud.tools.jib.api.buildplan.FileEntriesLayer) JibContainerBuilder(com.google.cloud.tools.jib.api.JibContainerBuilder)

Example 2 with PlatformConfiguration

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

the class PluginConfigurationProcessor method getPlatformsSet.

/**
 * Parses the list of platforms to a set of {@link Platform}.
 *
 * @param rawConfiguration raw configuration data
 * @return the set of parsed platforms
 * @throws InvalidPlatformException if there exists a {@link PlatformConfiguration} in the
 *     specified platforms list that is missing required fields or has invalid values
 */
@VisibleForTesting
static Set<Platform> getPlatformsSet(RawConfiguration rawConfiguration) throws InvalidPlatformException {
    Set<Platform> platforms = new LinkedHashSet<>();
    for (PlatformConfiguration platformConfiguration : rawConfiguration.getPlatforms()) {
        Optional<String> architecture = platformConfiguration.getArchitectureName();
        Optional<String> os = platformConfiguration.getOsName();
        String platformToString = "architecture=" + architecture.orElse("<missing>") + ", os=" + os.orElse("<missing>");
        if (!architecture.isPresent()) {
            throw new InvalidPlatformException("platform configuration is missing an architecture value", platformToString);
        }
        if (!os.isPresent()) {
            throw new InvalidPlatformException("platform configuration is missing an OS value", platformToString);
        }
        platforms.add(new Platform(architecture.get(), os.get()));
    }
    return platforms;
}
Also used : LinkedHashSet(java.util.LinkedHashSet) PlatformConfiguration(com.google.cloud.tools.jib.plugins.common.RawConfiguration.PlatformConfiguration) Platform(com.google.cloud.tools.jib.api.buildplan.Platform) VisibleForTesting(com.google.common.annotations.VisibleForTesting)

Example 3 with PlatformConfiguration

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

the class PluginConfigurationProcessor method getPlatformsSet.

/**
 * Parses the list of platforms to a set of {@link Platform}.
 *
 * @param rawConfiguration raw configuration data
 * @return the set of parsed platforms
 * @throws InvalidPlatformException if there exists a {@link PlatformConfiguration} in the
 *     specified platforms list that is missing required fields or has invalid values
 */
@VisibleForTesting
static Set<Platform> getPlatformsSet(RawConfiguration rawConfiguration) throws InvalidPlatformException {
    Set<Platform> platforms = new LinkedHashSet<>();
    for (PlatformConfiguration platformConfiguration : rawConfiguration.getPlatforms()) {
        Optional<String> architecture = platformConfiguration.getArchitectureName();
        Optional<String> os = platformConfiguration.getOsName();
        String platformToString = "architecture=" + architecture.orElse("<missing>") + ", os=" + os.orElse("<missing>");
        if (!architecture.isPresent()) {
            throw new InvalidPlatformException("platform configuration is missing an architecture value", platformToString);
        }
        if (!os.isPresent()) {
            throw new InvalidPlatformException("platform configuration is missing an OS value", platformToString);
        }
        platforms.add(new Platform(architecture.get(), os.get()));
    }
    return platforms;
}
Also used : LinkedHashSet(java.util.LinkedHashSet) PlatformConfiguration(com.google.cloud.tools.jib.plugins.common.RawConfiguration.PlatformConfiguration) Platform(com.google.cloud.tools.jib.api.buildplan.Platform) VisibleForTesting(com.google.common.annotations.VisibleForTesting)

Example 4 with PlatformConfiguration

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

the class PluginConfigurationProcessor method getSkaffoldSyncMap.

/**
 * Generate a skaffold syncmap JSON string for an image build configuration.
 *
 * @param rawConfiguration the raw configuration from the plugin
 * @param projectProperties an plugin specific implementation of {@link ProjectProperties}
 * @param excludes a set of paths to exclude, directories include in this list will be expanded
 * @return new json string representation of the Sync Map
 * @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 ExtraDirectoryNotFoundException if the extra directory specified for the build is not
 *     found
 */
public static String getSkaffoldSyncMap(RawConfiguration rawConfiguration, ProjectProperties projectProperties, Set<Path> excludes) throws IOException, InvalidCreationTimeException, InvalidImageReferenceException, IncompatibleBaseImageJavaVersionException, InvalidPlatformException, InvalidContainerVolumeException, MainClassInferenceException, InvalidAppRootException, InvalidWorkingDirectoryException, InvalidFilesModificationTimeException, InvalidContainerizingModeException, ExtraDirectoryNotFoundException {
    JibContainerBuilder jibContainerBuilder = processCommonConfiguration(rawConfiguration, ignored -> Optional.empty(), projectProperties);
    SkaffoldSyncMapTemplate syncMap = new SkaffoldSyncMapTemplate();
    // since jib has already expanded out directories after processing everything, we just
    // ignore directories and provide only files to watch
    Set<Path> excludesExpanded = getAllFiles(excludes);
    for (LayerObject layerObject : jibContainerBuilder.toContainerBuildPlan().getLayers()) {
        Verify.verify(layerObject instanceof FileEntriesLayer, "layer types other than FileEntriesLayer not yet supported in build plan layers");
        FileEntriesLayer layer = (FileEntriesLayer) layerObject;
        if (CONST_LAYERS.contains(layer.getName())) {
            continue;
        }
        if (GENERATED_LAYERS.contains(layer.getName())) {
            layer.getEntries().stream().filter(layerEntry -> Files.isRegularFile(layerEntry.getSourceFile())).filter(layerEntry -> !excludesExpanded.contains(layerEntry.getSourceFile().toAbsolutePath())).forEach(syncMap::addGenerated);
        } else {
            // this is a direct layer
            layer.getEntries().stream().filter(layerEntry -> Files.isRegularFile(layerEntry.getSourceFile())).filter(layerEntry -> !excludesExpanded.contains(layerEntry.getSourceFile().toAbsolutePath())).forEach(syncMap::addDirect);
        }
    }
    return syncMap.getJsonString();
}
Also used : Path(java.nio.file.Path) AbsoluteUnixPath(com.google.cloud.tools.jib.api.buildplan.AbsoluteUnixPath) CredHelperConfiguration(com.google.cloud.tools.jib.plugins.common.RawConfiguration.CredHelperConfiguration) Arrays(java.util.Arrays) ImageReference(com.google.cloud.tools.jib.api.ImageReference) PlatformConfiguration(com.google.cloud.tools.jib.plugins.common.RawConfiguration.PlatformConfiguration) JavaContainerBuilder(com.google.cloud.tools.jib.api.JavaContainerBuilder) ExtraDirectoriesConfiguration(com.google.cloud.tools.jib.plugins.common.RawConfiguration.ExtraDirectoriesConfiguration) Credential(com.google.cloud.tools.jib.api.Credential) LayerType(com.google.cloud.tools.jib.api.JavaContainerBuilder.LayerType) Map(java.util.Map) Splitter(com.google.common.base.Splitter) Path(java.nio.file.Path) AbsoluteUnixPath(com.google.cloud.tools.jib.api.buildplan.AbsoluteUnixPath) Verify(com.google.common.base.Verify) GlobalConfig(com.google.cloud.tools.jib.plugins.common.globalconfig.GlobalConfig) Set(java.util.Set) InvalidImageReferenceException(com.google.cloud.tools.jib.api.InvalidImageReferenceException) Instant(java.time.Instant) Collectors(java.util.stream.Collectors) FileNotFoundException(java.io.FileNotFoundException) StandardCharsets(java.nio.charset.StandardCharsets) DateTimeParseException(java.time.format.DateTimeParseException) List(java.util.List) LayerObject(com.google.cloud.tools.jib.api.buildplan.LayerObject) Stream(java.util.stream.Stream) ImageFormat(com.google.cloud.tools.jib.api.buildplan.ImageFormat) JibSystemProperties(com.google.cloud.tools.jib.global.JibSystemProperties) Optional(java.util.Optional) Platform(com.google.cloud.tools.jib.api.buildplan.Platform) DateTimeFormatterBuilder(java.time.format.DateTimeFormatterBuilder) Ports(com.google.cloud.tools.jib.api.Ports) DockerDaemonImage(com.google.cloud.tools.jib.api.DockerDaemonImage) JibContainerBuilder(com.google.cloud.tools.jib.api.JibContainerBuilder) RegistryImage(com.google.cloud.tools.jib.api.RegistryImage) FileEntriesLayer(com.google.cloud.tools.jib.api.buildplan.FileEntriesLayer) JibPluginExtensionException(com.google.cloud.tools.jib.plugins.extension.JibPluginExtensionException) Multimaps(com.google.common.collect.Multimaps) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) Jib(com.google.cloud.tools.jib.api.Jib) ImmutableList(com.google.common.collect.ImmutableList) CredentialRetrieverFactory(com.google.cloud.tools.jib.frontend.CredentialRetrieverFactory) LinkedHashSet(java.util.LinkedHashSet) Nullable(javax.annotation.Nullable) Files(java.nio.file.Files) TarImage(com.google.cloud.tools.jib.api.TarImage) IOException(java.io.IOException) ModificationTimeProvider(com.google.cloud.tools.jib.api.buildplan.ModificationTimeProvider) LogEvent(com.google.cloud.tools.jib.api.LogEvent) Containerizer(com.google.cloud.tools.jib.api.Containerizer) Paths(java.nio.file.Paths) DateTimeFormatter(java.time.format.DateTimeFormatter) Preconditions(com.google.common.base.Preconditions) VisibleForTesting(com.google.common.annotations.VisibleForTesting) LayerObject(com.google.cloud.tools.jib.api.buildplan.LayerObject) FileEntriesLayer(com.google.cloud.tools.jib.api.buildplan.FileEntriesLayer) JibContainerBuilder(com.google.cloud.tools.jib.api.JibContainerBuilder)

Aggregations

Platform (com.google.cloud.tools.jib.api.buildplan.Platform)4 PlatformConfiguration (com.google.cloud.tools.jib.plugins.common.RawConfiguration.PlatformConfiguration)4 VisibleForTesting (com.google.common.annotations.VisibleForTesting)4 LinkedHashSet (java.util.LinkedHashSet)4 Containerizer (com.google.cloud.tools.jib.api.Containerizer)2 Credential (com.google.cloud.tools.jib.api.Credential)2 DockerDaemonImage (com.google.cloud.tools.jib.api.DockerDaemonImage)2 ImageReference (com.google.cloud.tools.jib.api.ImageReference)2 InvalidImageReferenceException (com.google.cloud.tools.jib.api.InvalidImageReferenceException)2 JavaContainerBuilder (com.google.cloud.tools.jib.api.JavaContainerBuilder)2 LayerType (com.google.cloud.tools.jib.api.JavaContainerBuilder.LayerType)2 Jib (com.google.cloud.tools.jib.api.Jib)2 JibContainerBuilder (com.google.cloud.tools.jib.api.JibContainerBuilder)2 LogEvent (com.google.cloud.tools.jib.api.LogEvent)2 Ports (com.google.cloud.tools.jib.api.Ports)2 RegistryImage (com.google.cloud.tools.jib.api.RegistryImage)2 TarImage (com.google.cloud.tools.jib.api.TarImage)2 AbsoluteUnixPath (com.google.cloud.tools.jib.api.buildplan.AbsoluteUnixPath)2 FileEntriesLayer (com.google.cloud.tools.jib.api.buildplan.FileEntriesLayer)2 ImageFormat (com.google.cloud.tools.jib.api.buildplan.ImageFormat)2