Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow configuration of platform #36

Merged
merged 3 commits into from Oct 24, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
17 changes: 17 additions & 0 deletions README.md
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
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"
Copy link
Contributor

@xtremerui xtremerui Oct 22, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is changed when running

docker buildx build --platform linux/arm64/v8,linux/amd64 -t concourse/test-image-static:latest --push .

for building multi-arch image for testing.


// see testdata/static.tagged/Dockerfile
const LATEST_TAGGED_STATIC_DIGEST = "sha256:ecfdc2527b0a5d7d134be55234590336209e7feafc2ec364a930adf4a9c722e2"
Expand Down
44 changes: 42 additions & 2 deletions types.go
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
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