Skip to content

make extra_hosts values uniques#685

Merged
glours merged 1 commit intocompose-spec:mainfrom
glours:extra_hosts-unicity
Sep 26, 2024
Merged

make extra_hosts values uniques#685
glours merged 1 commit intocompose-spec:mainfrom
glours:extra_hosts-unicity

Conversation

@glours
Copy link
Copy Markdown
Collaborator

@glours glours commented Sep 24, 2024

Issue occurred when you have an extra_hosts value defined in the main config file and you have an extends of the service with the exact same name without any additional extra_hosts config

Fixes docker/compose#12155

@glours glours requested a review from ndeloof as a code owner September 24, 2024 12:55
@glours glours requested a review from jhrotko September 24, 2024 12:55
@glours glours self-assigned this Sep 24, 2024
unique["services.*.environment"] = keyValueIndexer
unique["services.*.env_file"] = envFileIndexer
unique["services.*.expose"] = exposeIndexer
unique["services.*.extra_hosts"] = keyValueIndexer
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

:-1
this was intentionally removed, as extra_hosts can be set multiple time per host with distinct IPs
see docker/compose#12088

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

one option could be to drop strictly equal lines, which somehow relax the json schema unicity rule, which doesn't bring any value here

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Ok, I'll build a custom indexer

@glours glours force-pushed the extra_hosts-unicity branch from 38f94a7 to 6523dd3 Compare September 26, 2024 08:50
Comment on lines +169 to +178
// Rewrite content of left slice to remove duplicate elements
i := 0
for _, v := range left {
if !slices.Contains(right, v) {
left[i] = v
i++
}
}
// keep only not duplicated elements from left slice
left = left[:i]
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

you can use https://pkg.go.dev/slices#Compact to remove duplicates from a slice

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Nope I tried it and it works only with consecutive values unfortunately

@glours glours force-pushed the extra_hosts-unicity branch from 6523dd3 to 8231c19 Compare September 26, 2024 09:08
@glours glours requested a review from ndeloof September 26, 2024 09:15
Signed-off-by: Guillaume Lours <705411+glours@users.noreply.github.com>
@glours glours force-pushed the extra_hosts-unicity branch from 8231c19 to 602e5ba Compare September 26, 2024 14:09
@glours glours enabled auto-merge (rebase) September 26, 2024 14:09
@glours glours merged commit d3fd7d9 into compose-spec:main Sep 26, 2024
@Nek-
Copy link
Copy Markdown

Nek- commented Oct 8, 2024

Thanks for the bugfix! Is there an estimated date for a new release? 😅

@jhrotko
Copy link
Copy Markdown
Collaborator

jhrotko commented Oct 9, 2024

@Nek- We are not sure, but should be around in 1~2 weeks

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

Successfully merging this pull request may close these issues.

[BUG] <extra_hosts array items[0,1] must be unique>

4 participants