Skip to content

Instantly share code, notes, and snippets.

@chasebolt
Forked from jkeiser/depends_on.rb
Last active Oct 13, 2015
Embed
What would you like to do?
Chef::Resource::DockerContainer.class_eval do
property :dependencies_updated, [true, false]
def depends_on(resource)
subscribes :dependencies_updated, resource, :immediately
subscribes :run, resource
end
action :dependencies_updated do
new_resource.dependencies_updated true
end
module NewCreateAction
def action_create
super
new_resource.reset_property(:dependencies_updated)
end
end
# This puts NewCreateAction::action_create as the first thing called, and super() == DockerContainer::action_create
action_class.prepend NewCreateAction
end
# And then change subscribes to depends_on in your recipe:
directory '/tmp'
file '/tmp/some_config.ini' do
content 'blah'
action :create
end
file '/tmp/another_config.ini' do
content 'blah'
action :create
end
docker_image 'alpine' do
tag 'latest'
action :pull_if_missing
end
docker_container 'alpine' do
command 'sleep 3000'
depends_on 'docker_image[some_image]'
depends_on 'file[/tmp/some_config.ini]'
depends_on 'file[/tmp/another_config.ini]'
action :run
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment