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

Recompute docker dependencies across dev loops. #5121

Merged

Conversation

tejal29
Copy link
Contributor

@tejal29 tejal29 commented Dec 7, 2020

fixes #5110 & #5115

In #4896, we cache results for docker.GetDependencies since there were getting computed atleast 2 times for docker builds.
However, this PR ended up caching the results across dev loops.

In this PR,

Alternate approach considered,

  1. To create a new dependencyCache for each loop.
  • this would have required a huge refactor as docker.GetDependency is a public method.
  1. To invalidate the dependencyCache at end of each dev loop
event.DevLoopComplete(r.devIteration)
// invalidate all cached GetDependencies.
docker.InvalidateDependencyCache()
logger.Unmute()

This would have required adding pkg/skaffold/docker package dependency in pkg/skaffold/runner. If all dependencies were cached, we could have added InvalidateDependencyCache() to Builder interface. However only docker dependencies are cached, so went with the approach to add a new method GetCachedDependencies and use it when creating tar context

Testing notes

  1. make
  2. go to examples/hot-reload
  3. skaffold dev
  4. Add a new js file touch node/src/new.js
  5. Verify a dev loop is started.
Watching for changes...
[node] Example app listening on port 3000!
INFO[0040] files added: [node/src/new.js] 
Syncing 1 files for node-example:682863e6ee15639b6fceb28c79308b206f6fb329188e18907fc0a766e77b2cc0
INFO[0040] Copying files: map[node/src/new.js:[/home/node/app/src/new.js]] to node-example:682863e6ee15639b6fceb28c79308b206f6fb329188e18907fc0a766e77b2cc0 

Watching for changes...

@tejal29 tejal29 requested a review from a team as a code owner December 7, 2020 21:55
@tejal29 tejal29 requested a review from briandealwis December 7, 2020 21:55
@google-cla google-cla bot added the cla: yes label Dec 7, 2020
@tejal29 tejal29 changed the title Only read chached values in createContext Recompute docker dependencies across dev loops. Dec 7, 2020
@codecov
Copy link

codecov bot commented Dec 7, 2020

Codecov Report

Merging #5121 (35bff8e) into master (272f104) will increase coverage by 0.04%.
The diff coverage is 71.42%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #5121      +/-   ##
==========================================
+ Coverage   72.19%   72.24%   +0.04%     
==========================================
  Files         380      380              
  Lines       13303    13326      +23     
==========================================
+ Hits         9604     9627      +23     
  Misses       3006     3006              
  Partials      693      693              
Impacted Files Coverage Δ
pkg/skaffold/build/cluster/cluster.go 25.80% <0.00%> (ø)
pkg/skaffold/build/cluster/kaniko.go 22.97% <0.00%> (+0.60%) ⬆️
pkg/skaffold/build/dependencies.go 33.33% <33.33%> (ø)
pkg/skaffold/docker/context.go 75.00% <66.66%> (ø)
pkg/skaffold/docker/dependencies.go 74.71% <81.25%> (+1.37%) ⬆️
pkg/skaffold/build/custom/dependencies.go 76.47% <100.00%> (+1.47%) ⬆️
pkg/skaffold/build/docker/docker.go 76.59% <100.00%> (ø)
pkg/skaffold/diagnose/diagnose.go 54.54% <100.00%> (+0.69%) ⬆️
pkg/skaffold/docker/image.go 80.75% <100.00%> (+1.21%) ⬆️
pkg/skaffold/util/store.go 100.00% <100.00%> (ø)
... and 3 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 272f104...35bff8e. Read the comment docs.

@tejal29 tejal29 added the kokoro:force-run forces a kokoro re-run on a PR label Dec 7, 2020
@kokoro-team kokoro-team removed the kokoro:force-run forces a kokoro re-run on a PR label Dec 7, 2020
@tejal29 tejal29 changed the title Recompute docker dependencies across dev loops. [Hold] Recompute docker dependencies across dev loops. Dec 7, 2020
@tejal29
Copy link
Contributor Author

tejal29 commented Dec 7, 2020

Hold, i am also trying to fix #5115 which is result of #4896

@pull-request-size pull-request-size bot added size/L and removed size/S labels Dec 8, 2020
@tejal29 tejal29 force-pushed the fix_get_dependency_cache branch from 62b2d0b to a380575 Compare December 8, 2020 00:14
@tejal29 tejal29 changed the title [Hold] Recompute docker dependencies across dev loops. Recompute docker dependencies across dev loops. Dec 8, 2020
@tejal29
Copy link
Contributor Author

tejal29 commented Dec 8, 2020

Performance stats

I ran GetDependencies on https://github.com/GoogleCloudPlatform/microservices-demo and did the time analysis on

Number of Files GetDependencies Time in Ms Total Time spent in GetDependencies in skaffold build.
11 7.961 15.922
10 3.558 7.116
9 11.09 22.18
10 1.718 3.436
9 2.395 4.79
62 4.82 9.64
5 3.884 7.768
10 4.486 8.972
14 19.509 39.018
9 4.103 8.206
10 6.569 13.138

image

@tejal29
Copy link
Contributor Author

tejal29 commented Dec 8, 2020

@gsquared94, @briandealwis and @nkubala please take a look.
We could get into gcloud if released today.

@tejal29 tejal29 added the kokoro:force-run forces a kokoro re-run on a PR label Dec 8, 2020
@kokoro-team kokoro-team removed the kokoro:force-run forces a kokoro re-run on a PR label Dec 8, 2020
@tejal29 tejal29 force-pushed the fix_get_dependency_cache branch from 49867f8 to 35bff8e Compare December 8, 2020 23:17
@@ -53,3 +52,8 @@ func GetDependencies(ctx context.Context, workspace string, a *latest.CustomArti
return list.Files(workspace, a.Dependencies.Paths, a.Dependencies.Ignore)
}
}

func getDockerBuildConfig(ws string, artifact string, a *latest.CustomArtifact) docker.BuildConfig {
dockerfile := a.Dependencies.Dockerfile
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 normalize the Dockerfile path here itself instead of later?

Copy link
Contributor Author

@tejal29 tejal29 Dec 9, 2020

Choose a reason for hiding this comment

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

That is a good suggestion. ThenormalizeDockerpath is used a lot many places. while going through the code, there is a huge scope of avoiding repetition across docker.SyncMap and docker.GetDependencies

I don't want to error out here in this stage of creating a BuildConfig

Copy link
Contributor

@gsquared94 gsquared94 left a comment

Choose a reason for hiding this comment

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

lgtm

@tejal29 tejal29 merged commit 4ea6623 into GoogleContainerTools:master Dec 9, 2020
tejal29 added a commit to tejal29/skaffold that referenced this pull request Dec 9, 2020
…#5121)

* only read chached values in createContext

* remove sf.do

* Move key from dockerfilePath to artifact name

* Fix kaniko test
IsaacPD pushed a commit that referenced this pull request Dec 9, 2020
* Recompute docker dependencies across dev loops. (#5121)

* only read chached values in createContext

* remove sf.do

* Move key from dockerfilePath to artifact name

* Fix kaniko test

* Release notes for v1.17.2
@tejal29 tejal29 deleted the fix_get_dependency_cache branch April 15, 2021 07:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
3 participants