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

Enhance default platform comparision for image shareablity #2810 #2834

Merged
merged 1 commit into from
Mar 5, 2024

Conversation

Shubhranshu153
Copy link
Contributor

Partially Addresses: #2810

There are cases where --platform flag may be passed during nerdctl build. In such a situation if platform matches the runtime platform the image is shareable.

func isMatchingRuntimePlatform(platform string) bool {
p, err := platforms.Parse(platform)
if err != nil {
return false
Copy link
Contributor

Choose a reason for hiding this comment

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

Should we log this error?

Suggested change
return false
log.L.WithError(err).Errorf("failed to parse platform")
return false

Copy link
Contributor Author

Choose a reason for hiding this comment

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

i don't think its important to log here, as the Parse will be called elsewhere and be handled. Here it just important to figure out if the image is shareable, if any thing goes wrong it will attempt to create a non-shareable image.

@AkihiroSuda AkihiroSuda requested a review from ktock February 22, 2024 05:16
@ktock
Copy link
Member

ktock commented Feb 22, 2024

Thanks. can we add a test for len(platform) == 1 case?

@Shubhranshu153
Copy link
Contributor Author

Thanks. can we add a test for len(platform) == 1 case?

Will add a test case.

@Shubhranshu153
Copy link
Contributor Author

@ktock
was thinking of adding a unit test file for build.go called build_test.go and add unit test for is_shreable() func. I dont see any other place where this can go. Let me know your thoughts.

@ktock
Copy link
Member

ktock commented Feb 23, 2024

Maybe we can add a test case here:

func TestBuildFromContainerd(t *testing.T) {

@Shubhranshu153 Shubhranshu153 force-pushed the fix-default-platform branch 2 times, most recently from 3735561 to 818d105 Compare February 24, 2024 00:02
@Shubhranshu153
Copy link
Contributor Author

Not sure about the test failures, some of the test seem flaky.

@ktock
Copy link
Member

ktock commented Feb 24, 2024

Test failed on CI: https://github.com/containerd/nerdctl/actions/runs/8026538828/job/21929197370?pr=2834#step:7:13

=== RUN   TestBuildIsShareableForCompatiblePlatform
    builder_build_test.go:86: assertion failed: 
        Command:  /usr/bin/docker build /tmp/nerdctl-build-test2104019243 -t nerdctl-testbuildisshareableforcompatibleplatform --platform linux/arm/v7 --progress plain
        ExitCode: 0
        Stdout:   
        Stderr:   #0 building with "default" instance using docker driver
        
        #1 [internal] load .dockerignore
        #1 transferring context: 2B done
        #1 DONE 0.0s
        
        #2 [internal] load build definition from Dockerfile
        #2 transferring dockerfile: 127B done
        #2 DONE 0.0s
        
        #3 [internal] load metadata for ghcr.io/stargz-containers/alpine:3.13-org
        #3 DONE 0.2s
        
        #4 [1/1] FROM ghcr.io/stargz-containers/alpine:3.13-org@sha256:ec14c7992a97fc11425907e908340c6c3d6ff602f5f13d899e6b7027c9b4133a
        #4 CACHED
        
        #5 exporting to image
        #5 exporting layers done
        #5 writing image sha256:6f5021027f826fc1f7353f081bd8ff6364f8db76b5ce718a9007e023faf033ab done
        #5 naming to docker.io/library/nerdctl-testbuildisshareableforcompatibleplatform done
        #5 DONE 0.0s
        
        
        Failures:
        Expected stderr to contain "tarball"
--- FAIL: TestBuildIsShareableForCompatiblePlatform (2.11s)

@Shubhranshu153
Copy link
Contributor Author

Fixed the above docker failed test.

@AkihiroSuda AkihiroSuda requested a review from ktock February 26, 2024 20:02
Copy link
Member

@ktock ktock left a comment

Choose a reason for hiding this comment

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

Thanks

@AkihiroSuda AkihiroSuda added this to the v2.0.0 milestone Feb 27, 2024
go.mod Outdated Show resolved Hide resolved
@Shubhranshu153
Copy link
Contributor Author

The lint error seems to be some sort of caching issue, is it possible to have no-cache option.
integ test not sure why it failed.

"testing"

"github.com/containerd/containerd/platforms"
"gotest.tools/v3/assert"
Copy link
Member

Choose a reason for hiding this comment

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

  Running [/home/runner/golangci-lint-1.55.2-linux-amd64/golangci-lint run --out-format=github-actions --verbose] in [] ...
  Error: File is not `gofmt`-ed with `-s` (gofmt)

…#2810

Partially Addresses: containerd#2810

There are cases where --platform flag may be passed during nerdctl build. In such a situation if
platform matches the runtime platform the image is shareable.

Signed-off-by: Shubhranshu Mahapatra <[email protected]>
Copy link
Member

@AkihiroSuda AkihiroSuda left a comment

Choose a reason for hiding this comment

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

Thanks

@AkihiroSuda AkihiroSuda merged commit ab4c717 into containerd:main Mar 5, 2024
22 checks passed
@Shubhranshu153 Shubhranshu153 deleted the fix-default-platform branch March 5, 2024 17:14
@@ -430,6 +438,15 @@ func (c *Cmd) AssertOutNotContains(s string) {
})
}

func (c *Cmd) AssertErrNotContains(s string) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Hey @Shubhranshu153

Looks like this is testing stdout (c.AssertOutWithFunc) and not stderr.
Can you clarify if the intention here was to test stderr?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants