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

feat: multistages now respect dependencies without building unnecessary stages #1165

Conversation

JordanGoasdoue
Copy link
Contributor

@JordanGoasdoue JordanGoasdoue commented Mar 29, 2020

Fixes #815

Description

⚠️ Started From this branch JordanGoasdoue:can-now-resolve-args-from-stage in this PR : #1160 to be able to have the args resolved correctly. The diff about this PR without taking into account #1160 is linked here : 2b45013
Multistage by kaniko doesn't have unnecessary builded stages anymore

Submitter Checklist

These are the criteria that every PR should meet, please check them off as you
review them:

  • Includes unit tests
  • Adds integration tests if needed.

See the contribution guide for more details.

Reviewer Notes

  • The code flow looks good.
  • Unit tests and or integration tests added.

Release Notes

Kaniko now respect multistage dependency tree without building unnecessary intermediates stages

Examples of user facing changes:
- kaniko adds a new flag `--registry-repo` to override registry

@googlebot googlebot added the cla: yes CLA signed by all commit authors label Mar 29, 2020
@JordanGoasdoue JordanGoasdoue changed the title feat: multistages now respect dependencies without building unnecessarily intermediates stages [WIP] feat: multistages now respect dependencies without building unnecessarily intermediates stages Mar 29, 2020
@JordanGoasdoue JordanGoasdoue changed the title [WIP] feat: multistages now respect dependencies without building unnecessarily intermediates stages [WIP] feat: multistages now respect dependencies without building unnecessarily stages Mar 29, 2020
@JordanGoasdoue JordanGoasdoue force-pushed the multistage-now-respects-dependencies branch 4 times, most recently from ee9cc87 to 39d447c Compare March 29, 2020 22:22
@JordanGoasdoue JordanGoasdoue changed the title [WIP] feat: multistages now respect dependencies without building unnecessarily stages feat: multistages now respect dependencies without building unnecessarily stages Mar 29, 2020
@JordanGoasdoue
Copy link
Contributor Author

JordanGoasdoue commented Mar 29, 2020

As this following dockerfile test from here pkg/executor/build_test.go can only work if it builds all the stages :

FROM debian as stage1
FROM ubuntu as stage2
RUN foo
COPY --from=stage1 /foo /bar
FROM alpine
COPY --from=stage1 /baz /bat

I have edited it to

FROM ubuntu as stage1
RUN foo
FROM alpine
COPY --from=stage1 /foo /bar
COPY --from=stage1 /baz /bat

because stage2 is never called on the case we are building without unnecessary stages.
Would be better I guess to add a parameter on the cli which would do this optimized build by calling the new function getUsedStaged only when the cli parameter is activated in order to not break anything, taking this dockerfile as an example. What do you think guys?

@JordanGoasdoue JordanGoasdoue changed the title feat: multistages now respect dependencies without building unnecessarily stages feat: multistages now respect dependencies without building unnecessary stages Mar 29, 2020
@JordanGoasdoue JordanGoasdoue changed the title feat: multistages now respect dependencies without building unnecessary stages [WIP] feat: multistages now respect dependencies without building unnecessary stages Mar 30, 2020
@JordanGoasdoue JordanGoasdoue force-pushed the multistage-now-respects-dependencies branch 4 times, most recently from dac590e to 4c55c2a Compare March 31, 2020 10:13
@JordanGoasdoue JordanGoasdoue changed the title [WIP] feat: multistages now respect dependencies without building unnecessary stages feat: multistages now respect dependencies without building unnecessary stages Mar 31, 2020
@JordanGoasdoue JordanGoasdoue force-pushed the multistage-now-respects-dependencies branch 3 times, most recently from d96db9a to 2b45013 Compare March 31, 2020 13:53
@JordanGoasdoue
Copy link
Contributor Author

JordanGoasdoue commented Mar 31, 2020

@tejal29 , the PR is now working as expected
If you are planning to have on kaniko this feature which doesn't build unusued stages, do you want a specific cli parameter to activate it as a new mode ?

@tejal29
Copy link
Member

tejal29 commented Apr 12, 2020

This is a great feature! It would be great if you can use a cli flag to expose this feature and turn it off by default.
--build-used-stages=false.

In future, we can make this default behavior.

@JordanGoasdoue
Copy link
Contributor Author

@tejal29, perfect, will do it.
But first, do I need to rebase both my PRs (this one and #1160) on the branch from this PR: #1190 ?

@JordanGoasdoue JordanGoasdoue force-pushed the multistage-now-respects-dependencies branch 3 times, most recently from 9e1ea8a to c0045f2 Compare April 15, 2020 07:32
@dani29
Copy link
Contributor

dani29 commented Apr 15, 2020

Hi Jordan, I rebased #1190 to resolve most of the conflicts with your previous PR - can you take a quick look and rebase your PR on it? Thanks!

@JordanGoasdoue JordanGoasdoue force-pushed the multistage-now-respects-dependencies branch from c0045f2 to 561695e Compare April 15, 2020 17:20
@JordanGoasdoue JordanGoasdoue force-pushed the multistage-now-respects-dependencies branch from 561695e to 352b10a Compare April 15, 2020 17:42
@JordanGoasdoue
Copy link
Contributor Author

JordanGoasdoue commented Apr 15, 2020

Done @dani29
Cheers

@JordanGoasdoue JordanGoasdoue force-pushed the multistage-now-respects-dependencies branch 4 times, most recently from 09379ae to 57aeb7a Compare April 16, 2020 07:48
@dani29
Copy link
Contributor

dani29 commented Apr 16, 2020

Thanks for the rebase!
It's a bit nitpicky, but I just realized that "build-used-stages" might be confusing for the user, as in both cases (t/f) you do build the used stages... it's the unused/unnecessary stages that you ignore.

Do you think it'd make more sense to call it --skip-unused-stages/--ignore-unused-stages or something like that?

@JordanGoasdoue
Copy link
Contributor Author

You're welcome.
True, I prefer even more --skip-unused-stages, it's clearer as you said.. I'm doing the change right now.

@JordanGoasdoue JordanGoasdoue force-pushed the multistage-now-respects-dependencies branch 2 times, most recently from 5f6b8c7 to 1ee7a9e Compare April 16, 2020 22:41
@JordanGoasdoue JordanGoasdoue force-pushed the multistage-now-respects-dependencies branch from 1ee7a9e to 8cbc7a8 Compare April 17, 2020 08:00
@JordanGoasdoue
Copy link
Contributor Author

JordanGoasdoue commented Apr 17, 2020

I've had some concerns about the function skipUnusedStages, especially with the targetIndex previously passed by value and retrieve by value after, it's why I've done some change on it.

Now targetIndex is passed by reference, and directly updated on the function if it needs to. No needs to retrieve it by value then.

I've also added some tests about the targetIndex, to compare It between the first one calculated before skipUnusedStages is called : expectedTargetIndexBeforeSkip, and the one updated after skipUnusedStages is called : expectedTargetIndexAfterSkip

@tejal29
Copy link
Member

tejal29 commented May 1, 2020

Thanks @JordanGoasdoue I will take a look and get it in today.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
cla: yes CLA signed by all commit authors
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Multi Stage build not respecting dependency tree
4 participants