From 96cd9f56d86234e2667f24340e891e56b5216397 Mon Sep 17 00:00:00 2001 From: Jason Hall Date: Tue, 26 Sep 2023 10:15:09 -0400 Subject: [PATCH] fix: build single-arch images compatibly with apko CLI (#173) When asked to build a single-arch image, apko CLI builds an index containing one manifest. By contrast, before this PR, tf-apko would build a single-arch _image_ in this case. This meant that the check-compatibility test (which tries to use the apko CLI to rebuild an image from the attested locked apko config, and get the same digest) would not get the same digest when building single-arch images. Signed-off-by: Jason Hall --- internal/provider/build.go | 11 ----------- internal/provider/resource_build_test.go | 4 ++-- 2 files changed, 2 insertions(+), 13 deletions(-) diff --git a/internal/provider/build.go b/internal/provider/build.go index b90ba3c..64f9550 100644 --- a/internal/provider/build.go +++ b/internal/provider/build.go @@ -202,17 +202,6 @@ func doBuild(ctx context.Context, data BuildResourceModel) (v1.Hash, coci.Signed if err := errg.Wait(); err != nil { return v1.Hash{}, nil, nil, err } - // If we built a final image, then return that instead of wrapping it in an - // image index. - if len(imgs) == 1 { - for _, img := range imgs { - h, err := img.Digest() - if err != nil { - return v1.Hash{}, nil, nil, err - } - return h, img, sboms, nil - } - } // generate the index finalDigest, idx, err := oci.GenerateIndex(ctx, *ic2, imgs) diff --git a/internal/provider/resource_build_test.go b/internal/provider/resource_build_test.go index ea44ae4..83271cd 100644 --- a/internal/provider/resource_build_test.go +++ b/internal/provider/resource_build_test.go @@ -224,7 +224,7 @@ resource "apko_build" "foo" { resource.TestCheckResourceAttr("apko_build.foo", "repo", repostr), resource.TestCheckResourceAttr("apko_build.foo", "image_ref", // With pinned packages we should always get this digest. - repo.Digest("sha256:14f90e68f2603e992cc51916cc70113b1037bc2c5c6566ca26fec292753f3360").String()), + repo.Digest("sha256:a753adeb6de448f76e829c3d09deabdc9c183f30242b78e42d4c65ada17aa607").String()), // Check that the build's amd64 predicate exists, the digest // matches, and the creation timestamp is what we expect. @@ -293,7 +293,7 @@ resource "apko_build" "foo" { resource.TestCheckResourceAttr("apko_build.foo", "repo", repostr), resource.TestCheckResourceAttr("apko_build.foo", "image_ref", // With pinned packages we should always get this digest. - repo.Digest("sha256:7ecfd5ca0cec575e96ff46bf53284950ee80e5d1211cba47a51189debe41c79a").String()), + repo.Digest("sha256:8cee7e4467cc4361cc0754255fb93856eb14a0ecddafc247d1babf79a41d2e1c").String()), // Check that the build's amd64 predicate exists, the digest // matches, and the creation timestamp is what we expect.