-
Notifications
You must be signed in to change notification settings - Fork 639
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
Fix media type on unpacking layer #257
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,25 @@ | ||
// Copyright 2016 The Linux Foundation | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
package image | ||
|
||
import ( | ||
"archive/tar" | ||
"bytes" | ||
"compress/gzip" | ||
"crypto/sha256" | ||
"fmt" | ||
"io" | ||
"io/ioutil" | ||
"os" | ||
|
@@ -48,3 +64,61 @@ func TestUnpackLayerDuplicateEntries(t *testing.T) { | |
t.Fatalf("Expected to fail with duplicate entry, got %v", err) | ||
} | ||
} | ||
|
||
func TestUnpackLayer(t *testing.T) { | ||
tmp1, err := ioutil.TempDir("", "test-layer") | ||
if err != nil { | ||
t.Fatal(err) | ||
} | ||
defer os.RemoveAll(tmp1) | ||
err = os.MkdirAll(filepath.Join(tmp1, "blobs", "sha256"), 0700) | ||
if err != nil { | ||
t.Fatal(err) | ||
} | ||
tarfile := filepath.Join(tmp1, "blobs", "sha256", "test.tar") | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
And “create image-layout fodder for testing” is likely to be useful stuff in lots of places. Can we make layer-generator, etc. helpers instead of baking it into There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. On Wed, Sep 07, 2016 at 09:15:42PM -0700, Lei Jitang wrote:
I'd rather avoid the temporary invalidity by placing it somewhere else tempDir := filepath.Join(tmp1, "tmp") And then use f.Name() where you were using tarfile? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
I don't know if I got your point, I did it similarly like you said at the beginning, put the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. On Wed, Sep 07, 2016 at 11:45:29PM -0700, Lei Jitang wrote:
You can use rename no matter what the source and destination are, and |
||
f, err := os.Create(tarfile) | ||
if err != nil { | ||
t.Fatal(err) | ||
} | ||
|
||
gw := gzip.NewWriter(f) | ||
tw := tar.NewWriter(gw) | ||
|
||
tw.WriteHeader(&tar.Header{Name: "test", Size: 4, Mode: 0600}) | ||
io.Copy(tw, bytes.NewReader([]byte("test"))) | ||
tw.Close() | ||
gw.Close() | ||
f.Close() | ||
|
||
// generate sha256 hash | ||
h := sha256.New() | ||
file, err := os.Open(tarfile) | ||
if err != nil { | ||
t.Fatal(err) | ||
} | ||
defer file.Close() | ||
_, err = io.Copy(h, file) | ||
if err != nil { | ||
t.Fatal(err) | ||
} | ||
err = os.Rename(tarfile, filepath.Join(tmp1, "blobs", "sha256", fmt.Sprintf("%x", h.Sum(nil)))) | ||
if err != nil { | ||
t.Fatal(err) | ||
} | ||
|
||
testManifest := manifest{ | ||
Layers: []descriptor{descriptor{ | ||
MediaType: "application/vnd.oci.image.layer.tar+gzip", | ||
Digest: fmt.Sprintf("sha256:%s", fmt.Sprintf("%x", h.Sum(nil))), | ||
}}, | ||
} | ||
err = testManifest.unpack(newPathWalker(tmp1), filepath.Join(tmp1, "rootfs")) | ||
if err != nil { | ||
t.Fatal(err) | ||
} | ||
|
||
_, err = os.Stat(filepath.Join(tmp1, "rootfs", "test")) | ||
if err != nil { | ||
t.Fatal(err) | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should be an error, not a
continue
. Changing this to an error fixes the “wrong media-type” issue discussed in #261 (but not currently fixed by that PR).There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Although the spec does not currently say that layers MUST have a particular type, so this is currently an:
I expect the spec should clarify if it places bounds (upper or lower) on manifest layer[] media types, and once that happens we can adjust this to match.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@wking if the layers MUST have a particular type is not said in the spec currently, I think we should make it clear in the spec first.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
On Wed, Sep 07, 2016 at 04:58:52AM -0700, Lei Jitang wrote:
If the layers MUST have a particular type, then you should error out
here with “your manifest is broken”. If the spec does not limit the
allowed types (like now), then you should error out here with
“unimplemented type”. In no case that I can see should we be silently
ignoring an unrecognized type.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@wking If the spec does not limit the allowed types, I don't think we should error out on unpacking, we should just
unpacking the allowed typed layers. But I think this is another issue we should discuss more not related to this pr
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
On Wed, Sep 07, 2016 at 08:46:36PM -0700, Lei Jitang wrote:
If there's any confusion, I'm fine punting this to another PR. The
media type fix is critical and obviously right. The continue→error
fix only matters for oddball manifests, so it's much less important.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
is there an issue to clarify this aspect?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
On Fri, Sep 09, 2016 at 03:07:52AM -0700, Antonio Murdaca wrote:
There are ~50 million open validation issues at the moment, so I
haven't opened up one specifically for this ;). I try and bring it up
where it impacts an existing issue/PR. Most recently in #286.