Skip to content

Commit

Permalink
Merge pull request #36 from concourse/platform
Browse files Browse the repository at this point in the history
Allow configuration of `platform`
  • Loading branch information
Rui Yang authored Oct 24, 2022
2 parents 1989dd3 + f81eb3a commit 5f38949
Show file tree
Hide file tree
Showing 4 changed files with 81 additions and 3 deletions.
17 changes: 17 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,23 @@ differences:
<code>aws_role_arn</code> is also specified.
</td>
</tr>
<tr>
<td><code>platform</code> <em>(Optional)<br>(Experimental)</em></td>
<td>
<ul>
<li>
<code>architecture</code> <em>(Optional)</em>:
Architecture the image is built for (e.g. `amd64`, `arm64/v8`). If not
specified, will default to https://pkg.go.dev/runtime#GOARCH.
</li>
<li>
<code>os</code> <em>(Optional)</em>:
OS the image is built for (e.g. `linux`, `darwin`, `windows`). If not
specified, will default to https://pkg.go.dev/runtime#GOOS.
</li>
</ul>
</td>
</tr>
<tr>
<td><code>debug</code> <em>(Optional)<br>Default: false</em></td>
<td>
Expand Down
2 changes: 1 addition & 1 deletion suite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ const OLDER_LIBRARY_DIGEST = "sha256:2131f09e4044327fd101ca1fd4043e6f3ad921ae7ee

// see testdata/static/Dockerfile
const OLDER_STATIC_DIGEST = "sha256:7dabedca9d367a71d1cd646bd8d79f14de7b07327e4417ab691f5f13be5647a9"
const LATEST_STATIC_DIGEST = "sha256:29eddd288c312215a0af1070d26478b1f530a3137d4589314df1bc79e586860a"
const LATEST_STATIC_DIGEST = "sha256:6d89d782e9c924098af48daa6af692d14aba9f4a92338ea04603d99ef68395df"

// see testdata/static.tagged/Dockerfile
const LATEST_TAGGED_STATIC_DIGEST = "sha256:ecfdc2527b0a5d7d134be55234590336209e7feafc2ec364a930adf4a9c722e2"
Expand Down
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
21 changes: 21 additions & 0 deletions types_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package resource_test

import (
"encoding/json"
"runtime"

. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
Expand Down Expand Up @@ -83,6 +84,26 @@ var _ = Describe("Source", func() {
Expect(*m.getAuthorizationInput.RegistryIds[0]).To(Equal(source.AwsCredentials.AWSECRRegistryId))
})
})

Describe("platform", func() {
It("should set platform to default if not specified", func() {
source := resource.Source{
RawPlatform: &resource.PlatformField{OS: "some-os", Architecture: "some-arch"},
}

platform := source.Platform()
Expect(platform.Architecture).To(Equal("some-arch"))
Expect(platform.OS).To(Equal("some-os"))
})

It("should set platform to default if not specified", func() {
var source resource.Source

platform := source.Platform()
Expect(platform.Architecture).To(Equal(runtime.GOARCH))
Expect(platform.OS).To(Equal(runtime.GOOS))
})
})
})

type mockECR struct {
Expand Down

0 comments on commit 5f38949

Please sign in to comment.