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

Sort mixin output in order declared #2472

Merged
merged 6 commits into from
Nov 30, 2022

Conversation

carolynvs
Copy link
Member

What does this change

When we are querying mixins, such as when we are asking each mixin for Dockerfile lines to include in the bundle image, we call them in go routines. Depending on how quickly they return, the order is not guaranteed and may change. I have updated our mixin query function to sort the results of querying the mixins in a consistent order, the order that they are defined in the bundle.

During build in particular, this ensures that we optimize layer caching as much as possible by always outputing the same contents of the Dockerfile when building a bundle. Previously, it could include the mixins in varying order which prevented reuse of layers from previous builds.

What issue does it fix

Fixes #2469

Notes for the reviewer

N/A

Checklist

  • Did you write tests?
  • Did you write documentation?
  • Did you change porter.yaml or a storage document record? Update the corresponding schema file.
  • If this is your first pull request, please add your name to the bottom of our Contributors list. Thank you for making Porter better! 🙇‍♀️

Reviewer Checklist

  • Comment with /azp run test-porter-release if a magefile or build script was modified
  • Comment with /azp run porter-integration if it's a non-trivial PR

When we are querying mixins, such as when we are asking each mixin for Dockerfile lines to include in the bundle image, we call them in go routines. Depending on how quickly they return, the order is not guaranteed and may change. I have updated our mixin query function to sort the results of querying the mixins in a consistent order, the order that they are defined in the bundle.

The Execute function now returns a bit more information about the results of each mixin command, and it's up to the caller to decide how to handle errors when not all mixins are required to have a successful exit code. Lint allows mixins to not implement that command, so in that case we check if the command isn't implemented and skip over it.

Fixes getporter#2469

During build in particular, this ensures that we optimize layer caching as much as possible by always outputing the same contents of the Dockerfile when building a bundle. Previously, it could include the mixins in varying order which prevented reuse of layers from previous builds.

Signed-off-by: Carolyn Van Slyck <[email protected]>
@carolynvs carolynvs force-pushed the sort-mixin-output-by-decl branch from 5636349 to d063b7a Compare November 28, 2022 18:54
@carolynvs carolynvs marked this pull request as ready for review November 28, 2022 19:21
pkg/mixin/query/query.go Outdated Show resolved Hide resolved
Signed-off-by: Carolyn Van Slyck <[email protected]>
@carolynvs carolynvs marked this pull request as draft November 28, 2022 21:28
@carolynvs
Copy link
Member Author

I just realized that the way I'm using the map isn't safe to use with go routines. I'll revert some of it to go back to using channels.

Signed-off-by: Carolyn Van Slyck <[email protected]>
Signed-off-by: Carolyn Van Slyck <[email protected]>
@carolynvs
Copy link
Member Author

Happily, the problem was just in the unit tests, not the code. I've fixed the test helper to avoid the race.

@carolynvs carolynvs marked this pull request as ready for review November 29, 2022 18:23
switch commandOpts.Command {
case "build":
if p.ReturnBuildError {
return errors.New("encountered build error")
}
fmt.Fprintln(pkgContext.Out, "# exec mixin has no buildtime dependencies")
fmt.Fprintf(pkgContext.Out, "# %s mixin has no buildtime dependencies", name)
Copy link
Contributor

Choose a reason for hiding this comment

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

should we preserve the new line break in the output here?

func (p *TestPackageManager) GetCalled() map[string]int {
return p.called
func (p *TestPackageManager) GetCalled(mixin string) int {
calls, _ := p.called.Load(mixin)
Copy link
Contributor

Choose a reason for hiding this comment

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

should we check the boolean returned by Load to make sure the mixin exist in the map before we do the type assertion?

The "unsupported command" text is printed to stderr. I have updated our mixin/plugin runner to capture the command output and include it in the returned error when the command fails.
That way we can check if a mixin command failed because the command isn't implemented.

Signed-off-by: Carolyn Van Slyck <[email protected]>
Signed-off-by: Carolyn Van Slyck <[email protected]>
@carolynvs
Copy link
Member Author

@VinozzZ I've updated the PR with your feedback, please take another look

Copy link
Contributor

@VinozzZ VinozzZ left a comment

Choose a reason for hiding this comment

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

lgtm!

@carolynvs carolynvs merged commit 3989045 into getporter:main Nov 30, 2022
@carolynvs carolynvs deleted the sort-mixin-output-by-decl branch November 30, 2022 16:32
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.

Mixins install order isn't fixed which results in cache miss and redundant images
3 participants