Skip to content

Commit

Permalink
Architecture and OS defaults & config
Browse files Browse the repository at this point in the history
Always pass in an architecture and an OS, because the library's defaults are hardcoded
Default to the architecture and OS reported by the Go runtime
Allow resource to override these defaults

based loosely on concourse#36 (which no longer applies cleanly)
  • Loading branch information
Infinoid committed Jan 1, 2022
1 parent 163c69f commit 39276ce
Showing 1 changed file with 32 additions and 1 deletion.
33 changes: 32 additions & 1 deletion 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 @@ -183,7 +192,29 @@ 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 Down

0 comments on commit 39276ce

Please sign in to comment.