10000 Convert ports before parsing. by thaJeztah · Pull Request #2251 · docker/cli · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Convert ports before parsing. #2251

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

Merged
merged 1 commit into from
Jan 16, 2020

Conversation

thaJeztah
Copy link
Member
@thaJeztah thaJeztah commented Jan 14, 2020

carry of #1965 (original branch was gone)

Refactor code to allow mixing notation with -p
Closes #1962
closes #1965
closes #2041
closes #2151
closes #2227
closes #2371

Signed-off-by: Aleksander Piotrowski apiotrowski312@gmail.com

- What I did
After refactoring and bug fixing. Docker provides better error message with invalid port:
docker run --rm -p 8080:87888888 busybox

and works with mixed notation like:
docker run --rm -p 8080:80 -p published=1500,target=444 busybox

- How I did it
I changed parsePortOpts, before it was iterating over all -p args and assuming that all of them are in the same notation. My fix is to iterate over all args and change every with = to short notation and then parse it.

- How to verify it
docker run --rm -p 8080:80 -p published=1500,target=444 busybox
docker run --rm -p 8080:87888888 busybox

- Description for the changelog
Fix a bug with parsing -p flag with mixed notation

- A picture of a cute animal (not mandatory but encouraged)

@thaJeztah
Copy link
Member Author

rebased, and addressed nits 👍 ptal

8000 Copy link
Contributor
@zappy-shu zappy-shu left a comment

Choose a reason for hiding this comment

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

LGTM

@thaJeztah
Copy link
Member Author

ping @silvin-lubecki PTAL

8000
}

params[opt[0]] = opt[1]
optsList = append(optsList, fmt.Sprintf("%s:%s/%s", params["target"], params["published"], params["protocol"]))
Copy link
Member Author

Choose a reason for hiding this comment

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

Note; this needs to be updated once #2252 is merged

Also; looking at how it's serialised to a string:

  • host-ip is not in the serialised form. while this looks to be currently not supported in the long form (we should), having a combination of "long" and "short" options could possibly mean that duplicates go unnoticed (I'd have to check). i.e., -p 0.0.0.0:8080:80 is the equivalent to -p published=8080,target=80, but the latter is serialised to 8080:80 (not 0.0.0.0:8080:80). Then again, we may already have a problem if -p 0.0.0.0:8080:80 and -p 127.0.0.1:8080:80 are both set 🤔
  • the long-form mode=host is only supported for swarm services (wondering if it should be added as a no-op option for docker run 🤔

Perhaps with some refactoring, we can re-use the PortOpt type for both docker run and docker service (separating validation to produce errors on options that are not supported by either docker run or docker service);

func (p *PortOpt) Set(value string) error {

Refactor code to allow mixed notation with -p flag.

Signed-off-by: Aleksander Piotrowski <apiotrowski312@gmail.com>
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
@codecov-io
Copy link

Codecov Report

❗ No coverage uploaded for pull request base (master@c8e2729). Click here to learn what that means.
The diff coverage is 83.33%.

@@            Coverage Diff            @@
##             master    #2251   +/-   ##
=========================================
  Coverage          ?   56.79%           
=========================================
  Files             ?      310           
  Lines             ?    21802           
  Branches          ?        0           
=========================================
  Hits              ?    12383           
  Misses            ?     8503           
  Partials          ?      916

@thaJeztah
Copy link
Member Author

@silvin-lubecki updated; PTAL

Copy link
Contributor
@silvin-lubecki silvin-lubecki left a comment

Choose a reason for hiding this comment

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

Still LGTM 👍

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