Skip to content

Commit c19b3de

Browse files
authored
Proposal: Address Base Image Reproducibility (GoogleContainerTools#224)
1 parent 40fa6ae commit c19b3de

1 file changed

Lines changed: 48 additions & 0 deletions

File tree

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
# Proposal: Address Base Image Reproducibility
2+
3+
## Motivation
4+
5+
One of the main goals of Jib is to be able to build images reproducibly, such that the same contents always creates the same images. It does this by wiping the timestamps and user information from the files in the Java application layers (dependencies, resources, classes). However, it does not do the same for the base image layers, which, by default, are from the latest [`gcr.io/distroless/java`](gcr.io/distroless/java) image. This may be unexpected behaviors since by default, reproducibility is on (the user may switch it off using the `enableReproducibleBuilds` parameter for Maven or the `reproducible` parameter for Gradle).
6+
7+
### Terminology
8+
9+
Image **reference** refers to the full reference for an image. This can be as short as `busybox` (which refers to the `library/busybox` **repository** on the Docker Hub **registry**), or as long as `gcr.io/distroless/java@sha256:0135c8b1adb3ed906f521973f825cea3fcdcb9b0db2f4012cc05480bf4d53fd6` (which refers to the image with **digest** `sha256:0135c8b1adb3...` in the `distroless/java` repository on the `gcr.io` registry). An image reference without a specific digest or tag, like `gcr.io/distroless/java`, defaults to the `latest` **tag**, which always refers to the newest digest in that repository.
10+
11+
## Problem
12+
13+
The main problem is that the reproducibility feature of Jib does not actually guaranteed *for the image*, but rather only guarantees reproducibility *for the application layers*. This is a bug.
14+
15+
The problem arises in a common workflow where the developer expects reproducibility:
16+
17+
1. The developer commits a change as version 123.
18+
1. The developer builds the image for that commit - results in image A.
19+
1. On another machine (possibly in prod), that developer checks out version 123 and builds the image - this should have resulted in image A again.
20+
21+
However, since Jib uses the latest version of the [gcr.io/distroless/java](gcr.io/distroless/java) image (which is updated rather frequently - about every 2 weeks) as the base image to build the application layers on top of, if a newer [gcr.io/distroless/java](gcr.io/distroless/java) is latest, the rebuild would result in a different image than expected.
22+
23+
## Goals
24+
25+
- Maintain ease-of-use (no unnecessary extra configuration, at least for the default case)
26+
- Preferable: Keep reproducibility on by default
27+
28+
## Solution
29+
30+
Jib will still use `gcr.io/distroless/java` by default, since in development, users may wish to keep at the latest base image. An alternative would be to use a specific digest of `gcr.io/distroless/java` but that would involve tying a version of Jib to a version of distroless.
31+
32+
The `reproducible`/`enableReproducibleBuilds` configuration will be removed. Application layers (dependencies, resources, classes) will always be reproducible.
33+
34+
Reproducibility will be guaranteed if the user specifies a specific digest to use for a base image. This can be specified as a fully-qualified custom base image, or as a `tag` configuration (Maven).
35+
36+
The user will be warned if the base image used is tagged with `latest` such that reproducibility is not guaranteed. Note that this warning is given by default.
37+
38+
So, the logic flow would be:
39+
40+
1. Jib uses `gcr.io/distroless/java` as the base image.
41+
1. If the user specifies a different image to use as the base image, use that.
42+
1. The user can configure a specific digest to use - `tag` for Maven, and `from.image` for Gradle.
43+
1. If the final tag/digest is still `latest`, warn the user that reproducibility is not guaranteed due a changeable base image, and suggest the user to specify a specific digest.
44+
45+
## Implementation
46+
47+
- Remove the `reproducible`/`enableReproducibleBuilds` configuration and always build application layers reproducibly.
48+
- When validating the `jib-maven-plugin`/`jib-gradle-plugin` configuration, warn the user if the base image uses a `latest` tag.

0 commit comments

Comments
 (0)