Skip to content

Commit

Permalink
Grab the image that matches the arch of the binary
Browse files Browse the repository at this point in the history
Crane defaults to "linux/amd64" as the platform, unless an option
is passed with WithPlatform. This defaults to an OS of "linux", and
an architecture of runtime.GOARCH, which is basically set at build
time.

Additional work will be required to process all arches of an image
in one go.

Related #807

Signed-off-by: Brad P. Crochet <brad@redhat.com>
  • Loading branch information
bcrochet committed Nov 7, 2022
1 parent 3de5a41 commit fdfe262
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 0 deletions.
7 changes: 7 additions & 0 deletions certification/internal/engine/engine.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import (
"path"
"path/filepath"
"regexp"
goruntime "runtime"
"sort"
"strings"
"sync"
Expand All @@ -28,8 +29,10 @@ import (

"github.com/google/go-containerregistry/pkg/crane"
"github.com/google/go-containerregistry/pkg/name"
cranev1 "github.com/google/go-containerregistry/pkg/v1"
"github.com/google/go-containerregistry/pkg/v1/cache"
"github.com/google/go-containerregistry/pkg/v1/remote"

log "github.com/sirupsen/logrus"
)

Expand Down Expand Up @@ -76,6 +79,10 @@ func (c *CraneEngine) ExecuteChecks(ctx context.Context) error {
authn.WithDockerConfig(c.Config.DockerConfig()),
),
),
crane.WithPlatform(&cranev1.Platform{
OS: "linux",
Architecture: goruntime.GOARCH,
}),
retryOnceAfter(5 * time.Second),
}

Expand Down
6 changes: 6 additions & 0 deletions certification/internal/policy/container/has_unique_tag.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,14 @@ package container
import (
"context"
"fmt"
goruntime "runtime"
"strings"

"github.com/redhat-openshift-ecosystem/openshift-preflight/certification"
"github.com/redhat-openshift-ecosystem/openshift-preflight/certification/internal/authn"

"github.com/google/go-containerregistry/pkg/crane"
cranev1 "github.com/google/go-containerregistry/pkg/v1"
)

var _ certification.Check = &hasUniqueTagCheck{}
Expand Down Expand Up @@ -57,6 +59,10 @@ func (p *hasUniqueTagCheck) getDataToValidate(ctx context.Context, image string)
options := []crane.Option{
crane.WithContext(ctx),
crane.WithAuthFromKeychain(authn.PreflightKeychain(authn.WithDockerConfig(p.dockercfg))),
crane.WithPlatform(&cranev1.Platform{
OS: "linux",
Architecture: goruntime.GOARCH,
}),
}

return crane.ListTags(image, options...)
Expand Down
6 changes: 6 additions & 0 deletions certification/runtime/assets.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,13 @@ package runtime
import (
"context"
"fmt"
goruntime "runtime"
"strings"

"github.com/redhat-openshift-ecosystem/openshift-preflight/certification/internal/authn"

"github.com/google/go-containerregistry/pkg/crane"
cranev1 "github.com/google/go-containerregistry/pkg/v1"
log "github.com/sirupsen/logrus"
)

Expand All @@ -26,6 +28,10 @@ func imageList(ctx context.Context) []string {
options := []crane.Option{
crane.WithContext(ctx),
crane.WithAuthFromKeychain(authn.PreflightKeychain()),
crane.WithPlatform(&cranev1.Platform{
OS: "linux",
Architecture: goruntime.GOARCH,
}),
}

imageList := make([]string, 0, len(images))
Expand Down

0 comments on commit fdfe262

Please sign in to comment.