Skip to content
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

Target ports cannot be set to range when using long syntax #504

Open
Neirda24 opened this issue Dec 5, 2023 · 5 comments
Open

Target ports cannot be set to range when using long syntax #504

Neirda24 opened this issue Dec 5, 2023 · 5 comments

Comments

@Neirda24
Copy link

Neirda24 commented Dec 5, 2023

Converting

services:
    my-service:
        ports:
            - '20-21:20-21/tcp'
            - '40000-40009:40000-40009/tcp'

to

services:
    my-service:
        ports:
            -
                target: '20-21'
                published: '20-21'
                protocol: 'tcp'
            -
                target: '40000-40009'
                published: '40000-40009'
                protocol: 'tcp'

fails with :

services.my-service.ports.[].target: failed to cast to expected type: strconv.Atoi: parsing "20-21": invalid syntax


It seems published correctly supports ranges but target doesn't

@ndeloof
Copy link
Collaborator

ndeloof commented Dec 7, 2023

short syntax 40000-40009:40000-40009 is actually expanded to 10 entries in long syntax:

            -  target: 40000
                published: '40000'
                protocol: 'tcp'
...
            -  target: 40009
                published: '40009'
                protocol: 'tcp'

long syntax actually reflect the Moby API used to create container, while the short syntax is just syntaxic sugar

@Neirda24
Copy link
Author

seems this time teh long syntax isn't the way to go then. Will it be fixed ? I'd gladly help but have no knowledge of go.

@ndeloof
Copy link
Collaborator

ndeloof commented Dec 13, 2023

it won't be "fixed" as the role for the long syntax is to offer detail about each and every exposed port, while the short syntax is just syntactic sugar, and offers a "range" syntax for convenience.
What's the reason you'd like to use long syntax with a range, what's wrong with short syntax?

@Neirda24
Copy link
Author

I like long syntax because it usually provides more features than short one and also avoid bugs in some cases (volumes for example). I find it odd that for this particular use case it is better to use the short one as it is "lacking" a feature syntax from the short syntax. (I posted on slack first then I was told that it looked like a bug and should open an issue). If I was to try to implement it and post a PR. Could it pass or would it get a refused for reasons mentioned earlier ?

@ndeloof
Copy link
Collaborator

ndeloof commented Dec 13, 2023

in this specific case, long syntax doesn't offer any additional option vs short one.
anyway, if you feel this is relevant, you can prepare a PR, but be aware the actual challenge is not to update the spec but to adapt https://github.com/compose-spec/compose-go

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

No branches or pull requests

2 participants