Flowlance
Flowlance

Reputation: 3

Extending a Chef 12 resource (Ruby)

I'm using Amazon Opsworks with Chef 12. This comes with a built in resource called deploy (which was removed in chef 14).

My issue with deploy is that I need a custom release_slug

Currently the path to the release looks something like this:

/srv/www/development/releases/20180706123524

but i need my build id

/srv/www/development/releases/199

So I'm trying to extend Deploy, and replace the release_slug (20180706123524) with my custom ID. I can see in the chef source that this is exactly what they do with their timestamped deploy: https://github.com/chef/chef/blob/12.5-stable/lib/chef/provider/deploy/timestamped.rb

I found a similar stackoverflow question here https://stackoverflow.com/questions/16114469/how-to-extend-a-lightweight-provider-in-chef#=

This is what I have under /libraries in my cookbook:

deploy_slug.rb:

class Chef
    class Resource::DeploySlug < Resource::DeployRevision

        def initialize(name, run_context = nil)
            super
            @resource_name = :deploy_slug
        end
    end
end

Before trying to modify the release_slug, I just want the deployment to actually work using my custom resource. And in my recipe I'm trying to call it with deploy_slug.

This is the error I'm getting:

* deploy_slug[/srv/www/development] action deploy
================================================================================
Error executing action `deploy` on resource 'deploy_slug[/srv/www/development]'
================================================================================
Chef::Exceptions::ProviderNotFound

What am I missing here?

Upvotes: 0

Views: 258

Answers (1)

coderanger
coderanger

Reputation: 54249

To start with: this is not even remotely supported. You should not do this, it is a bad idea. This resource was removed from Chef specifically because it's not good to use. Use a simple git resource instead.

That said, the issue is that you need to also subclass Provider::Deploy::Revision and map it to your new resource via a provides :deploy_slug.

Upvotes: 0

Related Questions