-
Notifications
You must be signed in to change notification settings - Fork 1.4k
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
Write history as part of layer metadata #877
Changes from 16 commits
318071e
8b2aada
23ee777
f7f83d4
b7d38d0
3530ec6
352c011
aa063f1
9ab0d43
260cf4d
f8f48c2
e4ce5a9
0c6cceb
bf2b25f
b93594d
247814e
3fe3597
aed225b
80c588a
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -42,6 +42,18 @@ | |
* "ExposedPorts": { "6000/tcp":{}, "8000/tcp":{}, "9000/tcp":{} } | ||
* "Labels": { "com.example.label": "value" } | ||
* }, | ||
* "history": [ | ||
* { | ||
* "author": "Jib", | ||
* "created": "1970-01-01T00:00:00Z", | ||
* "created_by": "jib" | ||
* }, | ||
* { | ||
* "author": "Jib", | ||
* "created": "1970-01-01T00:00:00Z", | ||
* "created_by": "jib" | ||
* } | ||
* ] | ||
* "rootfs": { | ||
* "diff_ids": [ | ||
* "sha256:2aebd096e0e237b447781353379722157e6c2d434b9ec5a0d63f2a6f07cf90c2", | ||
|
@@ -70,6 +82,9 @@ public class ContainerConfigurationTemplate implements JsonTemplate { | |
/** Execution parameters that should be used as a base when running the container. */ | ||
private final ConfigurationObjectTemplate config = new ConfigurationObjectTemplate(); | ||
|
||
/** Build commands used to create the image. */ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. "Describes the history of each layer"? |
||
private final List<HistoryEntry> history = new ArrayList<>(); | ||
|
||
/** Layer content digests that are used to build the container filesystem. */ | ||
private final RootFilesystemObjectTemplate rootfs = new RootFilesystemObjectTemplate(); | ||
|
||
|
@@ -137,10 +152,18 @@ public void addLayerDiffId(DescriptorDigest diffId) { | |
rootfs.diff_ids.add(diffId); | ||
} | ||
|
||
public void addHistory(HistoryEntry historyEntry) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nit: since |
||
history.add(historyEntry); | ||
} | ||
|
||
List<DescriptorDigest> getDiffIds() { | ||
return rootfs.diff_ids; | ||
} | ||
|
||
List<HistoryEntry> getHistory() { | ||
return history; | ||
} | ||
|
||
@Nullable | ||
String getCreated() { | ||
return created; | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,108 @@ | ||
/* | ||
* Copyright 2018 Google LLC. All rights reserved. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); you may not | ||
* use this file except in compliance with the License. You may obtain a copy of | ||
* the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT | ||
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the | ||
* License for the specific language governing permissions and limitations under | ||
* the License. | ||
*/ | ||
|
||
package com.google.cloud.tools.jib.image.json; | ||
|
||
import com.fasterxml.jackson.annotation.JsonIgnore; | ||
import com.fasterxml.jackson.annotation.JsonIgnoreProperties; | ||
import com.fasterxml.jackson.annotation.JsonProperty; | ||
import com.google.cloud.tools.jib.json.JsonTemplate; | ||
import java.util.Objects; | ||
import javax.annotation.Nullable; | ||
|
||
/** | ||
* Represents an item in the container configuration's {@code history} list. | ||
* | ||
* @see <a href=https://github.com/opencontainers/image-spec/blob/master/config.md#properties>OCI | ||
* image spec ({@code history} field)</a> | ||
*/ | ||
@JsonIgnoreProperties(ignoreUnknown = true) | ||
public class HistoryEntry implements JsonTemplate { | ||
|
||
/** The RFC 3339 formatted timestamp at which the image was created. */ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nit: specifically section 5.6 of RFC 3339 |
||
@JsonProperty("created") | ||
@Nullable | ||
private String creationTimestamp; | ||
|
||
/** The name of the author specified when committing the image. */ | ||
@JsonProperty("author") | ||
@Nullable | ||
private String author; | ||
|
||
/** The command used to build the image. */ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. s/image/layer/ |
||
@JsonProperty("created_by") | ||
@Nullable | ||
private String createdBy; | ||
|
||
/** A custom message set when creating the layer. */ | ||
@JsonProperty("comment") | ||
@Nullable | ||
private String comment; | ||
|
||
/** | ||
* Whether or not the entry corresponds to an empty layer ({@code @Nullable Boolean} to make field | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This comment should be updated too There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. To what? I already updated this from earlier. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The same as the |
||
* optional). | ||
*/ | ||
@JsonProperty("empty_layer") | ||
@Nullable | ||
private Boolean emptyLayer; | ||
|
||
public HistoryEntry() {} | ||
|
||
public HistoryEntry( | ||
@Nullable String creationTimestamp, | ||
@Nullable String author, | ||
@Nullable String createdBy, | ||
@Nullable String comment, | ||
@Nullable Boolean emptyLayer) { | ||
this.author = author; | ||
this.creationTimestamp = creationTimestamp; | ||
this.createdBy = createdBy; | ||
this.comment = comment; | ||
this.emptyLayer = emptyLayer; | ||
} | ||
|
||
/** | ||
* Returns whether or not the history object corresponds to a layer in the container. | ||
* | ||
* @return {@code true} if the history object corresponds to a layer in the container | ||
*/ | ||
@JsonIgnore | ||
public boolean hasLayer() { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nit: |
||
return emptyLayer == null ? false : emptyLayer; | ||
} | ||
|
||
@Override | ||
public boolean equals(Object other) { | ||
if (this == other) { | ||
return true; | ||
} | ||
if (other instanceof HistoryEntry) { | ||
HistoryEntry otherHistory = (HistoryEntry) other; | ||
return Objects.equals(otherHistory.creationTimestamp, creationTimestamp) | ||
&& Objects.equals(otherHistory.author, author) | ||
&& Objects.equals(otherHistory.createdBy, createdBy) | ||
&& Objects.equals(otherHistory.comment, comment) | ||
&& Objects.equals(otherHistory.emptyLayer, emptyLayer); | ||
} | ||
return false; | ||
} | ||
|
||
@Override | ||
public int hashCode() { | ||
return Objects.hash(author, creationTimestamp, createdBy, comment, emptyLayer); | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We probably want to go with a builder pattern here since it's unclear which field is which.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also, "auto-generated by Jib" might not be the text we want for
created_by
, sincecreated_by
refers to what created the layer the history entry refers to (and that layer was not "auto-generated by Jib") - I think "unknown" would be more suitable here.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's
comment
, notcreated_by
.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah right, then my first comment applies haha.