-
Notifications
You must be signed in to change notification settings - Fork 642
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 relative paths in volumes
statements in docker-compose.yaml
#848
Conversation
Codecov Report
@@ Coverage Diff @@
## master #848 +/- ##
============================================
+ Coverage 50.12% 50.46% +0.33%
- Complexity 1151 1180 +29
============================================
Files 134 137 +3
Lines 6951 7033 +82
Branches 916 935 +19
============================================
+ Hits 3484 3549 +65
- Misses 3164 3177 +13
- Partials 303 307 +4
|
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.
Thanks a lot, the functionality looks good to me and makes sense.
I have still some minor requests, though:
- would be cool if we can stick to jmockit as mocking lib.
- To make the behaviour consistent I would like to add this functionality to the 'normal' bind volumes via the regular configuration.
- Update of the documentation in src/main/asciidoc would be awesome.
- Add a line changelog.md for the new feature.
thanks!
import java.io.File; | ||
|
||
import static org.junit.Assert.assertEquals; | ||
import static org.mockito.Mockito.mock; |
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.
would it be able to use jmockit as Mock framework (as we already use this and I'm not so inclined to use multiple mock frameworks in d-m-p)
You could take e.g. https://github.com/rhuss/docker-maven-plugin/blob/674e80fdf56d31fdd263366d53e7a5cf0dc064b3/src/test/java/io/fabric8/maven/docker/access/log/LogRequestorTest.java#L220 as a sample how expectations are setup in jmockit.
* @param volume the volume string from the docker-compose file | ||
* @return the volume string, with any relative paths resolved as absolute paths | ||
*/ | ||
static String resolveRelativeVolumeBinding(File baseDir, String 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.
It would be awesome if we could use the same kind of parsing for the regular configuration, too.
E.g. in
- https://github.com/rhuss/docker-maven-plugin/blob/674e80fdf56d31fdd263366d53e7a5cf0dc064b3/src/main/java/io/fabric8/maven/docker/service/RunService.java#L258
- https://github.com/rhuss/docker-maven-plugin/blob/674e80fdf56d31fdd263366d53e7a5cf0dc064b3/src/main/java/io/fabric8/maven/docker/service/RunService.java#L332
The challenge there is to get the basedir into the method (which must not have a reference to any Maven code). Needs probably given through top-down.
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 appears that relative paths in volume binding strings can only appear in docker-compose.yaml
files.
The Docker Run reference indicates that relative paths are not allowed in image VOLUME
s:
-v, --volume=[host-src:]container-dest[:]: Bind mount a volume.
The comma-delimitedoptions
are [rw|ro], [z|Z],
[[r]shared|[r]slave|[r]private], and [nocopy].
The 'host-src' is an absolute path or a name value.
And later in the same section:
The container-dest must always be an absolute path such as /src/docs. The host-src can either be an absolute path or a name value. If you supply an absolute path for the host-dir, Docker bind-mounts to the path you specify. If you supply a name, Docker creates a named volume by that name.
A name value must start with an alphanumeric character, followed by a-z0-9, _ (underscore), . (period) or - (hyphen). An absolute path starts with a / (forward slash).
For example, you can specify either /foo or foo for a host-src value. If you supply the /foo value, Docker creates a bind-mount. If you supply the foo specification, Docker creates a named volume.
Let me know if you don't agree, but it seems that relative paths only need to be accounted for when using a docker-compose.yml
file.
In that case, the base directory used to resolve relative paths should be the one defined in the compose handler:
<external>
<type>compose</type>
<basedir>src/main/docker</basedir>
<composeFile>docker-compose.yml</composeFile>
</external>
Overall, I'm not sure of the wider applicability this code. What are your thoughts? Maybe I am missing something. I can certainly clean up the PR a bit, and have the resolution logic ready to be used by other classes as needed.
Hi @rhuss, Let me know if you think I've got all the bases covered. I tried to address each of your comments, but note my response here which may be hidden depending on how the GitHub UI renders the comment in your browser. I think the major portions of the logic are Again, based on my reasoning above, I'm not sure if there are other portions of the codebase that can take advantage of this, but I just may not be understanding the code base, or your request. Let me know if there's anything else you need. |
@rhuss just a ping on this PR- many thanks for your help/direction! |
@emetsger Thanks, will have a look ASAP. hope for today, but work is killing me ... |
* Moves path resolution logic to a utility class * Includes tests * Adds mockito-core as a test dependency Addresses fabric8io#846 Signed-off-by: Elliot Metsger <emetsger@jhu.edu>
Signed-off-by: Elliot Metsger <emetsger@jhu.edu>
…o use DockerPathUtil. Signed-off-by: Elliot Metsger <emetsger@jhu.edu>
… VolumeBindingUtil. Includes test updates. Signed-off-by: Elliot Metsger <emetsger@jhu.edu>
…asedir (fabric8io#846). Signed-off-by: Elliot Metsger <emetsger@jhu.edu>
9c6fb76
to
9cd4375
Compare
@rhuss fixed test failures, added some javadoc, rebased against master. |
Signed-off-by: Elliot Metsger <emetsger@jhu.edu>
Signed-off-by: Elliot Metsger <emetsger@jhu.edu>
…resolve relative path references in docker compose files. Signed-off-by: Elliot Metsger <emetsger@jhu.edu>
Thanks a lot ! @nicolaferraro could you have a brief look, I'm really so overloaded ;-( This is an awesome PR, I would like to get it merged asap (before my PTO next week) |
Sure @rhuss, I can look at it this morning. |
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.
@emetsger this PR is really awesome!
You've implemented most of the suggestions expressed by Roland.
Btw, I also think that the behavior should be kept consistent with "bind". If you look at the volume documentation, mount points are allowed in the plugin config and users should be able to use relative paths also there.
Even if docker run
does not support relative paths, the plugin has its own configuration schema and it can fill the gaps. The base dir in that case would be the project root imho.
I think that using relative paths in the "bind" configuration has real advantages.. e.g. you can create a container that supports hot reloading by sharing the "./target" directory..
Good stuff!
Hope you can do this fix (Roland has already suggested some starting points in previous comments).
|
||
// only perform resolution if the localPath begins with '~/' or './' | ||
|
||
if (localPath.startsWith("./")) { |
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.
Maybe a better option would be using the File#getCanonicalPath
method to resolve relative paths. So that also ../
is resolved correctly.
* docker-compose.yaml files may be resolved by relative parent references (e.g. "../path/to/docker-compose.yaml") * volume bind mounts may specifiy relative parent references (e.g. "../path/to/dir:/container/mount/point") * includes updated tests and comments Signed-off-by: Elliot Metsger <emetsger@jhu.edu>
@nicolaferraro @rhuss I think there are a couple more things that need to be done. For example, this PR doesn't handle volume bind strings that specify read permissions like Also, I'm not fully convinced that my changes will work on the Windows platform. Is there someone who can test this PR on Windows? I can probably get my hands on a machine somewhere if that's too much trouble for you all. |
@emetsger it would be good if you can test it on windows (and/or evaluate what's needed to be changed). Unfortunately (or fortunately 😄) I'm a lot far from any windows machine right now... |
bf97704
to
25eddf3
Compare
Signed-off-by: Elliot Metsger <emetsger@jhu.edu>
Signed-off-by: Elliot Metsger <emetsger@jhu.edu>
d7bf83c
to
f44c31b
Compare
* Consolidates constants and test-related utility methods in PathTestUtil * Updates Javadoc and comments * Updates DockerFileUtilTest to be tolerant of line-ending differences (fails on Windows without these changes) Signed-off-by: Elliot Metsger <emetsger@jhu.edu>
f44c31b
to
406a690
Compare
@nicolaferraro @rhuss OK! This PR has been tested on Windows; it does include a minor update to Please feel free to squash the PR, and/or let me know if you need anything else! |
Great @emetsger, I'll take another look later. |
[merge] |
@emetsger thanks ! |
@rhuss @nicolaferraro thank you folks for a great plugin! Happy to make a small contribution :) |
Addresses #846
Signed-off-by: Elliot Metsger emetsger@jhu.edu