From e2da5470753e1cd31236ae9b5b0636c21431a559 Mon Sep 17 00:00:00 2001 From: Ramkumar Chinchani Date: Fri, 16 Sep 2022 20:31:30 +0000 Subject: [PATCH] add support for user-specified annotations Signed-off-by: Ramkumar Chinchani --- build.go | 5 +++++ cache_test.go | 2 +- doc/stacker_yaml.md | 13 +++++++++++++ test/annotations.bats | 31 +++++++++++++++++++++++++++++++ types/layer.go | 1 + 5 files changed, 51 insertions(+), 1 deletion(-) create mode 100644 test/annotations.bats diff --git a/build.go b/build.go index 6a5dae8ca..e19f6565c 100644 --- a/build.go +++ b/build.go @@ -219,6 +219,11 @@ func (b *Builder) updateOCIConfigForOutput(sf *types.Stackerfile, s types.Storag return err } + // add user-defined annotations + for k, v := range l.Annotations { + annotations[k] = v + } + // compute the git version for the directory that the stacker file is // in. we don't care if it's not a git directory, because in that case // we'll fall back to putting the whole stacker file contents in the diff --git a/cache_test.go b/cache_test.go index 8e29cbf43..bb09249f5 100644 --- a/cache_test.go +++ b/cache_test.go @@ -126,5 +126,5 @@ func TestCacheEntryChanged(t *testing.T) { // This test works because the type information is included in the // hashstructure hash above, so using a zero valued CacheEntry is // enough to capture changes in types. - assert.Equal(uint64(0x99dd94c023d7ccc6), h) + assert.Equal(uint64(0x98ab47c70ff0b70), h) } diff --git a/doc/stacker_yaml.md b/doc/stacker_yaml.md index 00f0636b9..8c4a85454 100644 --- a/doc/stacker_yaml.md +++ b/doc/stacker_yaml.md @@ -218,3 +218,16 @@ In this particular case the parent folder of the current folder, let's call it When `stacker build -f parent/folder1/stacker.yaml` is invoked, stacker would search for the other two stacker.yaml files and build them first, before building the stacker.yaml specified in the command line. + +##### `annotations` + +`annotations` is a user-specified key value map that will be included in the final OCI image. + + annotations: + a.b.c.key: abc_val + p.q.r.key: pqr_val + +While `config` section supports a similar `labels`, it is more pertitent to the +image runtime. On the other hand, `annotations` is intended to be +image-specific metadata aligned with the +[annotations in the image spec](https://github.com/opencontainers/image-spec/blob/main/annotations.md). diff --git a/test/annotations.bats b/test/annotations.bats new file mode 100644 index 000000000..82feba6af --- /dev/null +++ b/test/annotations.bats @@ -0,0 +1,31 @@ +load helpers + +function setup() { + stacker_setup +} + +function teardown() { + cleanup +} + +@test "annotations work" { + cat > stacker.yaml <