Code Monkey home page Code Monkey logo

application's Introduction

Poise

Build Status Gem Version Cookbook Version Coverage Gemnasium License

What is Poise?

The poise cookbook is a set of libraries for writing reusable cookbooks. It provides helpers for common patterns and a standard structure to make it easier to create flexible cookbooks.

Writing your first resource

Rather than LWRPs, Poise promotes the idea of using normal, or "heavy weight" resources, while including helpers to reduce much of boilerplate needed for this. Each resource goes in its own file under libraries/ named to match the resource, which is in turn based on the class name. This means that the file libraries/my_app.rb would contain Chef::Resource::MyApp which maps to the resource my_app.

An example of a simple shell to start from:

require 'poise'
require 'chef/resource'
require 'chef/provider'

module MyApp
  class Resource < Chef::Resource
    include Poise
    provides(:my_app)
    actions(:enable)

    attribute(:path, kind_of: String)
    # Other attribute definitions.
  end

  class Provider < Chef::Provider
    include Poise
    provides(:my_app)

    def action_enable
      notifying_block do
        ... # Normal Chef recipe code goes here
      end
    end
  end
end

Starting from the top, first we require the libraries we will be using. Then we create a module to hold our resource and provider. If your cookbook declares multiple resources and/or providers, you might want additional nesting here. Then we declare the resource class, which inherits from Chef::Resource. This is similar to the resources/ file in an LWRP, and a similar DSL can be used. We then include the Poise mixin to load our helpers, and then call provides(:my_app) to tell Chef this class will implement the my_app resource. Then we use the familiar DSL, though with a few additions we'll cover later.

Then we declare the provider class, again similar to the providers/ file in an LWRP. We include the Poise mixin again to get access to all the helpers and call provides() to tell Chef what provider this is. Rather than use the action :enable do ... end DSL from LWRPs, we just define the action method directly. The implementation of action comes from a block of recipe code wrapped with notifying_block to capture changes in much the same way as use_inline_resources, see below for more information about all the features of notifying_block.

We can then use this resource like any other Chef resource:

my_app 'one' do
  path '/tmp'
end

Helpers

While not exposed as a specific method, Poise will automatically set the resource_name based on the class name.

Notifying Block

As mentioned above, notifying_block is similar to use_inline_resources in LWRPs. Any Chef resource created inside the block will be converged in a sub-context and if any have updated it will trigger notifications on the current resource. Unlike use_inline_resources, resources inside the sub-context can still see resources outside of it, with lookups propagating up sub-contexts until a match is found. Also any delayed notifications are scheduled to run at the end of the main converge cycle, instead of the end of this inner converge.

This can be used to write action methods using the normal Chef recipe DSL, while still offering more flexibility through subclassing and other forms of code reuse.

Include Recipe

In keeping with notifying_block to implement action methods using the Chef DSL, Poise adds an include_recipe helper to match the method of the same name in recipes. This will load and converge the requested recipe.

Resource DSL

To make writing resource classes easier, Poise exposes a DSL similar to LWRPs for defining actions and attributes. Both actions and default_action are just like in LWRPs, though default_action is rarely needed as the first action becomes the default. attribute is also available just like in LWRPs, but with some enhancements noted below.

One notable difference over the standard DSL method is that Poise attributes can take a block argument.

Template Content

A common pattern with resources is to allow passing either a template filename or raw file content to be used in a configuration file. Poise exposes a new attribute flag to help with this behavior:

attribute(:name, template: true)

This creates four methods on the class, name_source, name_cookbook, name_content, and name_options. If the name is set to '', no prefix is applied to the function names. The content method can be set directly, but if not set and source is set, then it will render the template and return it as a string. Default values can also be set for any of these:

attribute(:name, template: true, default_source: 'app.cfg.erb',
          default_options: {host: 'localhost'})

As an example, you can replace this:

if new_resource.source
  template new_resource.path do
    source new_resource.source
    owner 'app'
    group 'app'
    variables new_resource.options
  end
else
  file new_resource.path do
    content new_resource.content
    owner 'app'
    group 'app'
  end
end

with simply:

file new_resource.path do
  content new_resource.content
  owner 'app'
  group 'app'
end

As the content method returns the rendered template as a string, this can also be useful within other templates to build from partials.

Lazy Initializers

One issue with Poise-style resources is that when the class definition is executed, Chef hasn't loaded very far so things like the node object are not yet available. This means setting defaults based on node attributes does not work directly:

attribute(:path, default: node['myapp']['path'])
...
NameError: undefined local variable or method 'node'

To work around this, Poise extends the idea of lazy initializers from Chef recipes to work with resource definitions as well:

attribute(:path, default: lazy { node['myapp']['path'] })

These initializers are run in the context of the resource object, allowing complex default logic to be moved to a method if desired:

attribute(:path, default: lazy { my_default_path })

def my_default_path
  ...
end

Option Collector

Another common pattern with resources is to need a set of key/value pairs for configuration data or options. This can done with a simple Hash, but an option collector attribute can offer a nicer syntax:

attribute(:mydata, option_collector: true)
...

my_app 'name' do
  mydata do
    key1 'value1'
    key2 'value2'
  end
end

This will be converted to {key1: 'value1', key2: 'value2'}. You can also pass a Hash to an option collector attribute just as you would with a normal attribute.

Debugging Poise

Poise has its own extra-verbose level of debug logging that can be enabled in three different ways. You can either set the environment variable $POISE_DEBUG, set a node attribute node['POISE_DEBUG'], or touch the file /POISE_DEBUG. You will see a log message Extra verbose logging enabled at the start of the run to confirm Poise debugging has been enabled. Make sure you also set Chef's log level to debug, usually via -l debug on the command line.

Upgrading from Poise 1.x

The biggest change when upgrading from Poise 1.0 is that the mixin is no longer loaded automatically. You must add require 'poise' to your code is you want to load it, as you would with normal Ruby code outside of Chef. It is also highly recommended to add provides(:name) calls to your resources and providers, this will be required in Chef 13 and will display a deprecation warning if you do not. This also means you can move your code out of the Chef module namespace and instead declare it in your own namespace. An example of this is shown above.

Sponsors

The Poise test server infrastructure is generously sponsored by Rackspace. Thanks Rackspace!

License

Copyright 2013-2016, Noah Kantrowitz

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

application's People

Contributors

albandiguer avatar bfritz avatar bmironenko avatar cap10morgan avatar chrisroberts avatar coderanger avatar eczajk1 avatar erikfrey avatar ezotrank avatar grantr avatar guilhem avatar hungryblank avatar iafonov avatar jcoleman avatar josephholsten avatar jregeimbal avatar jschneiderhan avatar kesor avatar kevinreedy avatar lamont-granquist avatar nathenharvey avatar schisamo avatar sethvargo avatar tojofo avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

application's Issues

before_symlink in new version 5.x

According to the README it says that since version 5.x the deploy properties have been removed.
Is there a way to achieve something like before_symlink in 5.x?

I had a few steps running 'before' the application does the final 'symlink' and not quite sure how I could achieve this with the new version.

Support resource 'guards'?

This would be fantastic to have, and seems to make sense to me as one typically trying to abide by most Foodcritic rules:

application 'whatever' do
  only_if ...
end

unable to deploy rails application

Hi,
I have been attempting to setup a chef recipe which installs ruby using bundle_install and then uses the application_ruby cookbook to configure the application.
I have the following error :
NameError : No resource found for bundle install

metadata.rb is missing

Hello,

Since there has not been a release of this cookbook in over a year, we have been using what is in the development git repository since keep_releases is broken in the officially released application cookbook on supermarket.

It seems that in a recent commit, metadata.rb has been removed and is breaking Berkshelf's dependency resolution when pointed at the repo. Can it be replaced, and can we possibly get some new tagged releases out? :)

SVN authentication support

Can you add official svn authentication support to application?
I can't find an easy way to pass svn_username and svn_password to application's deploy_revision resource.

Guideline request - difference from artifact-cookbook and deploy_revision

I'm trying to find out how this cookbook differs (or overlaps) with the artifact-cookbook and the Chef built in deploy_revision logic.

Can you provide a bit of explanation please?

I want to move towards a managed LWRP setup for deploying packaged code or binary distributions (such as WAR files) and so far I've done all of the work manually (eg copying files around, cleaning up releases myself, updating symlinks myself, etc). I'd like to know how to choose which cookbook to use.

find_matching_role only searches top-level roles

I want to have a role defining a group of application_server-roles. But then the load_balancer is not picking up the nodes as find_matching_role only searches for "role:" instead of "roles:".

Could this be changed?

shallow_clone default causing difficulty with newer versions of git

I experienced the same issue as #49, but it isn't specific to Ubuntu, but is caused by using a newer version of git.

In order to sync a different branch than the one that is checked out I had to set shallow_clone to false before checking it out (on my existing node I deleted cached_copy to ensure that this happened when I ran chef-client).

When shallow_clone is not set to false, it can't sync to a revision that isn't merged to the revision that's checked out (in this case it's master).

On the deploy cookbook, shallow_clone defaults to false. I think it would be easier to use this application cookbook with newer distros if shallow_clone also defaulted to false.

path is not the "name-attribute" anymore

Got this error with latest supermarket version:

    ArgumentError
    -------------
    You must supply a name when declaring a directory resource

    Cookbook Trace:
    ---------------
    /var/chef/cache/cookbooks/application/providers/default.rb:75:in `before_deploy'
    /var/chef/cache/cookbooks/application/providers/default.rb:27:in `block in class_from_file

Please update documentation.

fix by setting path attribute explicitly

uninitialized constant Chef::DSL

Hiya, first off, thanks for the cookbook, ruby_application looks awesome.

I'm fairly new to Chef, but I seem to be getting an odd error with the latest version of application/application_ruby when I'm following this guide:
http://www.concreteinteractive.com/how-to-deploy-a-rails-application-anywhere-with-chef/

The stacktrace from the error I'm getting is:

โžœ  chef-repo git:(master) โœ— vagrant up            
Bringing machine 'default' up with 'virtualbox' provider...
[default] Importing base box 'precise64'...
[default] Matching MAC address for NAT networking...
[default] Setting the name of the VM...
[default] Clearing any previously set forwarded ports...
[default] Clearing any previously set network interfaces...
[default] Preparing network interfaces based on configuration...
[default] Forwarding ports...
[default] -- 22 => 2222 (adapter 1)
[default] Booting VM...
[default] Waiting for machine to boot. This may take a few minutes...
[default] Machine booted and ready!
[default] Mounting shared folders...
[default] -- /vagrant
[default] -- /tmp/vagrant-chef-1/chef-solo-3/roles
[default] -- /tmp/vagrant-chef-1/chef-solo-2/cookbooks
[default] -- /tmp/vagrant-chef-1/chef-solo-1/cookbooks
[default] -- /tmp/vagrant-chef-1/chef-solo-4/data_bags
[default] Running provisioner: chef_solo...
Generating chef JSON and uploading...
Running chef-solo...
stdin: is not a tty
[2014-01-18T03:53:39+00:00] INFO: *** Chef 10.14.2 ***
[2014-01-18T03:53:40+00:00] INFO: Setting the run_list to ["recipe[dev-chatter]"] from JSON
[2014-01-18T03:53:40+00:00] INFO: Run List is [recipe[dev-chatter]]
[2014-01-18T03:53:40+00:00] INFO: Run List expands to [dev-chatter]
[2014-01-18T03:53:40+00:00] INFO: Starting Chef Run for precise64
[2014-01-18T03:53:40+00:00] INFO: Running start handlers
[2014-01-18T03:53:40+00:00] INFO: Start handlers complete.

================================================================================
Recipe Compile Error in /tmp/vagrant-chef-1/chef-solo-1/cookbooks/application/resources/default.rb
================================================================================

NameError
---------
uninitialized constant Chef::DSL

Cookbook Trace:
---------------
  /tmp/vagrant-chef-1/chef-solo-1/cookbooks/application/resources/default.rb:23:in `class_from_file'

Relevant File Content:
----------------------
/tmp/vagrant-chef-1/chef-solo-1/cookbooks/application/resources/default.rb:

  1:  #
  2:  # Author:: Noah Kantrowitz <[email protected]>
  3:  # Cookbook Name:: application
  4:  # Resource:: default
  5:  #
  6:  # Copyright:: 2011-2012, Opscode, Inc <[email protected]>
  7:  #
  8:  # Licensed under the Apache License, Version 2.0 (the "License");
  9:  # you may not use this file except in compliance with the License.

[2014-01-18T03:53:40+00:00] ERROR: Running exception handlers
[2014-01-18T03:53:40+00:00] ERROR: Exception handlers complete
[2014-01-18T03:53:40+00:00] FATAL: Stacktrace dumped to /var/chef/cache/chef-stacktrace.out
[2014-01-18T03:53:40+00:00] FATAL: NameError: uninitialized constant Chef::DSL
Chef never successfully completed! Any errors should be visible in the
output above. Please fix your recipes so that they properly complete.

The versions after running the librarian-chef are:

โžœ  chef-repo git:(master) โœ— librarian-chef install                                            
Installing apache2 (1.8.14)
Installing application (4.1.4)
Installing logrotate (1.4.0)
Installing build-essential (1.4.2)
Installing passenger_apache2 (2.1.2)
Installing yum (3.0.4)
Installing yum-epel (0.2.0)
Installing runit (1.5.8)
Installing unicorn (1.3.0)
Installing application_ruby (3.0.2)
Installing apt (2.3.4)
Installing ruby_build (0.8.0)
Installing user (0.3.0)

System settings:

โžœ  chef-repo git:(master) โœ— ruby -v
ruby 2.0.0p353 (2013-11-22 revision 43784) [x86_64-darwin13.0.0]

โžœ  chef-repo git:(master) โœ— gem -v librarian-chef
2.0.14

โžœ  chef-repo git:(master) โœ— vagrant -v
Vagrant 1.4.3

To get around this bug, I've downgraded application and application_ruby, so it works with these versions:

Installing apache2 (1.8.14)
Installing application (3.0.0)
Installing logrotate (1.4.0)
Installing build-essential (1.4.2)
Installing passenger_apache2 (2.1.2)
Installing yum (3.0.4)
Installing yum-epel (0.2.0)
Installing runit (1.5.8)
Installing unicorn (1.3.0)
Installing application_ruby (2.1.4)
Installing apt (2.3.4)
Installing ruby_build (0.8.0)
Installing user (0.3.0)

[Chef 12.0] Cannot find a provider for deploy_revision[application] on ubuntu version 12.04

This looks to be related with the changes in Chef 12 regarding recipe DSL and providers.

================================================================================       
  Error executing action `deploy` on resource 'deploy_revision[nodejs application]'       
  ================================================================================       

  ArgumentError       
  -------------       
  Cannot find a provider for deploy_revision[nodejs application] on ubuntu version 12.04       

  Cookbook Trace:       
  ---------------       
  /tmp/kitchen/cache/cookbooks/application/libraries/default.rb:144:in `deploy_provider'       
  /tmp/kitchen/cache/cookbooks/application/libraries/default.rb:152:in `release_path'       
  /tmp/kitchen/cache/cookbooks/nodestack/recipes/application_nodejs.rb:93:in `block (3 levels) in from_file'       
  /tmp/kitchen/cache/cookbooks/application/libraries/default.rb:189:in `safe_recipe_eval'       
         /tmp/kitchen/cache/cookbooks/application/libraries/default.rb:165:in `callback'
         /tmp/kitchen/cache/cookbooks/application/providers/default.rb:193:in `run_actions_with_context'
         /tmp/kitchen/cache/cookbooks/application/providers/default.rb:172:in `block (2 levels) in run_deploy'

Using ~/foo as application path creates /~/foo directory (linux)

Resources are copied to //foo
e.g. /
/foo/id_deploy (if using a deploy key for a git repo)

Expected behavior is to copy data to chef user's home folder (probably /root/ if chef running as root).

HOWEVER
some code and scripts interprets '~/' correctly and then gets upset because it cannot find resources e.g.
git ssh wrapper looks for keys in /root/foo/id_deploy ... which does not exist

Can you do a release please.

I need the deploy_key feature which has been updated in documentation but to not released yet (which was fun to figure out).

Status of this cookbook/documentation

This cookbook looks comprehensive but is no longer maintained? Or is the documentation not up-to-date? I noticed that many of the examples don't work. For example snippet below does not work. git needs to be path. And bundle_install is not a resource!? unicorn also does not exist!?

application '/opt/test_sinatra' do
  git 'https://github.com/example/my_sinatra_app.git'
  bundle_install do
    deployment true
  end
  unicorn do
    port 9000
  end
end

uninitialized error

I keep getting this error and I'm not sure how to fix it.
I'm running on Chef 12.13.37
this is with app

cookbook 'application', '~> 5.2.0'
cookbook 'application_git', '~> 1.2.0'
NameError
---------
uninitialized constant Chef::Provider::ApplicationCookbook
 
Cookbook Trace:
---------------
/var/chef/runs/0cb47e0c-a8f5-468e-ba5f-c83c8784a522/local-mode-cache/cache/cookbooks/application/providers/default.rb:21:in `class_from_file'

14:  # Unless required by applicable law or agreed to in writing, software
15:  # distributed under the License is distributed on an "AS IS" BASIS,
16:  # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17:  # See the License for the specific language governing permissions and
18:  # limitations under the License.
19:  #
20:  
21>> include ApplicationCookbook::ProviderBase
22:  
23:  action :deploy do
24:  
25:    before_compile
26:  
27:    before_deploy
28:  
29:    run_deploy

Cannot deploy nodejs application with error "NoMethodError: undefined method `owner' for Chef::Resource::DeployRevision"

Dear guy,

I cannot deploy a nodejs app with application & application_nodejs cookbook.

My environment :

  1. Chef 11.12.2
  2. Application : 4.1.4
  3. Application_nodejs : 2.0.1
  4. Ubuntu 12.04 LTS

Full error :
"[2014-06-02T10:51:51+00:00] INFO: Running queued delayed notifications before re-raising exception
[2014-06-02T10:51:51+00:00] ERROR: Running exception handlers
[2014-06-02T10:51:51+00:00] ERROR: Exception handlers complete
[2014-06-02T10:51:51+00:00] FATAL: Stacktrace dumped to /var/chef/cache/chef-stacktrace.out
[2014-06-02T10:51:51+00:00] ERROR: deploy_revision[xxxx](/tmp/vagrant-chef-1/chef-solo-1/cookbooks/application/providers/default.rb line 123) had an error: NoMethodError: undefined method `owner' for Chef::Resource::DeployRevision
[2014-06-02T10:51:51+00:00] FATAL: Chef::Exceptions::ChildConvergeError: Chef run process exited unsuccessfully (exit code 1)"

Any idea?

Regards,
Phung Le.

Cookbook failing to compile with chef-client 14.5.33

I have this cookbook in my list of dependencies for a run list that is failing with the following message during my chef-client runs:

================================================================================
Recipe Compile Error in /var/chef/cache/cookbooks/application/libraries/default.rb
================================================================================

FrozenError
-----------
can't modify frozen Array

Cookbook Trace:
---------------
  /var/chef/cache/cookbooks/poise/files/halite_gem/poise/helpers/subresources/container.rb:220:in `included'
  /var/chef/cache/cookbooks/poise/files/halite_gem/poise/resource.rb:51:in `include'
  /var/chef/cache/cookbooks/poise/files/halite_gem/poise/resource.rb:51:in `poise_subresource_container'
  /var/chef/cache/cookbooks/poise/files/halite_gem/poise.rb:93:in `block in Poise'
  /var/chef/cache/cookbooks/application/files/halite_gem/poise_application/resources/application.rb:45:in `include'
  /var/chef/cache/cookbooks/application/files/halite_gem/poise_application/resources/application.rb:45:in `<class:Resource>'
  /var/chef/cache/cookbooks/application/files/halite_gem/poise_application/resources/application.rb:44:in `<module:Application>'
  /var/chef/cache/cookbooks/application/files/halite_gem/poise_application/resources/application.rb:27:in `<module:Resources>'
  /var/chef/cache/cookbooks/application/files/halite_gem/poise_application/resources/application.rb:24:in `<module:PoiseApplication>'
  /var/chef/cache/cookbooks/application/files/halite_gem/poise_application/resources/application.rb:23:in `<top (required)>'
  /var/chef/cache/cookbooks/application/files/halite_gem/poise_application/resources.rb:17:in `<top (required)>'
  /var/chef/cache/cookbooks/application/files/halite_gem/poise_application/cheftie.rb:17:in `<top (required)>'
  /var/chef/cache/cookbooks/application/libraries/default.rb:19:in `<top (required)>'

Relevant File Content:
----------------------
/var/chef/cache/cookbooks/poise/files/halite_gem/poise/helpers/subresources/container.rb:

213:                @container_default
214:              end
215:            end
216:
217:            def included(klass)
218:              super
219:              klass.extend(ClassMethods)
220>>             klass.const_get(:HIDDEN_IVARS) << :@subcontexts
221:              klass.const_get(:FORBIDDEN_IVARS) << :@subcontexts
222:            end
223:          end
224:
225:          extend ClassMethods
226:        end
227:      end
228:    end
229:  end

Additional information:
-----------------------
      Ruby objects are often frozen to prevent further modifications
      when they would negatively impact the process (e.g. values inside
      Ruby's ENV class) or to prevent polluting other objects when default
      values are passed by reference to many instances of an object (e.g.
      the empty Array as a Chef resource default, passed by reference
      to every instance of the resource).

      Chef uses Object#freeze to ensure the default values of properties
      inside Chef resources are not modified, so that when a new instance
      of a Chef resource is created, and Object#dup copies values by
      reference, the new resource is not receiving a default value that
      has been by a previous instance of that resource.

      Instead of modifying an object that contains a default value for all
      instances of a Chef resource, create a new object and assign it to
      the resource's parameter, e.g.:

      fruit_basket = resource(:fruit_basket, 'default')

      # BAD: modifies 'contents' object for all new fruit_basket instances
      fruit_basket.contents << 'apple'

      # GOOD: allocates new array only owned by this fruit_basket instance
      fruit_basket.contents %w(apple)


System Info:
------------
chef_version=14.5.33
platform=oracle
platform_version=6.10
ruby=ruby 2.5.1p57 (2018-03-29 revision 63029) [x86_64-linux]
program_name=/usr/bin/chef-client
executable=/opt/chef/bin/chef-client


Running handlers:
Running handlers complete
Chef Client failed. 0 resources updated in 07 seconds

Git behavior regarding new commits in the production branch

Hi!

I'm trying to find some information about how this cookbook behaves when specifying a git repo. My desired behaviour would be to do an initial checkout when deploying a new server, but not checking out again automatically. I'm afraid of having an automatic, non authorized deploy to production if someone by mistake pushes something to the production branch. Also, if this cookbook deploys automatically, my CI tests will not make much sense.

Can someone explain me how this cookbook behaves in this situation? Thanks!

Faster deployments with git-based approach

There is a better (== much faster) approach do deploying, using git tags, instead of releases directories. See more here http://blog.codeclimate.com/blog/2013/10/02/high-speed-rails-deploys-with-git/ and here http://factore.ca/blog/278-how-we-reduced-rails-deploy-times-to-under-one-second-with-plain-git

Are there any plans or thoughts on implementing this approach? Currently I hacked around with this small utility method:

def files_changed?(repository, path_to_previous_revision, files)
  `cd #{repository} && git log HEAD...$(cat #{path_to_previous_revision}) -- #{files} | wc -l`.to_i > 0
end

that is then used in deployment callbacks as only_if guard. But it's kind of messy and still, it's not really git-tags solution. What do you think about?

Incompatibility with Ubuntu 14.04

I have been testing version 4.1.4 of this cookbook on Ubuntu 14.04 and I continue to get the following error whenever I try to deploy a branch that is out of sync with master:

==> default: ---- Begin output of git checkout -b deploy 031023767ab6c625443ef5c271986c70d8368da0 ----
==> default: STDOUT: 
==> default: STDERR: fatal: reference is not a tree: 031023767ab6c625443ef5c271986c70d8368da0
==> default: ---- End output of git checkout -b deploy 031023767ab6c625443ef5c271986c70d8368da0 ----
==> default: Ran git checkout -b deploy 031023767ab6c625443ef5c271986c70d8368da0 returned 128

If I merge the branch into master, and then try and redploy that same branch, the error goes away.

If I keep the branch out of sync, and revert back to an Ubuntu 12.04 OS, the problem never occurs.

Here is the cookbook I have written to test:

https://github.com/duro/application-cookbook-test

It is pointed at a private repo that is basically just a README that has a master and dev branch, with dev 1 commit ahead of master. The key embedded is a read only deploy key, so feel free to use it to test.

How do you use this cookbook?

Hey Noah,

Big fan of your blog, man.

I know this cookbook is in the middle of a rewrite. I've been following posting and github issues for both this project and the application_ruby cookbook over the last month or so, and I'm still not seeing much about how to USE these new cookbooks.

Any ETA on when the project will be complete? Do you need any help writing docs?

Regards,
Joe Reid

Notifications don't work for the application resource

Hi,

I'm using the application resource to deploy code and unfortunately I'm not able to use either notifies or subscribes whenever new code is deployed. I can see that new code is being pulled down, but it will never notify another resource about.

Has anyone else experienced this?

Thanks!

  application 'nodejs application' do
    path node['path']
    owner node['app_user']
    group node['app_user']
    repository node['git_repo']
    revision node['git_rev']
    notifies :restart, "service[application]", :delayed
  end

NoMethodError: undefined method `to_sym' for nil:NilClass

details TK, but this morning we generated this stacktrace:

Generated at 2017-01-10 12:09:17 -0800
NoMethodError: undefined method `to_sym' for nil:NilClass
Did you mean?  to_s
/var/cache/chef/cookbooks/poise/files/halite_gem/poise/helpers/resource_subclass.rb:38:in `subclass_providers!'
/var/cache/chef/cookbooks/application/files/halite_gem/poise_application/resources/application_cookbook_file.rb:43:in `<class
:Resource>'
/var/cache/chef/cookbooks/application/files/halite_gem/poise_application/resources/application_cookbook_file.rb:39:in `<modul
e:ApplicationCookbookFile>'
/var/cache/chef/cookbooks/application/files/halite_gem/poise_application/resources/application_cookbook_file.rb:24:in `<modul
e:Resources>'
/var/cache/chef/cookbooks/application/files/halite_gem/poise_application/resources/application_cookbook_file.rb:21:in `<modul
e:PoiseApplication>'
/var/cache/chef/cookbooks/application/files/halite_gem/poise_application/resources/application_cookbook_file.rb:20:in `<top (
required)>'
/usr/lib/ruby/2.3.0/rubygems/core_ext/kernel_require.rb:55:in `require'
/usr/lib/ruby/2.3.0/rubygems/core_ext/kernel_require.rb:55:in `require'
/var/cache/chef/cookbooks/application/files/halite_gem/poise_application/resources.rb:18:in `<top (required)>'
/usr/lib/ruby/2.3.0/rubygems/core_ext/kernel_require.rb:55:in `require'
/usr/lib/ruby/2.3.0/rubygems/core_ext/kernel_require.rb:55:in `require'
/var/cache/chef/cookbooks/application/files/halite_gem/poise_application/cheftie.rb:17:in `<top (required)>'
/usr/lib/ruby/2.3.0/rubygems/core_ext/kernel_require.rb:55:in `require'
/usr/lib/ruby/2.3.0/rubygems/core_ext/kernel_require.rb:55:in `require'
/var/cache/chef/cookbooks/application/libraries/default.rb:19:in `<top (required)>'
/usr/lib/ruby/vendor_ruby/chef/run_context/cookbook_compiler.rb:191:in `load'
/usr/lib/ruby/vendor_ruby/chef/run_context/cookbook_compiler.rb:191:in `block in load_libraries_from_cookbook'
/usr/lib/ruby/vendor_ruby/chef/run_context/cookbook_compiler.rb:188:in `each'
/usr/lib/ruby/vendor_ruby/chef/run_context/cookbook_compiler.rb:188:in `load_libraries_from_cookbook'
/usr/lib/ruby/vendor_ruby/chef/run_context/cookbook_compiler.rb:99:in `block in compile_libraries'
/usr/lib/ruby/vendor_ruby/chef/run_context/cookbook_compiler.rb:98:in `each'
/usr/lib/ruby/vendor_ruby/chef/run_context/cookbook_compiler.rb:98:in `compile_libraries'
/usr/lib/ruby/vendor_ruby/chef/run_context/cookbook_compiler.rb:71:in `compile'
/usr/lib/ruby/vendor_ruby/chef/run_context.rb:96:in `load'
/usr/lib/ruby/vendor_ruby/chef/policy_builder/expand_node_object.rb:87:in `setup_run_context'
/usr/lib/ruby/vendor_ruby/chef/client.rb:256:in `setup_run_context'
/usr/lib/ruby/vendor_ruby/chef/client.rb:454:in `run'
/usr/lib/ruby/vendor_ruby/chef/application.rb:271:in `block in fork_chef_client'
/usr/lib/ruby/vendor_ruby/chef/application.rb:259:in `fork'
/usr/lib/ruby/vendor_ruby/chef/application.rb:259:in `fork_chef_client'
/usr/lib/ruby/vendor_ruby/chef/application.rb:225:in `block in run_chef_client'
/usr/lib/ruby/vendor_ruby/chef/local_mode.rb:39:in `with_server_connectivity'
/usr/lib/ruby/vendor_ruby/chef/application.rb:213:in `run_chef_client'
/usr/lib/ruby/vendor_ruby/chef/application/client.rb:402:in `block in interval_run_chef_client'
/usr/lib/ruby/vendor_ruby/chef/application/client.rb:392:in `loop'
/usr/lib/ruby/vendor_ruby/chef/application/client.rb:392:in `interval_run_chef_client'
/usr/lib/ruby/vendor_ruby/chef/application/client.rb:382:in `run_application'
/usr/lib/ruby/vendor_ruby/chef/application.rb:60:in `run'
/usr/bin/chef-client:26:in `<main>'
[2017-01-10T12:16:14-08:00] INFO: Forking chef instance to converge...
[2017-01-10T12:16:14-08:00] INFO: *** Chef 12.3.0 ***
[2017-01-10T12:16:14-08:00] INFO: Chef-client pid: 13011
[2017-01-10T12:16:18-08:00] INFO: Run List is [role[tomato]]
[2017-01-10T12:16:18-08:00] INFO: Run List expands to [apt, avahi, chef-client, sudo, poise-python, ntp, postfix, slackmail,
undef-base-cb::users, undef-sensu, undef-sensu::ntp, chef-splunk, undef-base-cb::splunk, undef-sensu::splunk, nginx, undef-ba
se-cb, undef-sensu::master, undef-sensu::rabbitmq, undef-sensu::redis, redisio, redisio::enable]
[2017-01-10T12:16:18-08:00] INFO: Starting Chef Run for tomato
[2017-01-10T12:16:18-08:00] INFO: Running start handlers
[2017-01-10T12:16:18-08:00] INFO: Start handlers complete.
[2017-01-10T12:16:20-08:00] INFO: Loading cookbooks [[email protected], [email protected], [email protected], [email protected], cron
@3.0.0, [email protected], [email protected], [email protected], [email protected], [email protected], [email protected], [email protected], poise
[email protected], [email protected], [email protected], [email protected], [email protected], [email protected], [email protected], [email protected], ap
[email protected], [email protected], [email protected], [email protected], [email protected], [email protected], application_
[email protected], [email protected], [email protected], [email protected], [email protected], [email protected], [email protected], [email protected], [email protected]
.0, [email protected], [email protected], [email protected], [email protected], [email protected], [email protected], [email protected].
0, [email protected], [email protected], [email protected], [email protected], [email protected]]

================================================================================
Recipe Compile Error in /var/cache/chef/cookbooks/application/libraries/default.rb
================================================================================

NoMethodError
-------------
undefined method `to_sym' for nil:NilClass
Did you mean?  to_s

Cookbook Trace:
---------------
  /var/cache/chef/cookbooks/poise/files/halite_gem/poise/helpers/resource_subclass.rb:38:in `subclass_providers!'
  /var/cache/chef/cookbooks/application/files/halite_gem/poise_application/resources/application_cookbook_file.rb:43:in `<
class:Resource>'
  /var/cache/chef/cookbooks/application/files/halite_gem/poise_application/resources/application_cookbook_file.rb:39:in `<
module:ApplicationCookbookFile>'
  /var/cache/chef/cookbooks/application/files/halite_gem/poise_application/resources/application_cookbook_file.rb:24:in `<
module:Resources>'
  /var/cache/chef/cookbooks/application/files/halite_gem/poise_application/resources/application_cookbook_file.rb:21:in `<
module:PoiseApplication>'
  /var/cache/chef/cookbooks/application/files/halite_gem/poise_application/resources/application_cookbook_file.rb:20:in `<
top (required)>'
  /var/cache/chef/cookbooks/application/files/halite_gem/poise_application/resources.rb:18:in `<top (required)>'
  /var/cache/chef/cookbooks/application/files/halite_gem/poise_application/cheftie.rb:17:in `<top (required)>'
  /var/cache/chef/cookbooks/application/libraries/default.rb:19:in `<top (required)>'

Relevant File Content:
----------------------
/var/cache/chef/cookbooks/poise/files/halite_gem/poise/helpers/resource_subclass.rb:

 31:            resource_name ||= self.resource_name
 32:            superclass_resource_name ||= if superclass.respond_to?(:resource_name)
 33:              superclass.resource_name
 34:            elsif superclass.respond_to?(:dsl_name)
 35:              superclass.dsl_name
 36:            else
 37:              raise Poise::Error.new("Unable to determine superclass resource name for #{superclass}. Please specify n
ame manually via subclass_providers!('name').")
 38>>           end.to_sym
 39:            # Deal with the node maps.
 40:            node_maps = {}
 41:            node_maps['handler map'] = Chef.provider_handler_map if defined?(Chef.provider_handler_map)
 42:            node_maps['priority map'] = Chef.provider_priority_map if defined?(Chef.provider_priority_map)
 43:            # Patch anything in the descendants tracker.
 44:            Chef::Provider.descendants.each do |provider|
 45:              node_maps["#{provider} node map"] = provider.node_map if defined?(provider.node_map)
 46:            end if defined?(Chef::Provider.descendants)
 47:            node_maps.each do |map_name, node_map|


[2017-01-10T12:16:20-08:00] ERROR: Running exception handlers
[2017-01-10T12:16:20-08:00] ERROR: Exception handlers complete
[2017-01-10T12:16:20-08:00] FATAL: Stacktrace dumped to /var/cache/chef/chef-stacktrace.out
[2017-01-10T12:16:20-08:00] INFO: Sending resource update report (run-id: c1467eec-7c4c-4d44-a09c-2685816bb1b0)
[2017-01-10T12:16:21-08:00] ERROR: undefined method `to_sym' for nil:NilClass
Did you mean?  to_s
[2017-01-10T12:16:21-08:00] FATAL: Chef::Exceptions::ChildConvergeError: Chef run process exited unsuccessfully (exit code 1)

Deploying app from a subdirectory?

Hello,
Our app is not at the "root" of the code repository, is there a way to handle that with this cookbook?
Currently our application is deployed with

application 'app' do

  path _path
  owner _owner
  group _group
  deploy_key _pkey
  rollback_on_error true

  # repository "[email protected]:code/full.git"
  # revision "master"

  symlinks 'log' => 'log', 'node_modules' => 'node_modules'

  # packages %w( git )
  action :deploy
end

But the code we'd like to deploy is not at the root of github.com:code/full but rather inside a subdirectory called app.

Is there a way to tell this cookbook to only take the content of the subdirectory and put it in path ?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.