-
Notifications
You must be signed in to change notification settings - Fork 644
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 #859: ARG not support in FROM #1299
Conversation
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 for the PR, but I think its not complete. Its not only that you can use args in a tag but as anything behind FROM (also the image name).
Not sure though how to actually tackle this.
doc/changelog.md
Outdated
@@ -8,6 +8,7 @@ | |||
- Add docker:build support for 'network' option #1030 | |||
- Failure referencing a previous staged image in FROM clause #1264 | |||
- Treat bridged and default network mode the same (#1234) | |||
- ARG not support in FROM (#859) |
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.
- ARG not support in FROM (#859) | |
- Support `ARG ` in `FROM` (#859) |
for (String[] argLine : argLines) { | ||
if (argLine.length > 1) { | ||
if (argLine[1].contains(":")) { | ||
result.put(argLine[1].split(":")[0], argLine[1].split(":")[1]); |
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 should only split once and reuse the result
- You should split into exactly two parts, with the second parts potentially having
:
, too. I.e. use the split function which takes the max. nr of resulting split elements as argument.
if (argLine[1].contains(":")) { | ||
result.put(argLine[1].split(":")[0], argLine[1].split(":")[1]); | ||
} else if (argLine[1].contains("=")) { | ||
result.put(argLine[1].split("=")[0], argLine[1].split("=")[1]); |
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 can put the split on ':' and '=' into a function for reuse, e.g. addArgWitValue(result, "=", argLine[1])
I was trying to do the changes but I noticed one thing, I'm testing using this Dockerfile(to test
But docker doesn't seem to be able to process this:
Were you talking about this case? I'm not sure whether I've understood your comment correctly or not. I'm on 1.40 API version at the moment.
|
Sorry, it seems to be working in this case:
|
fc6fde3
to
d19be15
Compare
private static AbstractMap.SimpleEntry<String, String> resolveArgsFromArgString(String argString) { | ||
for (int index = 0; index < argString.length(); index++) { | ||
if (argString.charAt(index) == ':' || argString.charAt(index) == '=') { | ||
return new AbstractMap.SimpleEntry<>(argString.substring(0, index), argString.substring(index+1)); |
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.
Could we add a trim()
to allow spaces around : or = ?
well thats not possible as you send only the first argument of the line (and arguments are delmited by spaces).
I'm really not sure that simplistic parsing of values is correct. What happens with arg values that carry spaces ?
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.
What if index is the lasst char in the string ? Wouldn't it be better to use String.split() with a regexp like :|=
?
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 for the PR but I'm afraid the parsing is not robust enough and only works for simple cases. That's just my feeling, but we need a better test coverage for the corner case and error cases, too.
private static AbstractMap.SimpleEntry<String, String> resolveArgsFromArgString(String argString) { | ||
for (int index = 0; index < argString.length(); index++) { | ||
if (argString.charAt(index) == ':' || argString.charAt(index) == '=') { | ||
return new AbstractMap.SimpleEntry<>(argString.substring(0, index), argString.substring(index+1)); |
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.
What if index is the lasst char in the string ? Wouldn't it be better to use String.split() with a regexp like :|=
?
Map<String, String> result = new HashMap<>(); | ||
for (String[] argLine : argLines) { | ||
if (argLine.length > 1) { | ||
AbstractMap.SimpleEntry<String, String> resolvedArg = resolveArgsFromArgString(argLine[1]); |
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 would call the method updateMapWithArgValue()
and feed in the map as argument. That allows you to avoid to generate temporary, short-lived obkects like resolvedArg
assertEquals("busybox:latest", fromClauses.next()); | ||
assertEquals(false, fromClauses.hasNext()); | ||
} | ||
|
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 would love to see more tests directly for the parsing methods with many corner cases. No need to create test Dockerfiles, but calling extractArgs()
and resolveImageTagFromArgs()
in a loop with different inputs (you could make the methods package private). But we need much more tests about different cases (like with ARG values, containing spaces, if this is allowed. Also check the Docker spec for the possible ARG variations).
@rhuss : Hi, Sorry I forgot to update this. I will update this around coming weekend |
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.
Looks good to me with one minor suggestion.
But we should merge this sonnish ...
* @param argLines list of lines containing arguments | ||
* @return HashMap of arguments or empty collection if none is found | ||
*/ | ||
public static Map<String, String> extractArgs(List<String[]> argLines) { |
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 you could inline the usage of extractLines
? (e..g change the signature to extractArgs(String dockerfile, FIxedStringSearchInterpolator interpolator)
and call extract Lines internally)
} | ||
|
||
@Test | ||
public void testExtractArgsFromDockerfile() { |
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.
👍
6bf635e
to
22f51d6
Compare
This issue that this PR fixes is important; I hope the PR can be merged and released. |
Thanks, let's merge that now. |
…r arguments in FROM port of fabric8io/docker-maven-plugin#1299
…r arguments in FROM Port of fabric8io/docker-maven-plugin#1299
…r arguments in FROM Port of fabric8io/docker-maven-plugin#1299
…r arguments in FROM Port of fabric8io/docker-maven-plugin#1299
…r arguments in FROM Port of fabric8io/docker-maven-plugin#1299
…r arguments in FROM Port of fabric8io/docker-maven-plugin#1299
Fix #859