Skip to content

Commit

Permalink
fix: add option to ignore ref annotation (#436)
Browse files Browse the repository at this point in the history
  • Loading branch information
thesayyn authored May 3, 2024
1 parent ec9020e commit 8217a9e
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 19 deletions.
7 changes: 0 additions & 7 deletions .github/workflows/integration-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,6 @@ on: [push, pull_request]

permissions: read-all

concurrency:
# On master/release, we don't want any jobs cancelled
# On PR branches, we cancel the job if new commits are pushed
# More info: https://stackoverflow.com/a/70972844/1261287
group: ${{ github.ref }}
cancel-in-progress: ${{ github.ref != 'refs/heads/master' }}

jobs:
build:
name: PR unit tests
Expand Down
4 changes: 2 additions & 2 deletions bazel/container_structure_test.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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)])
Expand Down
3 changes: 2 additions & 1 deletion cmd/container-structure-test/app/cmd/test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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")
Expand Down
19 changes: 10 additions & 9 deletions pkg/config/options.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 8217a9e

Please sign in to comment.