Skip to content

Commit 8217a9e

Browse files
authored
fix: add option to ignore ref annotation (#436)
1 parent ec9020e commit 8217a9e

File tree

4 files changed

+14
-19
lines changed

4 files changed

+14
-19
lines changed

.github/workflows/integration-tests.yml

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,6 @@ on: [push, pull_request]
55

66
permissions: read-all
77

8-
concurrency:
9-
# On master/release, we don't want any jobs cancelled
10-
# On PR branches, we cancel the job if new commits are pushed
11-
# More info: https://stackoverflow.com/a/70972844/1261287
12-
group: ${{ github.ref }}
13-
cancel-in-progress: ${{ github.ref != 'refs/heads/master' }}
14-
158
jobs:
169
build:
1710
name: PR unit tests

bazel/container_structure_test.bzl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ readonly image=$(rlocation {image_path})
3333
# When the image points to a folder, we can read the index.json file inside
3434
if [[ -d "$image" ]]; then
3535
readonly DIGEST=$("$jq" -r '.manifests[0].digest | sub(":"; "-")' "$image/index.json")
36-
exec "$st" test --driver {driver} {fixed_args} --default-image-tag "registry.structure_test.oci.local/image:$DIGEST" $@
36+
exec "$st" test --driver {driver} {fixed_args} --default-image-tag "cst.oci.local/$DIGEST:$DIGEST" $@
3737
else
3838
exec "$st" test --driver {driver} {fixed_args} $@
3939
fi
@@ -53,7 +53,7 @@ def _structure_test_impl(ctx):
5353
# https://github.com/GoogleContainerTools/container-structure-test/blob/5e347b66fcd06325e3caac75ef7dc999f1a9b614/cmd/container-structure-test/app/cmd/test.go#L110
5454
if ctx.attr.driver != "docker":
5555
fail("when the 'driver' attribute is not 'docker', then the image must be a .tar file")
56-
fixed_args.extend(["--image-from-oci-layout", "$(rlocation %s)" % image_path])
56+
fixed_args.extend(["--ignore-ref-annotation", "--image-from-oci-layout", "$(rlocation %s)" % image_path])
5757

5858
for arg in ctx.files.configs:
5959
fixed_args.extend(["--config", "$(rlocation %s)" % to_rlocation_path(ctx, arg)])

cmd/container-structure-test/app/cmd/test.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,7 @@ func run(out io.Writer) error {
137137
var tag name.Tag
138138

139139
ref := desc.Annotations[v1.AnnotationRefName]
140-
if ref != "" {
140+
if ref != "" && !opts.IgnoreRefAnnotation {
141141
tag, err = name.NewTag(ref)
142142
if err != nil {
143143
logrus.Fatalf("could not parse ref annotation %s: %v", v1.AnnotationRefName, err)
@@ -231,6 +231,7 @@ func AddTestFlags(cmd *cobra.Command) {
231231
cmd.Flags().StringVarP(&opts.ImagePath, "image", "i", "", "path to test image")
232232
cmd.Flags().StringVar(&opts.ImageFromLayout, "image-from-oci-layout", "", "path to the oci layout to test against")
233233
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.")
234+
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")
234235
cmd.MarkFlagsMutuallyExclusive("image", "image-from-oci-layout")
235236
cmd.Flags().StringVarP(&opts.Driver, "driver", "d", "docker", "driver to use when running tests")
236237
cmd.Flags().StringVar(&opts.Metadata, "metadata", "", "path to image metadata file")

pkg/config/options.go

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -17,15 +17,16 @@ package config
1717
import "github.com/GoogleContainerTools/container-structure-test/pkg/types/unversioned"
1818

1919
type StructureTestOptions struct {
20-
ImagePath string
21-
ImageFromLayout string
22-
DefaultImageTag string
23-
Driver string
24-
Runtime string
25-
Platform string
26-
Metadata string
27-
TestReport string
28-
ConfigFiles []string
20+
ImagePath string
21+
ImageFromLayout string
22+
DefaultImageTag string
23+
IgnoreRefAnnotation bool
24+
Driver string
25+
Runtime string
26+
Platform string
27+
Metadata string
28+
TestReport string
29+
ConfigFiles []string
2930

3031
JSON bool
3132
Output unversioned.OutputValue

0 commit comments

Comments
 (0)