Skip to content

Commit

Permalink
Merge pull request #3482 from rhatdan/timestamp
Browse files Browse the repository at this point in the history
Add epoch time field to buildah images
  • Loading branch information
openshift-merge-robot authored Aug 26, 2021
2 parents 9855bc7 + 71e1ebf commit a20b5f4
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 7 deletions.
4 changes: 4 additions & 0 deletions cmd/buildah/images.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ type jsonImage struct {
Digest string `json:"digest"`
CreatedAt string `json:"createdat"`
Size string `json:"size"`
Created int64 `json:"created"`
CreatedAtRaw time.Time `json:"createdatraw"`
ReadOnly bool `json:"readonly"`
History []string `json:"history"`
Expand All @@ -35,6 +36,7 @@ type imageOutputParams struct {
ID string
Name string
Digest string
Created int64
CreatedAt string
Size string
CreatedAtRaw time.Time
Expand Down Expand Up @@ -204,6 +206,7 @@ func formatImagesJSON(images []*libimage.Image, opts imageOptions) error {
jsonImages = append(jsonImages,
jsonImage{
CreatedAtRaw: created,
Created: created.Unix(),
CreatedAt: units.HumanDuration(time.Since(created)) + " ago",
Digest: image.Digest().String(),
ID: truncateID(image.ID(), opts.truncate),
Expand Down Expand Up @@ -246,6 +249,7 @@ func formatImages(images []*libimage.Image, opts imageOptions) error {
}
created := image.Created()
outputParam.CreatedAtRaw = created
outputParam.Created = created.Unix()
outputParam.CreatedAt = units.HumanDuration(time.Since(created)) + " ago"
outputParam.Digest = image.Digest().String()
outputParam.ID = truncateID(image.ID(), opts.truncate)
Expand Down
11 changes: 6 additions & 5 deletions docs/buildah-images.md
Original file line number Diff line number Diff line change
Expand Up @@ -58,14 +58,15 @@ Valid placeholders for the Go template are listed below:

| **Placeholder** | **Description** |
| --------------- | -----------------------------------------|
| .Tag | Image Tag |
| .ID | Image ID |
| .Name | Image Name |
| .Digest | Image Digest |
| .Created | Creation date in epoch time |
| .CreatedAt | Creation date Pretty Formatted |
| .Size | Image Size |
| .CreatedAtRaw | Creation date in raw format |
| .Digest | Image Digest |
| .ID | Image ID |
| .Name | Image Name |
| .ReadOnly | Indicates if image came from a R/O store |
| .Size | Image Size |
| .Tag | Image Tag |

**--history**

Expand Down
11 changes: 9 additions & 2 deletions tests/bud.bats
Original file line number Diff line number Diff line change
Expand Up @@ -2453,20 +2453,24 @@ EOM

@test "bud timestamp" {
_prefetch alpine
run_buildah build --timestamp=0 --quiet --pull=false --signature-policy ${TESTSDIR}/policy.json -t timestamp -f Dockerfile.1 ${TESTSDIR}/bud/cache-stages
timestamp=40
run_buildah build --timestamp=${timestamp} --quiet --pull=false --signature-policy ${TESTSDIR}/policy.json -t timestamp -f Dockerfile.1 ${TESTSDIR}/bud/cache-stages
cid=$output
run_buildah inspect --format '{{ .Docker.Created }}' timestamp
expect_output --substring "1970-01-01"
run_buildah inspect --format '{{ .OCIv1.Created }}' timestamp
expect_output --substring "1970-01-01"
run_buildah inspect --format '{{ .History }}' timestamp
expect_output --substring '1970-01-01 00:00:00'
expect_output --substring "1970-01-01 00:00:${timestamp}"

run_buildah from --quiet --pull=false --signature-policy ${TESTSDIR}/policy.json timestamp
cid=$output
run_buildah run $cid ls -l /tmpfile
expect_output --substring "1970"

run_buildah images --format "{{.Created}}" timestamp
expect_output ${timestamp}

rm -rf ${TESTDIR}/tmp
}

Expand All @@ -2476,6 +2480,9 @@ EOM
run_buildah build --timestamp=${TIMESTAMP} --quiet --pull=false --signature-policy ${TESTSDIR}/policy.json -t timestamp -f Dockerfile.1 ${TESTSDIR}/bud/cache-stages
cid=$output

run_buildah images --format "{{.Created}}" timestamp
expect_output ${timestamp}

run_buildah build --timestamp=${TIMESTAMP} --quiet --pull=false --signature-policy ${TESTSDIR}/policy.json -t timestamp -f Dockerfile.1 ${TESTSDIR}/bud/cache-stages
expect_output "$cid"

Expand Down

0 comments on commit a20b5f4

Please sign in to comment.