Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CHANGELOG for reproducible buildTar change / refactor tests #3211

Merged
merged 3 commits into from
Apr 14, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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