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

Use daemon or runtime provided arch instead of amd64 #232

Merged
merged 1 commit into from
Nov 2, 2023
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions local/local.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ type DockerClient interface {
ImageSave(ctx context.Context, images []string) (io.ReadCloser, error)
ImageTag(ctx context.Context, image, ref string) error
Info(ctx context.Context) (types.Info, error)
ServerVersion(ctx context.Context) (types.Version, error)
}

// getters
Expand Down
14 changes: 8 additions & 6 deletions local/local_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,17 +43,19 @@ func testImage(t *testing.T, when spec.G, it spec.S) {
var (
dockerClient client.CommonAPIClient
daemonOS string
daemonArchitecture string
runnableBaseImageName string
)

it.Before(func() {
var err error
dockerClient = h.DockerCli(t)

daemonInfo, err := dockerClient.Info(context.TODO())
versionInfo, err := dockerClient.ServerVersion(context.TODO())
h.AssertNil(t, err)

daemonOS = daemonInfo.OSType
daemonOS = versionInfo.Os
daemonArchitecture = versionInfo.Arch
runnableBaseImageName = h.RunnableBaseImage(daemonOS)

h.PullIfMissing(t, dockerClient, runnableBaseImageName)
Expand All @@ -79,11 +81,11 @@ func testImage(t *testing.T, when spec.G, it spec.S) {
inspect, _, err := dockerClient.ImageInspectWithRaw(context.TODO(), img.Name())
h.AssertNil(t, err)

daemonInfo, err := dockerClient.Info(context.TODO())
versionInfo, err := dockerClient.ServerVersion(context.TODO())
h.AssertNil(t, err)

h.AssertEq(t, inspect.Os, daemonInfo.OSType)
h.AssertEq(t, inspect.Architecture, "amd64")
h.AssertEq(t, inspect.Os, versionInfo.Os)
h.AssertEq(t, inspect.Architecture, versionInfo.Arch)
h.AssertEq(t, inspect.RootFS.Type, "layers")
})
})
Expand Down Expand Up @@ -210,7 +212,7 @@ func testImage(t *testing.T, when spec.G, it spec.S) {
inspect, _, err := dockerClient.ImageInspectWithRaw(context.TODO(), img.Name())
h.AssertNil(t, err)
h.AssertEq(t, inspect.Os, daemonOS)
h.AssertEq(t, inspect.Architecture, "amd64")
h.AssertEq(t, inspect.Architecture, daemonArchitecture)
h.AssertEq(t, inspect.RootFS.Type, "layers")

h.AssertEq(t, img.Found(), true)
Expand Down
6 changes: 3 additions & 3 deletions local/new.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,14 +86,14 @@ func NewImage(repoName string, dockerClient DockerClient, ops ...ImageOption) (*
}

func defaultPlatform(dockerClient DockerClient) (imgutil.Platform, error) {
daemonInfo, err := dockerClient.Info(context.Background())
versionInfo, err := dockerClient.ServerVersion(context.Background())
if err != nil {
return imgutil.Platform{}, err
}

return imgutil.Platform{
OS: daemonInfo.OSType,
Architecture: "amd64",
OS: versionInfo.Os,
Architecture: versionInfo.Arch,
}, nil
}

Expand Down
3 changes: 2 additions & 1 deletion remote/new.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package remote
import (
"io"
"net/http"
"runtime"
"strings"
"time"

Expand Down Expand Up @@ -93,7 +94,7 @@ func NewImage(repoName string, keychain authn.Keychain, ops ...ImageOption) (*Im
func defaultPlatform() imgutil.Platform {
return imgutil.Platform{
OS: "linux",
Architecture: "amd64",
Architecture: runtime.GOARCH,
}
}

Expand Down
5 changes: 3 additions & 2 deletions remote/remote_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"io"
"log"
"os"
"runtime"
"strings"
"testing"
"time"
Expand Down Expand Up @@ -102,7 +103,7 @@ func testImage(t *testing.T, when spec.G, it spec.S) {

arch, err := img.Architecture()
h.AssertNil(t, err)
h.AssertEq(t, arch, "amd64")
h.AssertEq(t, arch, runtime.GOARCH)
})

it("fails to save to read-only registry", func() {
Expand Down Expand Up @@ -274,7 +275,7 @@ func testImage(t *testing.T, when spec.G, it spec.S) {

arch, err := img.Architecture()
h.AssertNil(t, err)
h.AssertEq(t, arch, "amd64")
h.AssertEq(t, arch, runtime.GOARCH)

readCloser, err := img.GetLayer(existingLayerSha)
h.AssertNil(t, err)
Expand Down