RE: Re: docker cookbook and idempotency


#1

Yeah, I kinda thought that it would be difficult to implement idempotency.

I’m not sure the build_if_missing would work, because of resource ordering. If I understand you correctly, you are suggesting something like this:

docker_image "myimage do

action :build_if_missing

end

remote_directory “/tmp/mydockercontext” do

notifies :build, “docker_image[myimage]”

end

But with this order, the docker image would be built before the context is set up.

Reversing the order of the resources would break the notification, because you cannot notify resources that come later in the recipe. Or am I mistaken about that?

Kevin Keane

The NetTech

http://www.4nettech.com

Our values: Privacy, Liberty, Justice

See https://www.4nettech.com/corp/the-nettech-values.html

-----Original message-----
From: Sean OMeara someara@chef.io
Sent: Tuesday 1st September 2015 1:09
To: chef@lists.opscode.com
Subject: [chef] Re: docker cookbook and idempotency

Hi Kevin

Unfortunately, :build will perform work on every chef-client run. There isn’t really a way to “check” to see if the image contents are out of date given the inputs.

I’d have your build context notify a docker_image with the :build_if_missing action set.

-s

On Tue, Sep 1, 2015 at 12:21 AM, Kevin Keane Subscription <subscription@kkeane.com mailto:subscription@kkeane.com > wrote:

I love the docker cookbook - thanks to those who created and maintain it!

That said, there are a few things I’m trying to understand better. Specifically, how does idempotency work with the docker_image :build action? Does this rebuild the image on every chef run, or only when the build context has changed?

Currently, I am using a notification to rebuild the image when the build context has changed. But this is unsatisfactory because when the context is already up to date but the image is outdated or missing, it will not trigger a rebuild.

How do I solve this?

Kevin Keane

The NetTech

http://www.4nettech.com http://www.4nettech.com

Our values: Privacy, Liberty, Justice

See https://www.4nettech.com/corp/the-nettech-values.html


#2

On Tuesday, September 1, 2015 at 7:25 AM, Kevin Keane Subscription wrote:

RE: [chef] Re: docker cookbook and idempotency
Yeah, I kinda thought that it would be difficult to implement idempotency.

I’m not sure the build_if_missing would work, because of resource ordering. If I understand you correctly, you are suggesting something like this:

docker_image "myimage do

action :build_if_missing
end

remote_directory “/tmp/mydockercontext” do

notifies :build, "docker_image[myimage]"
end
But with this order, the docker image would be built before the context is set up.
Reversing the order of the resources would break the notification, because you cannot notify resources that come later in the recipe. Or am I mistaken about that?

That used to be the case a really long time ago, but it’s supported on any version of Chef that you’re likely to be using.

Kevin Keane
The NetTech


Daniel DeLeo


#3

You would be mistaken about that. That’s one of the things the compilation
phase lets you do. =)
-s

On Tue, Sep 1, 2015 at 4:25 PM, Kevin Keane Subscription <
subscription@kkeane.com> wrote:

Yeah, I kinda thought that it would be difficult to implement idempotency.

I’m not sure the build_if_missing would work, because of resource
ordering. If I understand you correctly, you are suggesting something
like this:

docker_image "myimage do

action :build_if_missing

end

remote_directory “/tmp/mydockercontext” do

notifies :build, “docker_image[myimage]”

end

But with this order, the docker image would be built before the context is
set up.

Reversing the order of the resources would break the notification, because
you cannot notify resources that come later in the recipe. Or am I mistaken
about that?

Kevin Keane

The NetTech

http://www.4nettech.com

Our values: Privacy, Liberty, Justice

See https://www.4nettech.com/corp/the-nettech-values.html

-----Original message-----
From: Sean OMeara someara@chef.io
Sent: Tuesday 1st September 2015 1:09
To: chef@lists.opscode.com
Subject: [chef] Re: docker cookbook and idempotency

Hi Kevin

Unfortunately, :build will perform work on every chef-client run. There
isn’t really a way to “check” to see if the image contents are out of date
given the inputs.

I’d have your build context notify a docker_image with the
:build_if_missing action set.

-s

On Tue, Sep 1, 2015 at 12:21 AM, Kevin Keane Subscription <
subscription@kkeane.com> wrote:

I love the docker cookbook - thanks to those who created and maintain it!

That said, there are a few things I’m trying to understand better.
Specifically, how does idempotency work with the docker_image :build
action? Does this rebuild the image on every chef run, or only when the
build context has changed?

Currently, I am using a notification to rebuild the image when the build
context has changed. But this is unsatisfactory because when the context is
already up to date but the image is outdated or missing, it will not
trigger a rebuild.

How do I solve this?

Kevin Keane

The NetTech

http://www.4nettech.com

Our values: Privacy, Liberty, Justice

See https://www.4nettech.com/corp/the-nettech-values.html


#4

PS: you probably also want to use the :immediately notification timing.

I’m just going out on a limb here and assuming you’ll have a
docker_container resource in your recipe coming up soon.

The default is :delayed, which will wait until the end of the chef-client
run.

remote_directory “/tmp/mydockercontext” do

notifies :build, “docker_image[myimage]”, :immediately

end

docker_image “myimage” do

action :build_if_missing

end

docker_container ‘my_thang’ do

repo ‘myimage’

end

On Tue, Sep 1, 2015 at 4:25 PM, Kevin Keane Subscription <
subscription@kkeane.com> wrote:

Yeah, I kinda thought that it would be difficult to implement idempotency.

I’m not sure the build_if_missing would work, because of resource
ordering. If I understand you correctly, you are suggesting something
like this:

docker_image "myimage do

action :build_if_missing

end

remote_directory “/tmp/mydockercontext” do

notifies :build, “docker_image[myimage]”

end

But with this order, the docker image would be built before the context is
set up.

Reversing the order of the resources would break the notification, because
you cannot notify resources that come later in the recipe. Or am I mistaken
about that?

Kevin Keane

The NetTech

http://www.4nettech.com

Our values: Privacy, Liberty, Justice

See https://www.4nettech.com/corp/the-nettech-values.html

-----Original message-----
From: Sean OMeara someara@chef.io
Sent: Tuesday 1st September 2015 1:09
To: chef@lists.opscode.com
Subject: [chef] Re: docker cookbook and idempotency

Hi Kevin

Unfortunately, :build will perform work on every chef-client run. There
isn’t really a way to “check” to see if the image contents are out of date
given the inputs.

I’d have your build context notify a docker_image with the
:build_if_missing action set.

-s

On Tue, Sep 1, 2015 at 12:21 AM, Kevin Keane Subscription <
subscription@kkeane.com> wrote:

I love the docker cookbook - thanks to those who created and maintain it!

That said, there are a few things I’m trying to understand better.
Specifically, how does idempotency work with the docker_image :build
action? Does this rebuild the image on every chef run, or only when the
build context has changed?

Currently, I am using a notification to rebuild the image when the build
context has changed. But this is unsatisfactory because when the context is
already up to date but the image is outdated or missing, it will not
trigger a rebuild.

How do I solve this?

Kevin Keane

The NetTech

http://www.4nettech.com

Our values: Privacy, Liberty, Justice

See https://www.4nettech.com/corp/the-nettech-values.html