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

process extends recursively #547

Merged
merged 2 commits into from
Jan 25, 2024
Merged

Conversation

ndeloof
Copy link
Collaborator

@ndeloof ndeloof commented Jan 24, 2024

fixes docker/compose#11394

issue takes place when there's a chain of extending services:

services:
  level1:
    build:
      context: ..

  level2:
    extends: level1

  service:
    extends: level2
    build:
      target: target

The root cause for this issue is that we try to extends a service before the compose model has been fully resolved. Typically loading this illustration example, if first service (which go map iteration makes random) to be processed is service, it will merge with sibling level2. This results in a build mapping defined without a context, and will default to .. But if level2 is loaded first, it will have build.context set to .., and then service will do as well.

This PR changes the logic so that we force extends to be applied recursively on services using new func applyServiceExtends. This one will process a service to apply extends if needed (otherwise is no-op). Once it has identified the base service used by extends, it executes recursively to enforce this one to be fully defined

@ndeloof ndeloof force-pushed the extends_race branch 2 times, most recently from a824217 to b93a956 Compare January 24, 2024 14:33
Copy link
Member

@milas milas left a comment

Choose a reason for hiding this comment

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

👍🏻

Comment on lines 124 to 128
extendsOpts.ResourceLoaders = append([]ResourceLoader{}, opts.ResourceLoaders...)
// replace localResourceLoader with a new flavour, using extended file base path
extendsOpts.ResourceLoaders[len(opts.ResourceLoaders)-1] = localResourceLoader{
WorkingDir: localdir,
}
Copy link
Member

Choose a reason for hiding this comment

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

Instead of assuming that localResourceLoader is the last in the slice, it might be better to loop through and attempt to cast them until you find it and then replace it

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

this isn't an assumption, local resource loader has to be the last in the slice as all "remote" resource loaders are checked first.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I introduced RemoteResourceLoaders to check this implicit rule

@ndeloof ndeloof force-pushed the extends_race branch 2 times, most recently from 99d2fbd to 8ef0fb3 Compare January 25, 2024 11:04
Signed-off-by: Nicolas De Loof <[email protected]>
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] random build context path for services with a long(ish) chain of extends with compose 2.24.2
2 participants