Skip to content

Instantly share code, notes, and snippets.

@chasebolt
Forked from jkeiser/depends_on.rb
Last active October 13, 2015 03:11
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save chasebolt/4a3ff4aac332a66c392e to your computer and use it in GitHub Desktop.
Save chasebolt/4a3ff4aac332a66c392e to your computer and use it in GitHub Desktop.
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