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

Dev build cleanup deletes all layers #2050

Closed
tdickman opened this issue May 1, 2019 · 5 comments
Closed

Dev build cleanup deletes all layers #2050

tdickman opened this issue May 1, 2019 · 5 comments

Comments

@tdickman
Copy link
Contributor

tdickman commented May 1, 2019

Expected behavior

Skaffold dev should only cleanup layers it created.

Actual behavior

Skaffold dev cleans up all layers for a given image (even layers that already existed before it started).

For example, if I run skaffold run once, then run skaffold dev to start developing my application, and later hit control-c to stop the process, skaffold deletes all layers of the image it used, even the layers it didn't build (ex: layers that were built during skaffold run).

My current workflow is to run skaffold dev to develop my application, and use control-c when I am done working on it for the time being. I then resume with skaffold dev again the next day. This used to start the application in a few seconds (since the previous layers already existed). Now it results in 5 - 10 minutes of build time since it has to rebuild a multi-gigabit docker image.

I believe we should either:

  • Update skaffold to only delete new layers that it is responsible for
  • Disable image cleanup (pruning) as a default

Information

  • Skaffold version: v0.28.0
  • Operating system: Ubuntu 18.10
  • Contents of skaffold.yaml:
apiVersion: skaffold/v1beta7
kind: Config
build:
  artifacts:
    - image: localhost:32000/app
deploy:
  helm:
    releases:
      - name: app
        chartPath: infrastructure/kube
        namespace: default
        setValueTemplates:
          image.repository: "{{.IMAGE_NAME}}"
          image.tag: "{{.DIGEST}}"
        imageStrategy:
          helm: {}
        valuesFiles:
          - infrastructure/kube/values.yaml

Steps to reproduce the behavior

  1. Run skaffold run once (to build and deploy an app)
  2. Run skaffold dev
  3. Control-c out of skaffold dev
  4. Run skaffold dev again
@tdickman tdickman changed the title Dev build cleanup deletes everything Dev build cleanup deletes all layers May 1, 2019
@tejal29
Copy link
Contributor

tejal29 commented May 7, 2019

The quick fix for you would be to use --no-prune flag on your command line.
You can also set environment variable
"SKAFFOLD_NO_PRUNE=false"

I was digging in to the cleanup code and i think that is the intended behaviour.
We delete images which are built by skaffold. So all layers mentioned in your global skaffold config will be deleted.
If you want to iterate a specific layer, then i would suggest add a skaffold.yaml for the layer and run skaffold dev on this skaffold.yaml.

e.g.

root/
skaffold.yaml
layer1/
  src/
  test/
layer2/
  src/
app/
  skaffold.yaml
  src/

So your workflow would be:

1. Build and deploy once
cd root
skaffold run 
2. Iterate over a specific layer.
skaffold dev -f app/skaffold.dev

Does that help?

@nkubala
Copy link
Contributor

nkubala commented May 7, 2019

skaffold does its pruning through the Force and PruneChildren options passed to the docker client call (or the --force-rm flag passed to docker build if building through the CLI). I think the majority of users iterating with skaffold dev don't want to see dozens or even hundreds of images stacking up in their docker daemon when they're done using skaffold, though I could be wrong.

I don't think we want to turn this off by default, but we could expose pruning options through the config - for your specific case, setting PruneChildren to false should fix your issue. it's not that skaffold is removing unrelated layers, but since the previously built layers are being reused in images build through your dev loop, they get cleaned up at the end.

would you be interested in sending a PR for this?

@charlyx
Copy link
Contributor

charlyx commented May 8, 2019

@nkubala I'm interested in sending a PR, if that's OK 😄

@priyawadhwa
Copy link
Contributor

@charlyx that would be great!

@nkubala
Copy link
Contributor

nkubala commented May 15, 2019

closed through #2113

@nkubala nkubala closed this as completed May 15, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

5 participants