Skip to content

Commit

Permalink
CHANGELOG for reproducible buildTar change / refactor tests (#3211)
Browse files Browse the repository at this point in the history
  • Loading branch information
chanseokoh authored Apr 14, 2021
1 parent f58e3bd commit c3e8f50
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 10 deletions.
1 change: 1 addition & 0 deletions jib-core/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ All notable changes to this project will be documented in this file.
### Changed

- `JavaContainerBuilder#fromDistroless()` and `JavaContainerBuilder#fromDistrolessJetty()` are deprecated. To migrate, check the Javadoc. ([#3123](https://github.com/GoogleContainerTools/jib/pull/3123))
- Timestamps of file entries in a built `TarImage` are set to the epoch, making the tarball reproducible. ([#3158](https://github.com/GoogleContainerTools/jib/issues/3158))

### Fixed

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

package com.google.cloud.tools.jib.tar;

import static java.time.temporal.ChronoUnit.SECONDS;
import static com.google.common.truth.Truth.assertThat;

import com.google.cloud.tools.jib.blob.Blobs;
import com.google.common.io.ByteStreams;
Expand Down Expand Up @@ -48,7 +48,7 @@ public class TarStreamBuilderTest {
private Path directoryA;
private byte[] fileAContents;
private byte[] fileBContents;
private TarStreamBuilder testTarStreamBuilder = new TarStreamBuilder();
private final TarStreamBuilder testTarStreamBuilder = new TarStreamBuilder();

@Before
public void setup() throws URISyntaxException, IOException {
Expand Down Expand Up @@ -99,15 +99,12 @@ public void testToBlob_stringsAndTarArchiveEntriesWithCompression() throws IOExc

@Test
public void testToBlob_multiByte() throws IOException {
Instant modificationTime = Instant.ofEpochMilli(1618041179516L);
Instant timeFromTarArchiveEntry = modificationTime.truncatedTo(SECONDS);

testTarStreamBuilder.addByteEntry(
"日本語".getBytes(StandardCharsets.UTF_8), "test", modificationTime);
"日本語".getBytes(StandardCharsets.UTF_8), "test", Instant.EPOCH);
testTarStreamBuilder.addByteEntry(
"asdf".getBytes(StandardCharsets.UTF_8), "crepecake", modificationTime);
"asdf".getBytes(StandardCharsets.UTF_8), "crepecake", Instant.EPOCH);
testTarStreamBuilder.addBlobEntry(
Blobs.from("jib"), "jib".getBytes(StandardCharsets.UTF_8).length, "jib", modificationTime);
Blobs.from("jib"), "jib".getBytes(StandardCharsets.UTF_8).length, "jib", Instant.EPOCH);

// Writes the BLOB and captures the output.
ByteArrayOutputStream tarByteOutputStream = new ByteArrayOutputStream();
Expand All @@ -130,17 +127,39 @@ public void testToBlob_multiByte() throws IOException {
Assert.assertEquals("crepecake", headerFile.getName());
Assert.assertEquals(
"asdf", new String(ByteStreams.toByteArray(tarArchiveInputStream), StandardCharsets.UTF_8));
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(timeFromTarArchiveEntry, headerFile.getModTime().toInstant());

Assert.assertNull(tarArchiveInputStream.getNextTarEntry());
}

@Test
public void testToBlob_modificationTime() throws IOException {
testTarStreamBuilder.addByteEntry(
"foo".getBytes(StandardCharsets.UTF_8), "foo", Instant.ofEpochSecond(1234));
testTarStreamBuilder.addBlobEntry(
Blobs.from("bar"),
"bar".getBytes(StandardCharsets.UTF_8).length,
"bar",
Instant.ofEpochSecond(3));

ByteArrayOutputStream outStream = new ByteArrayOutputStream();
testTarStreamBuilder.writeAsTarArchiveTo(outStream);

TarArchiveInputStream tarInStream =
new TarArchiveInputStream(new ByteArrayInputStream(outStream.toByteArray()));
TarArchiveEntry entry1 = tarInStream.getNextTarEntry();
TarArchiveEntry entry2 = tarInStream.getNextTarEntry();

assertThat(entry1.getName()).isEqualTo("foo");
assertThat(entry1.getModTime().toInstant()).isEqualTo(Instant.ofEpochSecond(1234));
assertThat(entry2.getName()).isEqualTo("bar");
assertThat(entry2.getModTime().toInstant()).isEqualTo(Instant.ofEpochSecond(3));
}

/** Creates a TarStreamBuilder using TarArchiveEntries. */
private void setUpWithTarEntries() {
// Prepares a test TarStreamBuilder.
Expand Down
2 changes: 2 additions & 0 deletions jib-gradle-plugin/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ All notable changes to this project will be documented in this file.

### Changed

- Timestamps of file entries in a tarball built with `jibBuildTar` are set to the epoch, making the tarball reproducible. ([#3158](https://github.com/GoogleContainerTools/jib/issues/3158))

### Fixed

## 3.0.0
Expand Down
2 changes: 2 additions & 0 deletions jib-maven-plugin/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ All notable changes to this project will be documented in this file.

### Changed

- Timestamps of file entries in a tarball built with `jib:buildTar` are set to the epoch, making the tarball reproducible. ([#3158](https://github.com/GoogleContainerTools/jib/issues/3158))

### Fixed

## 3.0.0
Expand Down

0 comments on commit c3e8f50

Please sign in to comment.