Skip to content

Instantly share code, notes, and snippets.

@jkeiser
Last active October 13, 2015 17:15
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save jkeiser/bce2b79e5f6874d1c801 to your computer and use it in GitHub Desktop.
Save jkeiser/bce2b79e5f6874d1c801 to your computer and use it in GitHub Desktop.
# In your recipe, do this at the top to monkeypatch the service resource the way we want:
Chef::Resource::DockerService.class_eval do
property :consumed_resources_updated, Boolean
def consumes(resource)
subscribes :consumed_resource_updated, resource, :immediately
subscribes :run, resource
end
action :consumed_resource_updated do
new_resource.consumed_resources_updated true
end
module NewCreateAction
def action_create
super
new_resource.reset_property(:consumed_resources_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 '/files'
template '/files/some_config.ini' do
variables(foo: node['bar'])
action :create
end
template '/files/another_config.ini' do
variables(foo: node['biz'])
action :create
end
docker_image 'some_image' do
tag node['external']['data']
action :pull_if_missing
end
docker_container 'some_container' do
tag node['external']['data']['tag']
port node['external']['data']['port']
command 'my_program'
binds "/files:/etc/myprogram/conf.d"
consumes 'docker_image[some_image]'
consumes 'template[/files/some_config.ini]'
consumes 'template[/files/another_config.ini]'
action :run
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment