The containers are often built twice, first by the run_if_missing action, and then again by the redeploy action
The run_if_missing action does not observe dependencies, so container1’s run_if_missing action is actually invoked before container2 even exists, causing a build failure.
Obviously, I could circumvent this by changing the default action to :nothing, but then the containers aren’t built at all if they are missing.
Also, using :immediate for the subscriptions is not an option (because then the redeploy action may get invoked too early and multiple times, and various other problems).
The containers are often built twice, first by the run_if_missing action, and then again by the redeploy action
The run_if_missing action does not observe dependencies, so container1's run_if_missing action is actually invoked before container2 even exists, causing a build failure.
Don't you have a problem in your recipes order ? Out of notifications,
you should ensure the run_list is coherent with the timeline of your
provisionning, if the container2 was before container1 in the resource
appearance order, it will be built before.
Another option could be to set a flag 'already_run' to define the
subscribe attributes' only after first run, something along:
docker_container container1 do
action :run_if_missing
subscribe :redeploy, "docker_image[image1] if node.tagged?('flag')
subscribe :redeploy, "docker_container[container2] if
node.tagged?('flag')
end
At end of recipe (could be improved to handle failure by doing it in a
ruby_block and using notifications.)
node.tag('flag') # Flag could be generic or something named by container
for a more precise approch
Obviously, I could circumvent this by changing the default action to :nothing, but then the containers aren't built at all if they are missing.
Also, using :immediate for the subscriptions is not an option (because then the redeploy action may get invoked too early and multiple times, and various other problems).
you probably want :run instead of :run_if_missing if you're launching a
long running service. It's safe across multiple runs and will repair the
container in the event of a crash or out-of-band administrative actions.
Remember, :delayed notify/subscribes are queued until after the end of
the chef-client converge.
Avoid spreading resources with notify/subscribe relationships across
multiple cookbooks. It creates a semantic dependency relationship between
them that's extremely difficult to reason about and test. The same recipe
is best.
The containers are often built twice, first by the run_if_missing
action, and then again by the redeploy action
The run_if_missing action does not observe dependencies, so container1's
run_if_missing action is actually invoked before container2 even exists,
causing a build failure.
Obviously, I could circumvent this by changing the default action to
:nothing, but then the containers aren't built at all if they are missing.
Also, using :immediate for the subscriptions is not an option (because
then the redeploy action may get invoked too early and multiple times, and
various other problems).