Search in sources :

Example 1 with LockFile

use of com.google.cloud.tools.jib.filesystem.LockFile in project jib by google.

the class CacheStorageWriter method writeMetadata.

/**
 * Saves image metadata (a manifest list and a list of manifest/container configuration pairs) for
 * an image reference.
 *
 * @param imageReference the image reference to store the metadata for
 * @param metadata the image metadata
 */
void writeMetadata(ImageReference imageReference, ImageMetadataTemplate metadata) throws IOException {
    verifyImageMetadata(metadata);
    Path imageDirectory = cacheStorageFiles.getImageDirectory(imageReference);
    Files.createDirectories(imageDirectory);
    try (LockFile ignored = LockFile.lock(imageDirectory.resolve("lock"))) {
        writeJsonTemplate(metadata, imageDirectory.resolve("manifests_configs.json"));
    }
}
Also used : Path(java.nio.file.Path) LockFile(com.google.cloud.tools.jib.filesystem.LockFile)

Example 2 with LockFile

use of com.google.cloud.tools.jib.filesystem.LockFile in project jib by google.

the class CacheStorageReader method retrieveMetadata.

/**
 * Retrieves the cached image metadata (a manifest list and a list of manifest/container
 * configuration pairs) for an image reference.
 *
 * @param imageReference the image reference
 * @return the image metadata for the image reference, if found
 * @throws IOException if an I/O exception occurs
 * @throws CacheCorruptedException if the cache is corrupted
 */
Optional<ImageMetadataTemplate> retrieveMetadata(ImageReference imageReference) throws IOException, CacheCorruptedException {
    Path imageDirectory = cacheStorageFiles.getImageDirectory(imageReference);
    Path metadataPath = imageDirectory.resolve("manifests_configs.json");
    if (!Files.exists(metadataPath)) {
        return Optional.empty();
    }
    ImageMetadataTemplate metadata;
    try (LockFile ignored = LockFile.lock(imageDirectory.resolve("lock"))) {
        metadata = JsonTemplateMapper.readJsonFromFile(metadataPath, ImageMetadataTemplate.class);
    }
    verifyImageMetadata(metadata, imageDirectory);
    return Optional.of(metadata);
}
Also used : Path(java.nio.file.Path) LockFile(com.google.cloud.tools.jib.filesystem.LockFile) ImageMetadataTemplate(com.google.cloud.tools.jib.image.json.ImageMetadataTemplate)

Example 3 with LockFile

use of com.google.cloud.tools.jib.filesystem.LockFile in project jib by GoogleContainerTools.

the class CacheStorageReader method retrieveMetadata.

/**
 * Retrieves the cached image metadata (a manifest list and a list of manifest/container
 * configuration pairs) for an image reference.
 *
 * @param imageReference the image reference
 * @return the image metadata for the image reference, if found
 * @throws IOException if an I/O exception occurs
 * @throws CacheCorruptedException if the cache is corrupted
 */
Optional<ImageMetadataTemplate> retrieveMetadata(ImageReference imageReference) throws IOException, CacheCorruptedException {
    Path imageDirectory = cacheStorageFiles.getImageDirectory(imageReference);
    Path metadataPath = imageDirectory.resolve("manifests_configs.json");
    if (!Files.exists(metadataPath)) {
        return Optional.empty();
    }
    ImageMetadataTemplate metadata;
    try (LockFile ignored = LockFile.lock(imageDirectory.resolve("lock"))) {
        metadata = JsonTemplateMapper.readJsonFromFile(metadataPath, ImageMetadataTemplate.class);
    }
    verifyImageMetadata(metadata, imageDirectory);
    return Optional.of(metadata);
}
Also used : Path(java.nio.file.Path) LockFile(com.google.cloud.tools.jib.filesystem.LockFile) ImageMetadataTemplate(com.google.cloud.tools.jib.image.json.ImageMetadataTemplate)

Example 4 with LockFile

use of com.google.cloud.tools.jib.filesystem.LockFile in project jib by GoogleContainerTools.

the class CacheStorageWriter method writeMetadata.

/**
 * Saves image metadata (a manifest list and a list of manifest/container configuration pairs) for
 * an image reference.
 *
 * @param imageReference the image reference to store the metadata for
 * @param metadata the image metadata
 */
void writeMetadata(ImageReference imageReference, ImageMetadataTemplate metadata) throws IOException {
    verifyImageMetadata(metadata);
    Path imageDirectory = cacheStorageFiles.getImageDirectory(imageReference);
    Files.createDirectories(imageDirectory);
    try (LockFile ignored = LockFile.lock(imageDirectory.resolve("lock"))) {
        writeJsonTemplate(metadata, imageDirectory.resolve("manifests_configs.json"));
    }
}
Also used : Path(java.nio.file.Path) LockFile(com.google.cloud.tools.jib.filesystem.LockFile)

Aggregations

LockFile (com.google.cloud.tools.jib.filesystem.LockFile)4 Path (java.nio.file.Path)4 ImageMetadataTemplate (com.google.cloud.tools.jib.image.json.ImageMetadataTemplate)2