-
Notifications
You must be signed in to change notification settings - Fork 604
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
Support copying files in volume #200
Support copying files in volume #200
Conversation
cf587a5
to
d10e861
Compare
7a00aaa
to
a82b0d0
Compare
run_mount.go
Outdated
|
||
s := client.SnapshotService(clicontext.String("snapshotter")) | ||
|
||
tempDir, err := ioutil.TempDir(os.Getenv("GOTMPDIR"), "initialC") |
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.
Why GOTMPDIR
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.
it is just a choice. I can create tempDir in in the default location for OS. it doesn't change anything for me
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.
updated to tempDir, err := ioutil.TempDir("", "initialC")
run_mount.go
Outdated
target := strings.Join([]string{tempDir, imgVol}, "") | ||
|
||
//copying up initial contents of the mount point directory | ||
copyExistingContents(target, anonVol.Mountpoint) |
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.
Named volumes need this as well
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.
Also make sure to catch 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.
@AkihiroSuda I made modification. FYI : in docker named volume do not copy initial content ( that may override source volume)
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.
@AkihiroSuda sorry I mixed mount bind and named volume. I added copyExistingContents
to named volume
fd20868
to
66e8281
Compare
run_mount_test.go
Outdated
base.Cmd("run", "-v", "/mnt", "--rm", imageName).AssertOut("hi") | ||
|
||
//NamedVolume | ||
base.Cmd("run", "-v", "/home:/mnt", "--rm", imageName).AssertFail() |
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 is a bind mount, not a named volume (nerdctl volume create)
run_mount.go
Outdated
imgVol := filepath.Clean(imgVolRaw) | ||
target := strings.Join([]string{tempDir, imgVol}, "") | ||
|
||
//Coyping content only for AnonymousVolume |
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.
No
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.
fixed
run_mount.go
Outdated
|
||
if ensuredImage != nil { | ||
imageVolumes = ensuredImage.ImageConfig.Volumes | ||
client, ctx, cancel, err := newClient(clicontext) |
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.
No, we already have the client
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.
fixed
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.
Doesn’t seem fixed
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.
it should be ok now!
pkg/mountutil/mountutil.go
Outdated
@@ -90,7 +96,7 @@ func ProcessFlagV(s string, volStore volumestore.VolumeStore) (*Processed, error | |||
return nil, errors.Errorf("failed to parse %q", s) | |||
} | |||
res.Mount = specs.Mount{ | |||
Type: "none", | |||
Type: string(vType), |
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 is an OCI Mount object, you can’t mix up Docker API type here
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.
@AkihiroSuda does OCI provide types values ? or I may set them directly in the code ?
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.
@AkihiroSuda is it ok for you ?
run_mount_test.go
Outdated
base.Cmd("volume","create", "copying-initial-content").AssertOK() | ||
base.Cmd("run", "-v", "copying-initial-content:/mnt", "--rm", imageName).AssertOut("hi") | ||
//mount bind | ||
base.Cmd("run", "-v", "/home:/mnt", "--rm", imageName).AssertFail() |
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.
Mounting /home is dangerous, please use some ioutil.TempDir
ff22da0
to
86e8f5f
Compare
pkg/mountutil/mountutil.go
Outdated
@@ -90,7 +93,7 @@ func ProcessFlagV(s string, volStore volumestore.VolumeStore) (*Processed, error | |||
return nil, errors.Errorf("failed to parse %q", s) | |||
} | |||
res.Mount = specs.Mount{ | |||
Type: "none", | |||
Type: vType, |
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.
Again, you can't have "volume" "bind" here
https://github.com/opencontainers/runtime-spec/blob/master/config.md#posix-platform-mounts
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.
The type fIeld can be in this struct
nerdctl/pkg/mountutil/mountutil.go
Line 32 in 86e8f5f
type Processed struct { |
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.
@AkihiroSuda moved.
cdff425
to
6a9b795
Compare
run_mount_test.go
Outdated
assert.NilError(t, err) | ||
defer os.RemoveAll(tmpDir) | ||
|
||
m := strings.Join([]string{"./", tmpDir, ":", "/mnt"}, "") |
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.
You don’t need ./ here
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.
fixed
@@ -32,6 +32,7 @@ import ( | |||
type Processed struct { | |||
Mount specs.Mount | |||
AnonymousVolume string // name | |||
Type string |
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.
enum (Bind = iota, Volume)
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.
@AkihiroSuda can review plz.
b63c6f0
to
05d4340
Compare
@AkihiroSuda any idea what is disturbing the |
return nil, nil, err | ||
} | ||
|
||
if err := mount.All(mounts, tempDir); err != nil { |
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.
Where are the mounts getting cleaned up? The temp mount logic is ideal for these type of use cases
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.
@dmcgowan I added unmount logic . The temp mount logic is ideal but not in this context because it push me to make same steps ( tmp dir creation then mount then unmount ) in each iteration flagVSlice
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.
I think it depends on user cannot CONTRL-C during copy
. Need to figure out how to clean up in this case
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.
0bb9b2e
to
c245c9c
Compare
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.
Pushed a new test.
LGTM if green. Thanks and sorry for slow reviewing
needs rebase
|
Signed-off-by: fahed dorgaa <fahed.dorgaa@gmail.com>
Signed-off-by: Akihiro Suda <akihiro.suda.cz@hco.ntt.co.jp>
Signed-off-by: Akihiro Suda <akihiro.suda.cz@hco.ntt.co.jp>
The commit c245c9c "support copying files in volume" (rebased as 89daa2b) improperly used `strings.Join` to join paths. The new commit replaces `strings.Join` with `securejoin.SecureJoin`. The problematic commit was not merged into the existing releases, so nobody was exposed to potential vulns. Signed-off-by: Akihiro Suda <akihiro.suda.cz@hco.ntt.co.jp>
697d2e7
to
a0390ad
Compare
@AkihiroSuda should we test hardlink too ? |
}() | ||
|
||
if err := mount.All(mounts, tempDir); err != nil { | ||
if err := s.Remove(ctx, tempDir); err != nil && !errdefs.IsNotFound(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.
need to umount first and then remove
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.
Using WDYT? @AkihiroSuda @dmcgowan |
Yes, that's more preferrable.
How do you use |
fixing #165