From 562e2b8d8034d12401fe1ecfb20614bfcd93d509 Mon Sep 17 00:00:00 2001 From: davidtron Date: Sat, 20 Mar 2021 21:09:59 +0000 Subject: [PATCH 01/15] #3158 - [Jib core] Tar archives with same contents are not reproducible --- .../cloud/tools/jib/tar/TarStreamBuilder.java | 3 +++ .../tools/jib/tar/TarStreamBuilderTest.java | 21 +++++++++++++++++++ 2 files changed, 24 insertions(+) diff --git a/jib-core/src/main/java/com/google/cloud/tools/jib/tar/TarStreamBuilder.java b/jib-core/src/main/java/com/google/cloud/tools/jib/tar/TarStreamBuilder.java index 006963ae02..f5559745e5 100644 --- a/jib-core/src/main/java/com/google/cloud/tools/jib/tar/TarStreamBuilder.java +++ b/jib-core/src/main/java/com/google/cloud/tools/jib/tar/TarStreamBuilder.java @@ -21,6 +21,7 @@ import java.io.IOException; import java.io.OutputStream; import java.nio.charset.StandardCharsets; +import java.time.Instant; import java.util.LinkedHashMap; import java.util.Map; import org.apache.commons.compress.archivers.tar.TarArchiveEntry; @@ -28,6 +29,7 @@ /** Builds a tarball archive. */ public class TarStreamBuilder { + public static final Instant DEFAULT_MODIFICATION_TIME = Instant.ofEpochSecond(1); /** * Maps from {@link TarArchiveEntry} to a {@link Blob}. The order of the entries is the order they @@ -89,6 +91,7 @@ public void addByteEntry(byte[] contents, String name) { public void addBlobEntry(Blob blob, long size, String name) { TarArchiveEntry entry = new TarArchiveEntry(name); entry.setSize(size); + entry.setModTime(DEFAULT_MODIFICATION_TIME.getEpochSecond()); archiveMap.put(entry, blob); } } diff --git a/jib-core/src/test/java/com/google/cloud/tools/jib/tar/TarStreamBuilderTest.java b/jib-core/src/test/java/com/google/cloud/tools/jib/tar/TarStreamBuilderTest.java index 6555c69c70..3675e540a3 100644 --- a/jib-core/src/test/java/com/google/cloud/tools/jib/tar/TarStreamBuilderTest.java +++ b/jib-core/src/test/java/com/google/cloud/tools/jib/tar/TarStreamBuilderTest.java @@ -29,6 +29,7 @@ import java.nio.file.Files; import java.nio.file.Path; import java.nio.file.Paths; +import java.util.Arrays; import java.util.zip.GZIPInputStream; import java.util.zip.GZIPOutputStream; import org.apache.commons.compress.archivers.tar.TarArchiveEntry; @@ -131,6 +132,26 @@ public void testToBlob_multiByte() throws IOException { Assert.assertNull(tarArchiveInputStream.getNextTarEntry()); } + @Test + public void testTarStreamAreReproducible() throws IOException, InterruptedException { + testTarStreamBuilder.addBlobEntry( + Blobs.from("jib"), "jib".getBytes(StandardCharsets.UTF_8).length, "jib"); + ByteArrayOutputStream firstTarByteOutputStream = new ByteArrayOutputStream(); + testTarStreamBuilder.writeAsTarArchiveTo(firstTarByteOutputStream); + + Thread.sleep(2000); + + TarStreamBuilder anotherTestTarStreamBuilder = new TarStreamBuilder(); + anotherTestTarStreamBuilder.addBlobEntry( + Blobs.from("jib"), "jib".getBytes(StandardCharsets.UTF_8).length, "jib"); + ByteArrayOutputStream secondTarByteOutputStream = new ByteArrayOutputStream(); + anotherTestTarStreamBuilder.writeAsTarArchiveTo(secondTarByteOutputStream); + + Assert.assertTrue( + Arrays.equals( + firstTarByteOutputStream.toByteArray(), secondTarByteOutputStream.toByteArray())); + } + /** Creates a TarStreamBuilder using TarArchiveEntries. */ private void setUpWithTarEntries() { // Prepares a test TarStreamBuilder. From f4d67574bfa60de16beba192a24d499fbacb783b Mon Sep 17 00:00:00 2001 From: davidtron Date: Thu, 8 Apr 2021 08:50:01 +0100 Subject: [PATCH 02/15] Revert "#3158 - [Jib core] Tar archives with same contents are not reproducible" This reverts commit 562e2b8d --- .../cloud/tools/jib/tar/TarStreamBuilder.java | 3 --- .../tools/jib/tar/TarStreamBuilderTest.java | 21 ------------------- 2 files changed, 24 deletions(-) diff --git a/jib-core/src/main/java/com/google/cloud/tools/jib/tar/TarStreamBuilder.java b/jib-core/src/main/java/com/google/cloud/tools/jib/tar/TarStreamBuilder.java index f5559745e5..006963ae02 100644 --- a/jib-core/src/main/java/com/google/cloud/tools/jib/tar/TarStreamBuilder.java +++ b/jib-core/src/main/java/com/google/cloud/tools/jib/tar/TarStreamBuilder.java @@ -21,7 +21,6 @@ import java.io.IOException; import java.io.OutputStream; import java.nio.charset.StandardCharsets; -import java.time.Instant; import java.util.LinkedHashMap; import java.util.Map; import org.apache.commons.compress.archivers.tar.TarArchiveEntry; @@ -29,7 +28,6 @@ /** Builds a tarball archive. */ public class TarStreamBuilder { - public static final Instant DEFAULT_MODIFICATION_TIME = Instant.ofEpochSecond(1); /** * Maps from {@link TarArchiveEntry} to a {@link Blob}. The order of the entries is the order they @@ -91,7 +89,6 @@ public void addByteEntry(byte[] contents, String name) { public void addBlobEntry(Blob blob, long size, String name) { TarArchiveEntry entry = new TarArchiveEntry(name); entry.setSize(size); - entry.setModTime(DEFAULT_MODIFICATION_TIME.getEpochSecond()); archiveMap.put(entry, blob); } } diff --git a/jib-core/src/test/java/com/google/cloud/tools/jib/tar/TarStreamBuilderTest.java b/jib-core/src/test/java/com/google/cloud/tools/jib/tar/TarStreamBuilderTest.java index 3675e540a3..6555c69c70 100644 --- a/jib-core/src/test/java/com/google/cloud/tools/jib/tar/TarStreamBuilderTest.java +++ b/jib-core/src/test/java/com/google/cloud/tools/jib/tar/TarStreamBuilderTest.java @@ -29,7 +29,6 @@ import java.nio.file.Files; import java.nio.file.Path; import java.nio.file.Paths; -import java.util.Arrays; import java.util.zip.GZIPInputStream; import java.util.zip.GZIPOutputStream; import org.apache.commons.compress.archivers.tar.TarArchiveEntry; @@ -132,26 +131,6 @@ public void testToBlob_multiByte() throws IOException { Assert.assertNull(tarArchiveInputStream.getNextTarEntry()); } - @Test - public void testTarStreamAreReproducible() throws IOException, InterruptedException { - testTarStreamBuilder.addBlobEntry( - Blobs.from("jib"), "jib".getBytes(StandardCharsets.UTF_8).length, "jib"); - ByteArrayOutputStream firstTarByteOutputStream = new ByteArrayOutputStream(); - testTarStreamBuilder.writeAsTarArchiveTo(firstTarByteOutputStream); - - Thread.sleep(2000); - - TarStreamBuilder anotherTestTarStreamBuilder = new TarStreamBuilder(); - anotherTestTarStreamBuilder.addBlobEntry( - Blobs.from("jib"), "jib".getBytes(StandardCharsets.UTF_8).length, "jib"); - ByteArrayOutputStream secondTarByteOutputStream = new ByteArrayOutputStream(); - anotherTestTarStreamBuilder.writeAsTarArchiveTo(secondTarByteOutputStream); - - Assert.assertTrue( - Arrays.equals( - firstTarByteOutputStream.toByteArray(), secondTarByteOutputStream.toByteArray())); - } - /** Creates a TarStreamBuilder using TarArchiveEntries. */ private void setUpWithTarEntries() { // Prepares a test TarStreamBuilder. From 438e2dca6b45fb91cdf92aab10f8d1f403dbd892 Mon Sep 17 00:00:00 2001 From: davidtron Date: Thu, 8 Apr 2021 09:52:37 +0100 Subject: [PATCH 03/15] #3158 - [Jib core] Tar archives with same contents are not reproducible --- .../cloud/tools/jib/image/ImageTarball.java | 26 +++++++++++++------ .../cloud/tools/jib/tar/TarStreamBuilder.java | 9 +++++-- .../tools/jib/tar/TarStreamBuilderTest.java | 21 +++++++++------ 3 files changed, 38 insertions(+), 18 deletions(-) diff --git a/jib-core/src/main/java/com/google/cloud/tools/jib/image/ImageTarball.java b/jib-core/src/main/java/com/google/cloud/tools/jib/image/ImageTarball.java index 750a2dcd11..5c7287a305 100644 --- a/jib-core/src/main/java/com/google/cloud/tools/jib/image/ImageTarball.java +++ b/jib-core/src/main/java/com/google/cloud/tools/jib/image/ImageTarball.java @@ -31,6 +31,7 @@ import java.io.IOException; import java.io.OutputStream; import java.nio.charset.StandardCharsets; +import java.time.Instant; import java.util.Collections; /** Translates an {@link Image} to a tarball that can be loaded into Docker. */ @@ -48,6 +49,7 @@ public class ImageTarball { private final Image image; private final ImageReference imageReference; private final ImmutableSet allTargetImageTags; + private final Instant creationTime = Instant.EPOCH; /** * Instantiate with an {@link Image}. @@ -88,7 +90,8 @@ private void ociWriteTo(OutputStream out) throws IOException { DescriptorDigest digest = layer.getBlobDescriptor().getDigest(); long size = layer.getBlobDescriptor().getSize(); - tarStreamBuilder.addBlobEntry(layer.getBlob(), size, "blobs/sha256/" + digest.getHash()); + tarStreamBuilder.addBlobEntry( + layer.getBlob(), size, "blobs/sha256/" + digest.getHash(), creationTime); manifest.addLayer(size, digest); } @@ -99,21 +102,26 @@ private void ociWriteTo(OutputStream out) throws IOException { manifest.setContainerConfiguration(configDescriptor.getSize(), configDescriptor.getDigest()); tarStreamBuilder.addByteEntry( JsonTemplateMapper.toByteArray(containerConfiguration), - "blobs/sha256/" + configDescriptor.getDigest().getHash()); + "blobs/sha256/" + configDescriptor.getDigest().getHash(), + creationTime); // Adds the manifest to the tarball BlobDescriptor manifestDescriptor = Digests.computeDigest(manifest); tarStreamBuilder.addByteEntry( JsonTemplateMapper.toByteArray(manifest), - "blobs/sha256/" + manifestDescriptor.getDigest().getHash()); + "blobs/sha256/" + manifestDescriptor.getDigest().getHash(), + creationTime); // Adds the oci-layout and index.json tarStreamBuilder.addByteEntry( - "{\"imageLayoutVersion\": \"1.0.0\"}".getBytes(StandardCharsets.UTF_8), "oci-layout"); + "{\"imageLayoutVersion\": \"1.0.0\"}".getBytes(StandardCharsets.UTF_8), + "oci-layout", + creationTime); OciIndexTemplate index = new OciIndexTemplate(); // TODO: figure out how to tag with allTargetImageTags index.addManifest(manifestDescriptor, imageReference.toStringWithQualifier()); - tarStreamBuilder.addByteEntry(JsonTemplateMapper.toByteArray(index), "index.json"); + tarStreamBuilder.addByteEntry( + JsonTemplateMapper.toByteArray(index), "index.json", creationTime); tarStreamBuilder.writeAsTarArchiveTo(out); } @@ -127,7 +135,7 @@ private void dockerWriteTo(OutputStream out) throws IOException { String layerName = layer.getBlobDescriptor().getDigest().getHash() + LAYER_FILE_EXTENSION; tarStreamBuilder.addBlobEntry( - layer.getBlob(), layer.getBlobDescriptor().getSize(), layerName); + layer.getBlob(), layer.getBlobDescriptor().getSize(), layerName, creationTime); manifestTemplate.addLayerFile(layerName); } @@ -136,7 +144,8 @@ private void dockerWriteTo(OutputStream out) throws IOException { new ImageToJsonTranslator(image).getContainerConfiguration(); tarStreamBuilder.addByteEntry( JsonTemplateMapper.toByteArray(containerConfiguration), - CONTAINER_CONFIGURATION_JSON_FILE_NAME); + CONTAINER_CONFIGURATION_JSON_FILE_NAME, + creationTime); // Adds the manifest to tarball. for (String tag : allTargetImageTags) { @@ -144,7 +153,8 @@ private void dockerWriteTo(OutputStream out) throws IOException { } tarStreamBuilder.addByteEntry( JsonTemplateMapper.toByteArray(Collections.singletonList(manifestTemplate)), - MANIFEST_JSON_FILE_NAME); + MANIFEST_JSON_FILE_NAME, + creationTime); tarStreamBuilder.writeAsTarArchiveTo(out); } diff --git a/jib-core/src/main/java/com/google/cloud/tools/jib/tar/TarStreamBuilder.java b/jib-core/src/main/java/com/google/cloud/tools/jib/tar/TarStreamBuilder.java index 006963ae02..1f385f0a3d 100644 --- a/jib-core/src/main/java/com/google/cloud/tools/jib/tar/TarStreamBuilder.java +++ b/jib-core/src/main/java/com/google/cloud/tools/jib/tar/TarStreamBuilder.java @@ -21,6 +21,7 @@ import java.io.IOException; import java.io.OutputStream; import java.nio.charset.StandardCharsets; +import java.time.Instant; import java.util.LinkedHashMap; import java.util.Map; import org.apache.commons.compress.archivers.tar.TarArchiveEntry; @@ -71,10 +72,12 @@ public void addTarArchiveEntry(TarArchiveEntry entry) { * * @param contents the bytes to add to the tarball * @param name the name of the entry (i.e. filename) + * @param modTime the time the entry is created */ - public void addByteEntry(byte[] contents, String name) { + public void addByteEntry(byte[] contents, String name, Instant modTime) { TarArchiveEntry entry = new TarArchiveEntry(name); entry.setSize(contents.length); + entry.setModTime(modTime.getEpochSecond()); archiveMap.put(entry, Blobs.from(outputStream -> outputStream.write(contents))); } @@ -85,10 +88,12 @@ public void addByteEntry(byte[] contents, String name) { * @param blob the {@link Blob} to add to the tarball * @param size the size (in bytes) of {@code blob} * @param name the name of the entry (i.e. filename) + * @param modTime the time the entry is created */ - public void addBlobEntry(Blob blob, long size, String name) { + public void addBlobEntry(Blob blob, long size, String name, Instant modTime) { TarArchiveEntry entry = new TarArchiveEntry(name); entry.setSize(size); + entry.setModTime(modTime.getEpochSecond()); archiveMap.put(entry, blob); } } diff --git a/jib-core/src/test/java/com/google/cloud/tools/jib/tar/TarStreamBuilderTest.java b/jib-core/src/test/java/com/google/cloud/tools/jib/tar/TarStreamBuilderTest.java index 6555c69c70..c0586fbfa2 100644 --- a/jib-core/src/test/java/com/google/cloud/tools/jib/tar/TarStreamBuilderTest.java +++ b/jib-core/src/test/java/com/google/cloud/tools/jib/tar/TarStreamBuilderTest.java @@ -29,6 +29,7 @@ import java.nio.file.Files; import java.nio.file.Path; import java.nio.file.Paths; +import java.time.Instant; import java.util.zip.GZIPInputStream; import java.util.zip.GZIPOutputStream; import org.apache.commons.compress.archivers.tar.TarArchiveEntry; @@ -46,6 +47,7 @@ public class TarStreamBuilderTest { private byte[] fileAContents; private byte[] fileBContents; private TarStreamBuilder testTarStreamBuilder = new TarStreamBuilder(); + private final Instant creationTime = Instant.EPOCH; @Before public void setup() throws URISyntaxException, IOException { @@ -96,10 +98,11 @@ public void testToBlob_stringsAndTarArchiveEntriesWithCompression() throws IOExc @Test public void testToBlob_multiByte() throws IOException { - testTarStreamBuilder.addByteEntry("日本語".getBytes(StandardCharsets.UTF_8), "test"); - testTarStreamBuilder.addByteEntry("asdf".getBytes(StandardCharsets.UTF_8), "crepecake"); + testTarStreamBuilder.addByteEntry("日本語".getBytes(StandardCharsets.UTF_8), "test", creationTime); + testTarStreamBuilder.addByteEntry( + "asdf".getBytes(StandardCharsets.UTF_8), "crepecake", creationTime); testTarStreamBuilder.addBlobEntry( - Blobs.from("jib"), "jib".getBytes(StandardCharsets.UTF_8).length, "jib"); + Blobs.from("jib"), "jib".getBytes(StandardCharsets.UTF_8).length, "jib", creationTime); // Writes the BLOB and captures the output. ByteArrayOutputStream tarByteOutputStream = new ByteArrayOutputStream(); @@ -148,25 +151,27 @@ private void setUpWithTarEntries() { /** Creates a TarStreamBuilder using Strings. */ private void setUpWithStrings() { // Prepares a test TarStreamBuilder. - testTarStreamBuilder.addByteEntry(fileAContents, "some/path/to/resourceFileA"); - testTarStreamBuilder.addByteEntry(fileBContents, "crepecake"); + testTarStreamBuilder.addByteEntry(fileAContents, "some/path/to/resourceFileA", creationTime); + testTarStreamBuilder.addByteEntry(fileBContents, "crepecake", creationTime); testTarStreamBuilder.addTarArchiveEntry( new TarArchiveEntry(directoryA.toFile(), "some/path/to")); testTarStreamBuilder.addByteEntry( fileAContents, - "some/really/long/path/that/exceeds/100/characters/abcdefghijklmnopqrstuvwxyz0123456789012345678901234567890"); + "some/really/long/path/that/exceeds/100/characters/abcdefghijklmnopqrstuvwxyz0123456789012345678901234567890", + creationTime); } /** Creates a TarStreamBuilder using Strings and TarArchiveEntries. */ private void setUpWithStringsAndTarEntries() { // Prepares a test TarStreamBuilder. - testTarStreamBuilder.addByteEntry(fileAContents, "some/path/to/resourceFileA"); + testTarStreamBuilder.addByteEntry(fileAContents, "some/path/to/resourceFileA", creationTime); testTarStreamBuilder.addTarArchiveEntry(new TarArchiveEntry(fileB.toFile(), "crepecake")); testTarStreamBuilder.addTarArchiveEntry( new TarArchiveEntry(directoryA.toFile(), "some/path/to")); testTarStreamBuilder.addByteEntry( fileAContents, - "some/really/long/path/that/exceeds/100/characters/abcdefghijklmnopqrstuvwxyz0123456789012345678901234567890"); + "some/really/long/path/that/exceeds/100/characters/abcdefghijklmnopqrstuvwxyz0123456789012345678901234567890", + creationTime); } /** Creates a compressed blob from the TarStreamBuilder and verifies it. */ From f1fd86691c15a164f87fc4fdbd856f078a358cde Mon Sep 17 00:00:00 2001 From: David Parry Date: Fri, 9 Apr 2021 09:37:26 +0100 Subject: [PATCH 04/15] Update jib-core/src/main/java/com/google/cloud/tools/jib/image/ImageTarball.java Co-authored-by: Chanseok Oh --- .../java/com/google/cloud/tools/jib/image/ImageTarball.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/jib-core/src/main/java/com/google/cloud/tools/jib/image/ImageTarball.java b/jib-core/src/main/java/com/google/cloud/tools/jib/image/ImageTarball.java index 5c7287a305..ce9000aa9f 100644 --- a/jib-core/src/main/java/com/google/cloud/tools/jib/image/ImageTarball.java +++ b/jib-core/src/main/java/com/google/cloud/tools/jib/image/ImageTarball.java @@ -49,7 +49,7 @@ public class ImageTarball { private final Image image; private final ImageReference imageReference; private final ImmutableSet allTargetImageTags; - private final Instant creationTime = Instant.EPOCH; + private static final Instant TAR_ENTRY_MODIFICATION_TIME = Instant.EPOCH; /** * Instantiate with an {@link Image}. From 11e744dc7cd2121039789e63d1bf7dab67775283 Mon Sep 17 00:00:00 2001 From: David Parry Date: Fri, 9 Apr 2021 09:37:34 +0100 Subject: [PATCH 05/15] Update jib-core/src/test/java/com/google/cloud/tools/jib/tar/TarStreamBuilderTest.java Co-authored-by: Chanseok Oh --- .../com/google/cloud/tools/jib/tar/TarStreamBuilderTest.java | 1 - 1 file changed, 1 deletion(-) diff --git a/jib-core/src/test/java/com/google/cloud/tools/jib/tar/TarStreamBuilderTest.java b/jib-core/src/test/java/com/google/cloud/tools/jib/tar/TarStreamBuilderTest.java index c0586fbfa2..9efcde2055 100644 --- a/jib-core/src/test/java/com/google/cloud/tools/jib/tar/TarStreamBuilderTest.java +++ b/jib-core/src/test/java/com/google/cloud/tools/jib/tar/TarStreamBuilderTest.java @@ -47,7 +47,6 @@ public class TarStreamBuilderTest { private byte[] fileAContents; private byte[] fileBContents; private TarStreamBuilder testTarStreamBuilder = new TarStreamBuilder(); - private final Instant creationTime = Instant.EPOCH; @Before public void setup() throws URISyntaxException, IOException { From 3df1d7e8010e5a615becf7193a99271cfda58894 Mon Sep 17 00:00:00 2001 From: David Parry Date: Fri, 9 Apr 2021 09:37:43 +0100 Subject: [PATCH 06/15] Update jib-core/src/test/java/com/google/cloud/tools/jib/tar/TarStreamBuilderTest.java Co-authored-by: Chanseok Oh --- .../com/google/cloud/tools/jib/tar/TarStreamBuilderTest.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/jib-core/src/test/java/com/google/cloud/tools/jib/tar/TarStreamBuilderTest.java b/jib-core/src/test/java/com/google/cloud/tools/jib/tar/TarStreamBuilderTest.java index 9efcde2055..2f61b1c75a 100644 --- a/jib-core/src/test/java/com/google/cloud/tools/jib/tar/TarStreamBuilderTest.java +++ b/jib-core/src/test/java/com/google/cloud/tools/jib/tar/TarStreamBuilderTest.java @@ -101,7 +101,7 @@ public void testToBlob_multiByte() throws IOException { testTarStreamBuilder.addByteEntry( "asdf".getBytes(StandardCharsets.UTF_8), "crepecake", creationTime); testTarStreamBuilder.addBlobEntry( - Blobs.from("jib"), "jib".getBytes(StandardCharsets.UTF_8).length, "jib", creationTime); + Blobs.from("jib"), "jib".getBytes(StandardCharsets.UTF_8).length, "jib", Instant.EPOCH); // Writes the BLOB and captures the output. ByteArrayOutputStream tarByteOutputStream = new ByteArrayOutputStream(); From f4bc94d04c29049bdd6b6395b75e5fbd0f977182 Mon Sep 17 00:00:00 2001 From: David Parry Date: Fri, 9 Apr 2021 09:38:43 +0100 Subject: [PATCH 07/15] Update jib-core/src/main/java/com/google/cloud/tools/jib/tar/TarStreamBuilder.java Co-authored-by: Chanseok Oh --- .../java/com/google/cloud/tools/jib/tar/TarStreamBuilder.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/jib-core/src/main/java/com/google/cloud/tools/jib/tar/TarStreamBuilder.java b/jib-core/src/main/java/com/google/cloud/tools/jib/tar/TarStreamBuilder.java index 1f385f0a3d..903ca4482d 100644 --- a/jib-core/src/main/java/com/google/cloud/tools/jib/tar/TarStreamBuilder.java +++ b/jib-core/src/main/java/com/google/cloud/tools/jib/tar/TarStreamBuilder.java @@ -74,7 +74,7 @@ public void addTarArchiveEntry(TarArchiveEntry entry) { * @param name the name of the entry (i.e. filename) * @param modTime the time the entry is created */ - public void addByteEntry(byte[] contents, String name, Instant modTime) { + public void addByteEntry(byte[] contents, String name, Instant modificationTime) { TarArchiveEntry entry = new TarArchiveEntry(name); entry.setSize(contents.length); entry.setModTime(modTime.getEpochSecond()); From 5d19b1f0c8efa53b98f7abd3880a2a92f98fdf78 Mon Sep 17 00:00:00 2001 From: David Parry Date: Fri, 9 Apr 2021 09:38:50 +0100 Subject: [PATCH 08/15] Update jib-core/src/main/java/com/google/cloud/tools/jib/tar/TarStreamBuilder.java Co-authored-by: Chanseok Oh --- .../java/com/google/cloud/tools/jib/tar/TarStreamBuilder.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/jib-core/src/main/java/com/google/cloud/tools/jib/tar/TarStreamBuilder.java b/jib-core/src/main/java/com/google/cloud/tools/jib/tar/TarStreamBuilder.java index 903ca4482d..aff6e769ac 100644 --- a/jib-core/src/main/java/com/google/cloud/tools/jib/tar/TarStreamBuilder.java +++ b/jib-core/src/main/java/com/google/cloud/tools/jib/tar/TarStreamBuilder.java @@ -72,7 +72,7 @@ public void addTarArchiveEntry(TarArchiveEntry entry) { * * @param contents the bytes to add to the tarball * @param name the name of the entry (i.e. filename) - * @param modTime the time the entry is created + * @param modificationTime the modification time of the entry */ public void addByteEntry(byte[] contents, String name, Instant modificationTime) { TarArchiveEntry entry = new TarArchiveEntry(name); From 75d321a5ab53f0846df9cb06b3be03a78e55dbf3 Mon Sep 17 00:00:00 2001 From: davidtron Date: Fri, 9 Apr 2021 13:28:55 +0100 Subject: [PATCH 09/15] #3158 - [Jib core] Tar archives with same contents are not reproducible --- .../cloud/tools/jib/image/ImageTarball.java | 23 +++++++++++-------- .../cloud/tools/jib/tar/TarStreamBuilder.java | 8 +++---- .../tools/jib/tar/TarStreamBuilderTest.java | 20 ++++++++++------ 3 files changed, 31 insertions(+), 20 deletions(-) diff --git a/jib-core/src/main/java/com/google/cloud/tools/jib/image/ImageTarball.java b/jib-core/src/main/java/com/google/cloud/tools/jib/image/ImageTarball.java index ce9000aa9f..b87f3a52e7 100644 --- a/jib-core/src/main/java/com/google/cloud/tools/jib/image/ImageTarball.java +++ b/jib-core/src/main/java/com/google/cloud/tools/jib/image/ImageTarball.java @@ -46,10 +46,12 @@ public class ImageTarball { /** File name extension for the layer content files. */ private static final String LAYER_FILE_EXTENSION = ".tar.gz"; + /** Time that entry is set in the tar. */ + private static final Instant TAR_ENTRY_MODIFICATION_TIME = Instant.EPOCH; + private final Image image; private final ImageReference imageReference; private final ImmutableSet allTargetImageTags; - private static final Instant TAR_ENTRY_MODIFICATION_TIME = Instant.EPOCH; /** * Instantiate with an {@link Image}. @@ -91,7 +93,7 @@ private void ociWriteTo(OutputStream out) throws IOException { long size = layer.getBlobDescriptor().getSize(); tarStreamBuilder.addBlobEntry( - layer.getBlob(), size, "blobs/sha256/" + digest.getHash(), creationTime); + layer.getBlob(), size, "blobs/sha256/" + digest.getHash(), TAR_ENTRY_MODIFICATION_TIME); manifest.addLayer(size, digest); } @@ -103,25 +105,25 @@ private void ociWriteTo(OutputStream out) throws IOException { tarStreamBuilder.addByteEntry( JsonTemplateMapper.toByteArray(containerConfiguration), "blobs/sha256/" + configDescriptor.getDigest().getHash(), - creationTime); + TAR_ENTRY_MODIFICATION_TIME); // Adds the manifest to the tarball BlobDescriptor manifestDescriptor = Digests.computeDigest(manifest); tarStreamBuilder.addByteEntry( JsonTemplateMapper.toByteArray(manifest), "blobs/sha256/" + manifestDescriptor.getDigest().getHash(), - creationTime); + TAR_ENTRY_MODIFICATION_TIME); // Adds the oci-layout and index.json tarStreamBuilder.addByteEntry( "{\"imageLayoutVersion\": \"1.0.0\"}".getBytes(StandardCharsets.UTF_8), "oci-layout", - creationTime); + TAR_ENTRY_MODIFICATION_TIME); OciIndexTemplate index = new OciIndexTemplate(); // TODO: figure out how to tag with allTargetImageTags index.addManifest(manifestDescriptor, imageReference.toStringWithQualifier()); tarStreamBuilder.addByteEntry( - JsonTemplateMapper.toByteArray(index), "index.json", creationTime); + JsonTemplateMapper.toByteArray(index), "index.json", TAR_ENTRY_MODIFICATION_TIME); tarStreamBuilder.writeAsTarArchiveTo(out); } @@ -135,7 +137,10 @@ private void dockerWriteTo(OutputStream out) throws IOException { String layerName = layer.getBlobDescriptor().getDigest().getHash() + LAYER_FILE_EXTENSION; tarStreamBuilder.addBlobEntry( - layer.getBlob(), layer.getBlobDescriptor().getSize(), layerName, creationTime); + layer.getBlob(), + layer.getBlobDescriptor().getSize(), + layerName, + TAR_ENTRY_MODIFICATION_TIME); manifestTemplate.addLayerFile(layerName); } @@ -145,7 +150,7 @@ private void dockerWriteTo(OutputStream out) throws IOException { tarStreamBuilder.addByteEntry( JsonTemplateMapper.toByteArray(containerConfiguration), CONTAINER_CONFIGURATION_JSON_FILE_NAME, - creationTime); + TAR_ENTRY_MODIFICATION_TIME); // Adds the manifest to tarball. for (String tag : allTargetImageTags) { @@ -154,7 +159,7 @@ private void dockerWriteTo(OutputStream out) throws IOException { tarStreamBuilder.addByteEntry( JsonTemplateMapper.toByteArray(Collections.singletonList(manifestTemplate)), MANIFEST_JSON_FILE_NAME, - creationTime); + TAR_ENTRY_MODIFICATION_TIME); tarStreamBuilder.writeAsTarArchiveTo(out); } diff --git a/jib-core/src/main/java/com/google/cloud/tools/jib/tar/TarStreamBuilder.java b/jib-core/src/main/java/com/google/cloud/tools/jib/tar/TarStreamBuilder.java index aff6e769ac..bd579bbde4 100644 --- a/jib-core/src/main/java/com/google/cloud/tools/jib/tar/TarStreamBuilder.java +++ b/jib-core/src/main/java/com/google/cloud/tools/jib/tar/TarStreamBuilder.java @@ -77,7 +77,7 @@ public void addTarArchiveEntry(TarArchiveEntry entry) { public void addByteEntry(byte[] contents, String name, Instant modificationTime) { TarArchiveEntry entry = new TarArchiveEntry(name); entry.setSize(contents.length); - entry.setModTime(modTime.getEpochSecond()); + entry.setModTime(modificationTime.getEpochSecond()); archiveMap.put(entry, Blobs.from(outputStream -> outputStream.write(contents))); } @@ -88,12 +88,12 @@ public void addByteEntry(byte[] contents, String name, Instant modificationTime) * @param blob the {@link Blob} to add to the tarball * @param size the size (in bytes) of {@code blob} * @param name the name of the entry (i.e. filename) - * @param modTime the time the entry is created + * @param modificationTime the modification time of the entry */ - public void addBlobEntry(Blob blob, long size, String name, Instant modTime) { + public void addBlobEntry(Blob blob, long size, String name, Instant modificationTime) { TarArchiveEntry entry = new TarArchiveEntry(name); entry.setSize(size); - entry.setModTime(modTime.getEpochSecond()); + entry.setModTime(modificationTime.getEpochSecond()); archiveMap.put(entry, blob); } } diff --git a/jib-core/src/test/java/com/google/cloud/tools/jib/tar/TarStreamBuilderTest.java b/jib-core/src/test/java/com/google/cloud/tools/jib/tar/TarStreamBuilderTest.java index 2f61b1c75a..f257d9d8cc 100644 --- a/jib-core/src/test/java/com/google/cloud/tools/jib/tar/TarStreamBuilderTest.java +++ b/jib-core/src/test/java/com/google/cloud/tools/jib/tar/TarStreamBuilderTest.java @@ -97,9 +97,10 @@ public void testToBlob_stringsAndTarArchiveEntriesWithCompression() throws IOExc @Test public void testToBlob_multiByte() throws IOException { - testTarStreamBuilder.addByteEntry("日本語".getBytes(StandardCharsets.UTF_8), "test", creationTime); testTarStreamBuilder.addByteEntry( - "asdf".getBytes(StandardCharsets.UTF_8), "crepecake", creationTime); + "日本語".getBytes(StandardCharsets.UTF_8), "test", Instant.EPOCH); + testTarStreamBuilder.addByteEntry( + "asdf".getBytes(StandardCharsets.UTF_8), "crepecake", Instant.EPOCH); testTarStreamBuilder.addBlobEntry( Blobs.from("jib"), "jib".getBytes(StandardCharsets.UTF_8).length, "jib", Instant.EPOCH); @@ -124,11 +125,13 @@ public void testToBlob_multiByte() throws IOException { Assert.assertEquals("crepecake", headerFile.getName()); Assert.assertEquals( "asdf", new String(ByteStreams.toByteArray(tarArchiveInputStream), StandardCharsets.UTF_8)); + Assert.assertEquals(Instant.EPOCH, headerFile.getModTime().toInstant()); headerFile = tarArchiveInputStream.getNextTarEntry(); Assert.assertEquals("jib", headerFile.getName()); Assert.assertEquals( "jib", new String(ByteStreams.toByteArray(tarArchiveInputStream), StandardCharsets.UTF_8)); + Assert.assertEquals(Instant.EPOCH, headerFile.getModTime().toInstant()); Assert.assertNull(tarArchiveInputStream.getNextTarEntry()); } @@ -150,27 +153,27 @@ private void setUpWithTarEntries() { /** Creates a TarStreamBuilder using Strings. */ private void setUpWithStrings() { // Prepares a test TarStreamBuilder. - testTarStreamBuilder.addByteEntry(fileAContents, "some/path/to/resourceFileA", creationTime); - testTarStreamBuilder.addByteEntry(fileBContents, "crepecake", creationTime); + testTarStreamBuilder.addByteEntry(fileAContents, "some/path/to/resourceFileA", Instant.EPOCH); + testTarStreamBuilder.addByteEntry(fileBContents, "crepecake", Instant.EPOCH); testTarStreamBuilder.addTarArchiveEntry( new TarArchiveEntry(directoryA.toFile(), "some/path/to")); testTarStreamBuilder.addByteEntry( fileAContents, "some/really/long/path/that/exceeds/100/characters/abcdefghijklmnopqrstuvwxyz0123456789012345678901234567890", - creationTime); + Instant.EPOCH); } /** Creates a TarStreamBuilder using Strings and TarArchiveEntries. */ private void setUpWithStringsAndTarEntries() { // Prepares a test TarStreamBuilder. - testTarStreamBuilder.addByteEntry(fileAContents, "some/path/to/resourceFileA", creationTime); + testTarStreamBuilder.addByteEntry(fileAContents, "some/path/to/resourceFileA", Instant.EPOCH); testTarStreamBuilder.addTarArchiveEntry(new TarArchiveEntry(fileB.toFile(), "crepecake")); testTarStreamBuilder.addTarArchiveEntry( new TarArchiveEntry(directoryA.toFile(), "some/path/to")); testTarStreamBuilder.addByteEntry( fileAContents, "some/really/long/path/that/exceeds/100/characters/abcdefghijklmnopqrstuvwxyz0123456789012345678901234567890", - creationTime); + Instant.EPOCH); } /** Creates a compressed blob from the TarStreamBuilder and verifies it. */ @@ -215,18 +218,21 @@ private void verifyTarArchive(TarArchiveInputStream tarArchiveInputStream) throw // Verifies fileB was archived correctly. TarArchiveEntry headerFileB = tarArchiveInputStream.getNextTarEntry(); Assert.assertEquals("crepecake", headerFileB.getName()); + Assert.assertEquals(Instant.EPOCH, headerFileB.getModTime().toInstant()); byte[] fileBString = ByteStreams.toByteArray(tarArchiveInputStream); Assert.assertArrayEquals(fileBContents, fileBString); // Verifies directoryA was archived correctly. TarArchiveEntry headerDirectoryA = tarArchiveInputStream.getNextTarEntry(); Assert.assertEquals("some/path/to/", headerDirectoryA.getName()); + Assert.assertEquals(Instant.EPOCH, headerDirectoryA.getModTime().toInstant()); // Verifies the long file was archived correctly. TarArchiveEntry headerFileALong = tarArchiveInputStream.getNextTarEntry(); Assert.assertEquals( "some/really/long/path/that/exceeds/100/characters/abcdefghijklmnopqrstuvwxyz0123456789012345678901234567890", headerFileALong.getName()); + Assert.assertEquals(Instant.EPOCH, headerFileALong); byte[] fileALongString = ByteStreams.toByteArray(tarArchiveInputStream); Assert.assertArrayEquals(fileAContents, fileALongString); From 9c1141b5fbdd28eee851c6c656c966ca5eb61afa Mon Sep 17 00:00:00 2001 From: davidtron Date: Fri, 9 Apr 2021 13:39:34 +0100 Subject: [PATCH 10/15] #3158 - [Jib core] Tar archives with same contents are not reproducible --- .../com/google/cloud/tools/jib/tar/TarStreamBuilderTest.java | 3 --- 1 file changed, 3 deletions(-) diff --git a/jib-core/src/test/java/com/google/cloud/tools/jib/tar/TarStreamBuilderTest.java b/jib-core/src/test/java/com/google/cloud/tools/jib/tar/TarStreamBuilderTest.java index f257d9d8cc..10e7e65b3e 100644 --- a/jib-core/src/test/java/com/google/cloud/tools/jib/tar/TarStreamBuilderTest.java +++ b/jib-core/src/test/java/com/google/cloud/tools/jib/tar/TarStreamBuilderTest.java @@ -218,21 +218,18 @@ private void verifyTarArchive(TarArchiveInputStream tarArchiveInputStream) throw // Verifies fileB was archived correctly. TarArchiveEntry headerFileB = tarArchiveInputStream.getNextTarEntry(); Assert.assertEquals("crepecake", headerFileB.getName()); - Assert.assertEquals(Instant.EPOCH, headerFileB.getModTime().toInstant()); byte[] fileBString = ByteStreams.toByteArray(tarArchiveInputStream); Assert.assertArrayEquals(fileBContents, fileBString); // Verifies directoryA was archived correctly. TarArchiveEntry headerDirectoryA = tarArchiveInputStream.getNextTarEntry(); Assert.assertEquals("some/path/to/", headerDirectoryA.getName()); - Assert.assertEquals(Instant.EPOCH, headerDirectoryA.getModTime().toInstant()); // Verifies the long file was archived correctly. TarArchiveEntry headerFileALong = tarArchiveInputStream.getNextTarEntry(); Assert.assertEquals( "some/really/long/path/that/exceeds/100/characters/abcdefghijklmnopqrstuvwxyz0123456789012345678901234567890", headerFileALong.getName()); - Assert.assertEquals(Instant.EPOCH, headerFileALong); byte[] fileALongString = ByteStreams.toByteArray(tarArchiveInputStream); Assert.assertArrayEquals(fileAContents, fileALongString); From b12a4aaa2c855e855530af7a2261ad616d62ba58 Mon Sep 17 00:00:00 2001 From: davidtron Date: Sat, 10 Apr 2021 09:00:46 +0100 Subject: [PATCH 11/15] #3158 - [Jib core] Tar archives with same contents are not reproducible --- .../cloud/tools/jib/tar/TarStreamBuilder.java | 4 ++-- .../tools/jib/tar/TarStreamBuilderTest.java | 16 +++++++++++----- 2 files changed, 13 insertions(+), 7 deletions(-) diff --git a/jib-core/src/main/java/com/google/cloud/tools/jib/tar/TarStreamBuilder.java b/jib-core/src/main/java/com/google/cloud/tools/jib/tar/TarStreamBuilder.java index bd579bbde4..cccead8a8b 100644 --- a/jib-core/src/main/java/com/google/cloud/tools/jib/tar/TarStreamBuilder.java +++ b/jib-core/src/main/java/com/google/cloud/tools/jib/tar/TarStreamBuilder.java @@ -77,7 +77,7 @@ public void addTarArchiveEntry(TarArchiveEntry entry) { public void addByteEntry(byte[] contents, String name, Instant modificationTime) { TarArchiveEntry entry = new TarArchiveEntry(name); entry.setSize(contents.length); - entry.setModTime(modificationTime.getEpochSecond()); + entry.setModTime(modificationTime.toEpochMilli()); archiveMap.put(entry, Blobs.from(outputStream -> outputStream.write(contents))); } @@ -93,7 +93,7 @@ public void addByteEntry(byte[] contents, String name, Instant modificationTime) public void addBlobEntry(Blob blob, long size, String name, Instant modificationTime) { TarArchiveEntry entry = new TarArchiveEntry(name); entry.setSize(size); - entry.setModTime(modificationTime.getEpochSecond()); + entry.setModTime(modificationTime.toEpochMilli()); archiveMap.put(entry, blob); } } diff --git a/jib-core/src/test/java/com/google/cloud/tools/jib/tar/TarStreamBuilderTest.java b/jib-core/src/test/java/com/google/cloud/tools/jib/tar/TarStreamBuilderTest.java index 10e7e65b3e..f48f269c94 100644 --- a/jib-core/src/test/java/com/google/cloud/tools/jib/tar/TarStreamBuilderTest.java +++ b/jib-core/src/test/java/com/google/cloud/tools/jib/tar/TarStreamBuilderTest.java @@ -38,9 +38,12 @@ import org.junit.Before; import org.junit.Test; +import static java.time.temporal.ChronoUnit.SECONDS; + /** Tests for {@link TarStreamBuilder}. */ public class TarStreamBuilderTest { + private Path fileA; private Path fileB; private Path directoryA; @@ -97,12 +100,15 @@ public void testToBlob_stringsAndTarArchiveEntriesWithCompression() throws IOExc @Test public void testToBlob_multiByte() throws IOException { + Instant MODIFICATION_TIME = Instant.ofEpochMilli(1618041179516l); + Instant TIME_FROM_TAR_ARCHIVE_ENTRY = MODIFICATION_TIME.truncatedTo(SECONDS); + testTarStreamBuilder.addByteEntry( - "日本語".getBytes(StandardCharsets.UTF_8), "test", Instant.EPOCH); + "日本語".getBytes(StandardCharsets.UTF_8), "test", MODIFICATION_TIME); testTarStreamBuilder.addByteEntry( - "asdf".getBytes(StandardCharsets.UTF_8), "crepecake", Instant.EPOCH); + "asdf".getBytes(StandardCharsets.UTF_8), "crepecake", MODIFICATION_TIME); testTarStreamBuilder.addBlobEntry( - Blobs.from("jib"), "jib".getBytes(StandardCharsets.UTF_8).length, "jib", Instant.EPOCH); + Blobs.from("jib"), "jib".getBytes(StandardCharsets.UTF_8).length, "jib", MODIFICATION_TIME); // Writes the BLOB and captures the output. ByteArrayOutputStream tarByteOutputStream = new ByteArrayOutputStream(); @@ -125,13 +131,13 @@ public void testToBlob_multiByte() throws IOException { Assert.assertEquals("crepecake", headerFile.getName()); Assert.assertEquals( "asdf", new String(ByteStreams.toByteArray(tarArchiveInputStream), StandardCharsets.UTF_8)); - Assert.assertEquals(Instant.EPOCH, headerFile.getModTime().toInstant()); + Assert.assertEquals(TIME_FROM_TAR_ARCHIVE_ENTRY, headerFile.getModTime().toInstant()); headerFile = tarArchiveInputStream.getNextTarEntry(); Assert.assertEquals("jib", headerFile.getName()); Assert.assertEquals( "jib", new String(ByteStreams.toByteArray(tarArchiveInputStream), StandardCharsets.UTF_8)); - Assert.assertEquals(Instant.EPOCH, headerFile.getModTime().toInstant()); + Assert.assertEquals(TIME_FROM_TAR_ARCHIVE_ENTRY, headerFile.getModTime().toInstant()); Assert.assertNull(tarArchiveInputStream.getNextTarEntry()); } From 25a5ae278527fbd923b81ff216ae1ff84751c2e2 Mon Sep 17 00:00:00 2001 From: davidtron Date: Mon, 12 Apr 2021 20:32:20 +0100 Subject: [PATCH 12/15] #3158 - [Jib core] Tar archives with same contents are not reproducible --- .../cloud/tools/jib/tar/TarStreamBuilderTest.java | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/jib-core/src/test/java/com/google/cloud/tools/jib/tar/TarStreamBuilderTest.java b/jib-core/src/test/java/com/google/cloud/tools/jib/tar/TarStreamBuilderTest.java index f48f269c94..920fca335d 100644 --- a/jib-core/src/test/java/com/google/cloud/tools/jib/tar/TarStreamBuilderTest.java +++ b/jib-core/src/test/java/com/google/cloud/tools/jib/tar/TarStreamBuilderTest.java @@ -100,15 +100,15 @@ public void testToBlob_stringsAndTarArchiveEntriesWithCompression() throws IOExc @Test public void testToBlob_multiByte() throws IOException { - Instant MODIFICATION_TIME = Instant.ofEpochMilli(1618041179516l); - Instant TIME_FROM_TAR_ARCHIVE_ENTRY = MODIFICATION_TIME.truncatedTo(SECONDS); + Instant modificationTime = Instant.ofEpochMilli(1618041179516l); + Instant timeFromTarArchiveEntry = modificationTime.truncatedTo(SECONDS); testTarStreamBuilder.addByteEntry( - "日本語".getBytes(StandardCharsets.UTF_8), "test", MODIFICATION_TIME); + "日本語".getBytes(StandardCharsets.UTF_8), "test", modificationTime); testTarStreamBuilder.addByteEntry( - "asdf".getBytes(StandardCharsets.UTF_8), "crepecake", MODIFICATION_TIME); + "asdf".getBytes(StandardCharsets.UTF_8), "crepecake", modificationTime); testTarStreamBuilder.addBlobEntry( - Blobs.from("jib"), "jib".getBytes(StandardCharsets.UTF_8).length, "jib", MODIFICATION_TIME); + Blobs.from("jib"), "jib".getBytes(StandardCharsets.UTF_8).length, "jib", modificationTime); // Writes the BLOB and captures the output. ByteArrayOutputStream tarByteOutputStream = new ByteArrayOutputStream(); @@ -131,13 +131,13 @@ public void testToBlob_multiByte() throws IOException { Assert.assertEquals("crepecake", headerFile.getName()); Assert.assertEquals( "asdf", new String(ByteStreams.toByteArray(tarArchiveInputStream), StandardCharsets.UTF_8)); - Assert.assertEquals(TIME_FROM_TAR_ARCHIVE_ENTRY, headerFile.getModTime().toInstant()); + Assert.assertEquals(timeFromTarArchiveEntry, headerFile.getModTime().toInstant()); headerFile = tarArchiveInputStream.getNextTarEntry(); Assert.assertEquals("jib", headerFile.getName()); Assert.assertEquals( "jib", new String(ByteStreams.toByteArray(tarArchiveInputStream), StandardCharsets.UTF_8)); - Assert.assertEquals(TIME_FROM_TAR_ARCHIVE_ENTRY, headerFile.getModTime().toInstant()); + Assert.assertEquals(timeFromTarArchiveEntry, headerFile.getModTime().toInstant()); Assert.assertNull(tarArchiveInputStream.getNextTarEntry()); } From 3bc801f39f6cc9856234cb3345e84ea97984ef8e Mon Sep 17 00:00:00 2001 From: davidtron Date: Mon, 12 Apr 2021 20:40:58 +0100 Subject: [PATCH 13/15] #3158 - [Jib core] Tar archives with same contents are not reproducible --- .../com/google/cloud/tools/jib/tar/TarStreamBuilderTest.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/jib-core/src/test/java/com/google/cloud/tools/jib/tar/TarStreamBuilderTest.java b/jib-core/src/test/java/com/google/cloud/tools/jib/tar/TarStreamBuilderTest.java index 920fca335d..d8e588bab6 100644 --- a/jib-core/src/test/java/com/google/cloud/tools/jib/tar/TarStreamBuilderTest.java +++ b/jib-core/src/test/java/com/google/cloud/tools/jib/tar/TarStreamBuilderTest.java @@ -16,6 +16,8 @@ package com.google.cloud.tools.jib.tar; +import static java.time.temporal.ChronoUnit.SECONDS; + import com.google.cloud.tools.jib.blob.Blobs; import com.google.common.io.ByteStreams; import com.google.common.io.Resources; @@ -38,8 +40,6 @@ import org.junit.Before; import org.junit.Test; -import static java.time.temporal.ChronoUnit.SECONDS; - /** Tests for {@link TarStreamBuilder}. */ public class TarStreamBuilderTest { From cc87a869c2cb6582081240fa679c37d309f7e8a7 Mon Sep 17 00:00:00 2001 From: davidtron Date: Mon, 12 Apr 2021 20:53:28 +0100 Subject: [PATCH 14/15] #3158 - [Jib core] Tar archives with same contents are not reproducible --- .../com/google/cloud/tools/jib/tar/TarStreamBuilderTest.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/jib-core/src/test/java/com/google/cloud/tools/jib/tar/TarStreamBuilderTest.java b/jib-core/src/test/java/com/google/cloud/tools/jib/tar/TarStreamBuilderTest.java index d8e588bab6..99c0a921af 100644 --- a/jib-core/src/test/java/com/google/cloud/tools/jib/tar/TarStreamBuilderTest.java +++ b/jib-core/src/test/java/com/google/cloud/tools/jib/tar/TarStreamBuilderTest.java @@ -100,7 +100,7 @@ public void testToBlob_stringsAndTarArchiveEntriesWithCompression() throws IOExc @Test public void testToBlob_multiByte() throws IOException { - Instant modificationTime = Instant.ofEpochMilli(1618041179516l); + Instant modificationTime = Instant.ofEpochMilli(1618041179516L); Instant timeFromTarArchiveEntry = modificationTime.truncatedTo(SECONDS); testTarStreamBuilder.addByteEntry( From dd70bbac3d865e77a34df2199e9fc1cedcba8d99 Mon Sep 17 00:00:00 2001 From: davidtron Date: Mon, 12 Apr 2021 21:01:50 +0100 Subject: [PATCH 15/15] #3158 - [Jib core] Tar archives with same contents are not reproducible --- .../com/google/cloud/tools/jib/tar/TarStreamBuilderTest.java | 1 - 1 file changed, 1 deletion(-) diff --git a/jib-core/src/test/java/com/google/cloud/tools/jib/tar/TarStreamBuilderTest.java b/jib-core/src/test/java/com/google/cloud/tools/jib/tar/TarStreamBuilderTest.java index 99c0a921af..6aa2f9f2cd 100644 --- a/jib-core/src/test/java/com/google/cloud/tools/jib/tar/TarStreamBuilderTest.java +++ b/jib-core/src/test/java/com/google/cloud/tools/jib/tar/TarStreamBuilderTest.java @@ -43,7 +43,6 @@ /** Tests for {@link TarStreamBuilder}. */ public class TarStreamBuilderTest { - private Path fileA; private Path fileB; private Path directoryA;