chef-boneyard / knife-container

DEPRECATED: Container support for Chef's Knife Command
Apache License 2.0
57 stars 11 forks source link

Confused about re-building an image using --force #18

Closed jf647 closed 10 years ago

jf647 commented 10 years ago

I'm a bit confused about how knife-container uses tags when rebuilding images. Here's my use case:

  1. run knife container docker init foo. At this point there is a docker tag 'foo' pointing to the same image as chef/ubuntu-12.04
  2. hack around on recipes for foo,but accidentally get something wrong (let's say I pull in a recipe that builds nodejs from source when I needed to flip an attribute to use packages)
  3. run knife container docker build foo. The recipes goes along and builds, but is way bigger than I want it to be because it contains the build toolchain when I just wanted runtime binaries. However, at this point the docker tag 'foo' has moved to point to this new image.
  4. fix the attribute file to do what I wanted in the first place
  5. run knife container docker build foo --force. This builds what I wanted, but the image is even large than that created after step 3

The issue seems to be that the Dockerfile created starts "FROM foo", which makes sense the first time but not the second. I want to throw out what I had build incorrectly and start over from chef/ubuntu-12.04, not iterate on top of a (possibly) broken image.

Given that the first command in the generated Dockerfile is ADD, there is zero chance of getting a cache hit on re-builds, so it seems like we should always start from the base image.

My fix was to move the tag 'foo' back to the same image as chef/ubuntu-12.04 and re-run the build step. This produced the image I wanted in the first place.

Am I missing something? Is --force not meant to be used in this scenario, and if so what should I have done differently? Untagged 'foo', removed the cookbooks folder and start over without --force?

tduffield commented 10 years ago

What knife container docker build --force is intended to do is pass force down to things like Berkshelf. What you're looking for will be called knife container docker rebuild and should be out in the very near future. The process that docker rebuild will automate is retagging your base image (i.e. chef/ubuntu-12.04) as the image name, deleting your headless image and then rerunning knife container docker build. Does this make sense?

jf647 commented 10 years ago

That makes perfect sense. I saw that there were updates to things like chef-init in master vs the one in the base image (e.g. --verify), so I figured things might still be in flux. Thanks.

ringods commented 10 years ago

While the rebuild option is not there yet, can I mimick this by changing my FROM image to chef/buntu-12.04:latest in the Dockerfile? I would like to have a clean build every time build this image on my CI server.

tduffield commented 10 years ago

Yes - that is the way to do it if you want to converge from a fresh image every single time.