From 94c3725a3bec82f851fe74c2094d30cf539a8375 Mon Sep 17 00:00:00 2001 From: thesayyn Date: Fri, 3 May 2024 12:11:41 -0700 Subject: [PATCH] fix: add option to ignore ref annotation --- .github/workflows/integration-tests.yml | 10 ++-------- bazel/container_structure_test.bzl | 4 ++-- cmd/container-structure-test/app/cmd/test.go | 3 ++- pkg/config/options.go | 19 ++++++++++--------- 4 files changed, 16 insertions(+), 20 deletions(-) diff --git a/.github/workflows/integration-tests.yml b/.github/workflows/integration-tests.yml index b466a2b0..865e1d95 100644 --- a/.github/workflows/integration-tests.yml +++ b/.github/workflows/integration-tests.yml @@ -17,17 +17,11 @@ jobs: name: PR unit tests strategy: matrix: - os: [ubuntu-latest, macos-latest] + os: [ubuntu-latest] runs-on: ${{ matrix.os }} steps: - - name: start docker - if: ${{ matrix.os == 'macos-latest' }} - run: | - brew install docker - colima start - echo "DOCKER_HOST=unix:///Users/runner/.colima/default/docker.sock" >> $GITHUB_ENV - + - name: Set up Go uses: actions/setup-go@v5 with: diff --git a/bazel/container_structure_test.bzl b/bazel/container_structure_test.bzl index ba978800..9a01e233 100644 --- a/bazel/container_structure_test.bzl +++ b/bazel/container_structure_test.bzl @@ -33,7 +33,7 @@ readonly image=$(rlocation {image_path}) # When the image points to a folder, we can read the index.json file inside if [[ -d "$image" ]]; then readonly DIGEST=$("$jq" -r '.manifests[0].digest | sub(":"; "-")' "$image/index.json") - exec "$st" test --driver {driver} {fixed_args} --default-image-tag "registry.structure_test.oci.local/image:$DIGEST" $@ + exec "$st" test --driver {driver} {fixed_args} --default-image-tag "cst.oci.local/$DIGEST:$DIGEST" $@ else exec "$st" test --driver {driver} {fixed_args} $@ fi @@ -53,7 +53,7 @@ def _structure_test_impl(ctx): # https://github.com/GoogleContainerTools/container-structure-test/blob/5e347b66fcd06325e3caac75ef7dc999f1a9b614/cmd/container-structure-test/app/cmd/test.go#L110 if ctx.attr.driver != "docker": fail("when the 'driver' attribute is not 'docker', then the image must be a .tar file") - fixed_args.extend(["--image-from-oci-layout", "$(rlocation %s)" % image_path]) + fixed_args.extend(["--ignore-ref-annotation", "--image-from-oci-layout", "$(rlocation %s)" % image_path]) for arg in ctx.files.configs: fixed_args.extend(["--config", "$(rlocation %s)" % to_rlocation_path(ctx, arg)]) diff --git a/cmd/container-structure-test/app/cmd/test.go b/cmd/container-structure-test/app/cmd/test.go index d44d61ce..14953622 100644 --- a/cmd/container-structure-test/app/cmd/test.go +++ b/cmd/container-structure-test/app/cmd/test.go @@ -137,7 +137,7 @@ func run(out io.Writer) error { var tag name.Tag ref := desc.Annotations[v1.AnnotationRefName] - if ref != "" { + if ref != "" && !opts.IgnoreRefAnnotation { tag, err = name.NewTag(ref) if err != nil { logrus.Fatalf("could not parse ref annotation %s: %v", v1.AnnotationRefName, err) @@ -231,6 +231,7 @@ func AddTestFlags(cmd *cobra.Command) { cmd.Flags().StringVarP(&opts.ImagePath, "image", "i", "", "path to test image") cmd.Flags().StringVar(&opts.ImageFromLayout, "image-from-oci-layout", "", "path to the oci layout to test against") cmd.Flags().StringVar(&opts.DefaultImageTag, "default-image-tag", "", "default image tag to used when loading images to the daemon. required when --image-from-oci-layout refers to a oci layout lacking the reference annotation.") + cmd.Flags().BoolVar(&opts.IgnoreRefAnnotation, "ignore-ref-annotation", false, "ignore the org.opencontainers.image.ref.name and use --default-image-tag when loading to daemon") cmd.MarkFlagsMutuallyExclusive("image", "image-from-oci-layout") cmd.Flags().StringVarP(&opts.Driver, "driver", "d", "docker", "driver to use when running tests") cmd.Flags().StringVar(&opts.Metadata, "metadata", "", "path to image metadata file") diff --git a/pkg/config/options.go b/pkg/config/options.go index e819f1e4..ac1dbe9b 100644 --- a/pkg/config/options.go +++ b/pkg/config/options.go @@ -17,15 +17,16 @@ package config import "github.com/GoogleContainerTools/container-structure-test/pkg/types/unversioned" type StructureTestOptions struct { - ImagePath string - ImageFromLayout string - DefaultImageTag string - Driver string - Runtime string - Platform string - Metadata string - TestReport string - ConfigFiles []string + ImagePath string + ImageFromLayout string + DefaultImageTag string + IgnoreRefAnnotation bool + Driver string + Runtime string + Platform string + Metadata string + TestReport string + ConfigFiles []string JSON bool Output unversioned.OutputValue