Skip to content

Commit

Permalink
Add builder identity annotations.
Browse files Browse the repository at this point in the history
Use io.podman.version and fix inspect tests

Signed-off-by: caiges <caigesn@gmail.com>

Closes: #1917
Approved by: TomSweeneyRedHat
  • Loading branch information
caiges authored and rh-atomic-bot committed Nov 16, 2019
1 parent c5244fe commit 9ff68b3
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 3 deletions.
3 changes: 3 additions & 0 deletions cmd/buildah/commit.go
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,9 @@ func commitCmd(c *cobra.Command, args []string, iopts commitInputOptions) error
}
}

// Add builder identity information.
builder.SetLabel(buildah.BuilderIdentityAnnotation, buildah.Version)

options := buildah.CommitOptions{
PreferredManifestType: format,
Compression: compress,
Expand Down
7 changes: 7 additions & 0 deletions commit.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,13 @@ import (
"github.com/sirupsen/logrus"
)

const (
// BuilderIdentityAnnotation is the name of the annotation key containing
// the name and version of the producer of the image stored as an
// annotation on commit.
BuilderIdentityAnnotation = "io.buildah.version"
)

// CommitOptions can be used to alter how an image is committed.
type CommitOptions struct {
// PreferredManifestType is the preferred type of image manifest. The
Expand Down
12 changes: 12 additions & 0 deletions tests/commit.bats
Original file line number Diff line number Diff line change
Expand Up @@ -103,3 +103,15 @@ load helpers
buildah rm $cid
buildah rmi -a
}

@test "commit-builder-identity" {
cid=$(buildah from --pull --signature-policy ${TESTSDIR}/policy.json alpine)
buildah commit --signature-policy ${TESTSDIR}/policy.json $cid alpine-image

buildah_version=$(buildah --version | awk '{ print $3 }')
version=$(buildah inspect --format '{{ index .Docker.Config.Labels "io.buildah.version"}}' alpine-image)

[ "$version" == "$buildah_version" ]
buildah rm $cid
buildah rmi -f alpine-image
}
8 changes: 5 additions & 3 deletions tests/inspect.bats
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,13 @@ load helpers
}

@test "inspect" {
cid=$(buildah from --pull=false --signature-policy ${TESTSDIR}/policy.json alpine)
cid=$(buildah from --pull --signature-policy ${TESTSDIR}/policy.json alpine)
run_buildah commit --signature-policy ${TESTSDIR}/policy.json "$cid" alpine-image


buildah_version=$(buildah --version | awk '{ print $3 }')
out1=$(buildah inspect --format '{{.OCIv1.Config}}' alpine)
out2=$(buildah inspect --type image --format '{{.OCIv1.Config}}' alpine-image)
out2=$(buildah inspect --type image --format '{{.OCIv1.Config}}' alpine-image | sed "s/io.buildah.version:${buildah_version}//g")

[ "$out1" != "" ]
[ "$out1" = "$out2" ]
}
Expand Down

0 comments on commit 9ff68b3

Please sign in to comment.