Skip to content

Commit

Permalink
Allow configuration of platform
Browse files Browse the repository at this point in the history
Without the explcit use of `platform`, the underlying library ends up
using its own default (amd64). This is a problem for those running the
resource in other architectures.

To achieve that:

- bumps `go-containerregistry` to make
- sets `Platform` to the `{GOOS, GOARCH}` by default, allowing the
  possibility of having that set through a `platform` field in the
  resource config.

Example:

```yaml
resources:
- type: registry-image
  name: busybox-arm
  source:
    repository: busybox
    platform: {os: linux, architecture: arm}
```

the original commit is modified based on
Infinoid@39276ce

Signed-off-by: Ciro S. Costa <[email protected]>
Signed-off-by: Rui Yang <[email protected]>
  • Loading branch information
Ciro S. Costa authored and Rui Yang committed Oct 21, 2022
1 parent 1989dd3 commit f1e022d
Showing 1 changed file with 42 additions and 2 deletions.
44 changes: 42 additions & 2 deletions types.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (
"net/url"
"os"
"path/filepath"
"runtime"
"strings"

"github.com/aws/aws-sdk-go/aws"
Expand All @@ -21,6 +22,7 @@ import (
"github.com/aws/aws-sdk-go/service/ecr/ecriface"
"github.com/google/go-containerregistry/pkg/authn"
"github.com/google/go-containerregistry/pkg/name"
v1 "github.com/google/go-containerregistry/pkg/v1"
"github.com/google/go-containerregistry/pkg/v1/remote"
"github.com/google/go-containerregistry/pkg/v1/remote/transport"
"github.com/sirupsen/logrus"
Expand Down Expand Up @@ -75,6 +77,11 @@ type RegistryMirror struct {
BasicCredentials
}

type PlatformField struct {
Architecture string `json:"architecture,omitempty"`
OS string `json:"os,omitempty"`
}

type Source struct {
Repository string `json:"repository"`

Expand All @@ -96,6 +103,8 @@ type Source struct {

DomainCerts []string `json:"ca_certs,omitempty"`

RawPlatform *PlatformField `json:"platform,omitempty"`

Debug bool `json:"debug,omitempty"`
}

Expand Down Expand Up @@ -210,7 +219,33 @@ func (source Source) AuthOptions(repo name.Repository, scopeActions []string) ([
return nil, fmt.Errorf("initialize transport: %w", err)
}

return []remote.Option{remote.WithAuth(auth), remote.WithTransport(rt)}, nil
plat := source.Platform()
v1plat := v1.Platform{
Architecture: plat.Architecture,
OS: plat.OS,
}

return []remote.Option{remote.WithAuth(auth), remote.WithTransport(rt), remote.WithPlatform(v1plat)}, nil
}

func (source *Source) Platform() PlatformField {
DefaultArchitecture := runtime.GOARCH
DefaultOS := runtime.GOOS

p := source.RawPlatform
if p == nil {
p = &PlatformField{}
}

if p.Architecture == "" {
p.Architecture = DefaultArchitecture
}

if p.OS == "" {
p.OS = DefaultOS
}

return *p
}

func (source Source) NewRepository() (name.Repository, error) {
Expand All @@ -237,12 +272,17 @@ type ContentTrust struct {
BasicCredentials
}

/* Create notary config directory with following structure
/*
Create notary config directory with following structure
├── gcr-config.json
└── trust
└── private
└── <private-key-id>.key
└── tls
└── <notary-host>
├── client.cert
└── client.key
Expand Down

0 comments on commit f1e022d

Please sign in to comment.