Code Monkey home page Code Monkey logo

application_ruby'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_ruby's People

Contributors

adamstegman avatar bryanstearns avatar btm avatar cap10morgan avatar coderanger avatar dwradcliffe avatar flaccid avatar iafonov avatar jeanmertz avatar josephholsten avatar jschneiderhan avatar jtimberman avatar kevinreedy avatar lamont-granquist avatar logikal avatar mauriciosilva avatar rabidtester avatar redbeard avatar rgeyer avatar sethvargo avatar stephenlauck avatar threetee avatar wallace 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

application_ruby's Issues

Pass deploy_key to bundle_install resource?

Issue related to this pull request.

I'm trying to deploy a Rails application with this cookbook, but it fails because our Gemfile includes some private repos.

It would be nice to automatically share application_git's deploy_key attribute to bundle_installโ€”I'd submit a pull request, but I have no idea how to do that.

application_unicorn resource's upstart template not generating a .conf file for service

During the convergence of our application block, Chef never winds up triggering the application_unicorn's Upstart LWRP provider's Upstart#create_service method that creates the Upstart conf file that governs the app.

Because this conf file never gets generated, Upstart does not recognize the service "my_app_web" and when Chef attempts to restart the service we get the exception output:

   ================================================================================
   Error executing action `restart` on resource 'application[my_app_web]'
   ================================================================================

   Mixlib::ShellOut::ShellCommandFailed
   ------------------------------------
   application_unicorn[my_app_web] (my_app-chef::app_server line 161) had an error: Mixlib::ShellOut::ShellCommandFailed: poise_service[my_app_web] (/var/chef/cache/cookbooks/my_app-chef/recipes/app_server.rb line 161) had an error: Mixlib::ShellOut::ShellCommandFailed: service[my_app_web_app] (/var/chef/cache/cookbooks/my_app-chef/recipes/app_server.rb line 161) had an error: Mixlib::ShellOut::ShellCommandFailed: Expected process to exit with [0], but received '1'
   ---- Begin output of /sbin/start my_app_web_app ----
   STDOUT:
   STDERR: start: Unknown job: my_app_web_app
   ---- End output of /sbin/start my_app_web_app ----
   Ran /sbin/start my_app_web_app returned 1

   Cookbook Trace:
   ---------------
   /var/chef/cache/cookbooks/poise-service/files/halite_gem/poise_service/service_providers/base.rb:75:in `block in action_start'
   /var/chef/cache/cookbooks/poise-service/files/halite_gem/poise_service/service_providers/base.rb:135:in `notify_if_service'
   /var/chef/cache/cookbooks/poise-service/files/halite_gem/poise_service/service_providers/base.rb:74:in `action_start'
   /var/chef/cache/cookbooks/poise-service/files/halite_gem/poise_service/service_providers/upstart.rb:45:in `action_restart'
   /var/chef/cache/cookbooks/poise-service/files/halite_gem/poise_service/service_mixin.rb:125:in `block in action_restart'
   /var/chef/cache/cookbooks/poise-service/files/halite_gem/poise_service/service_mixin.rb:154:in `notify_if_service'
   /var/chef/cache/cookbooks/poise-service/files/halite_gem/poise_service/service_mixin.rb:124:in `action_restart'
   /var/chef/cache/cookbooks/application/files/halite_gem/poise_application/resources/application.rb:249:in `block in proxy_action'
   /var/chef/cache/cookbooks/application/files/halite_gem/poise_application/resources/application.rb:247:in `proxy_action'
   /var/chef/cache/cookbooks/application/files/halite_gem/poise_application/resources/application.rb:229:in `action_restart'

Here is our cookbook's full application block:

application 'my_app_web' do
  path "#{node['my_app']['app_deploy_root']}/latest"
  git '[email protected]:myapp.git' do
    deploy_key deploy_key['rsa']
    revision node['my_app']['revision']
  end
  ruby_runtime 'my_app_ruby' do
    version '2.2'
    provider :ruby_build
  end

  bundle_install do
    path "#{node['my_app']['app_deploy_root']}/latest" # Have to respecify path?  Ghetto as fuck, thanks Poise cookbooks
    vendor true
  end

  rails do
    rails_env node['my_app']['environment_name']
    path "#{node['my_app']['app_deploy_root']}/latest"
    database({
                 adapter: 'postgresql',
                 database: node['my_app']['postgres']['database'],
                 timeout: 5000,
                 username: postgres_credentials['application_username'],
                 password: postgres_credentials['application_password'],
                 host: node['my_app']['master_db_ip'].nil? ? 'localhost' : node['my_app']['master_db_ip'],
                 pool: 100,
                 redis_url: "redis://#{node['my_app']['master_db_ip']}:6379"
             })
    precompile_assets true
    migrate true
  end

  unicorn do
    path "#{node['my_app']['app_deploy_root']}/latest"
    port '8080'
    service_name 'my_app_web_app'
    action :enable
  end
end

/tmp directory not accessible for Rails

directory "#{r.application.path}/current/tmp" do
recursive true
end

results in a directory /tmp owned by root which then is not accessible by Rails and results in a server error. The owner/group should be the same as set in the application block.

Version bump?

Can you please version bump this in the supermarket?

Thanks!

database.yml template does not support the socket option

The mysql2 adapter connects to the UNIX socket specified if both the host and port is not specified, useful when mysql isn't connected to any TCP sockets, and is only listening on the UNIX socket.

So, I imagine that passing the path to the socket as so:

application "my_rails_mysql_app" do
  # ...
  database do
    socket '/var/run/mysqld.sock'
    user 'my_rails_app'
    password 'god_mode'
  end
  # ...
end

would work.

Runit template for Unicorn sub resource should be an attribute

The run script in the unicorn subresource is broken if you try to do anything, which causes unicorn not to start, which causes the nginx restart to throw an exception. As far as I can tell chef-rewind cannot fix this, so if this were an attribute it would be useable.

ERROR: IOError: Cannot open or read /home/chef-repo/cookbooks/iptables/metadata.rb!

When running:

knife cookbook site install application_ruby

I get:

Pristine copy branch (chef-vendor-iptables) exists, switching to it.
Downloading iptables from the cookbooks site at version 0.14.1 to /home/confucius/chef-repo/cookbooks/iptables.tar.gz
Cookbook saved: /home/confucius/chef-repo/cookbooks/iptables.tar.gz
Removing pre-existing version.
Uncompressing iptables version 0.14.1.
removing downloaded tarball
No changes made to iptables
Checking out the master branch.
ERROR: IOError: Cannot open or read /home/chef-repo/cookbooks/iptables/metadata.rb!

there is a metadata.json file but no metadata.rb file. When I try and add the metadata.rb from github and re-run install the iptable folder is overwritten and the metadata.rb file is deleted.

precompile_assets: specify node runtime?

rake assets:precompile needs a javascript runtime. I'm installing one via the javascript resource from poise-javascript, but ExecJS isn't finding it, as it's not in the PATH.

How do I fix this? Should I manually set the path to include node's bin dir? And if so, should I hardcode said path, or is there a way to extract it from the javascript resource?

Rails ENV Variables?

Hi guys.

Loving this cookbook! Really handy - but up I'm running into some issues setting up environment variables for my app. Here's my app block:

include_recipe "runit"
application 'myapp' do
  owner 'deploy'
  group 'deploy'
  path '/var/www/myapp'
  repository '[email protected]:hhff/myapp.git'
  rails do
    bundler true
    # These will eventually be passed in via a data bag
    environment "SECRET_KEY_BASE" => "secretkeybase", "SECRET_TOKEN" => "secrettoken"
    database do
      adapter "sqlite3"
      database "db/production.sqlite3"
    end
  end
  unicorn do
    worker_processes 2
  end
end

Here's my Rails secrets.yml

production:
  secret_key_base: <%= ENV["SECRET_KEY_BASE"] %>
  secret_token: <%= ENV["SECRET_TOKEN"] %>

However, after a cook, when I tail my logs I'm still seeing:

2015-01-23_16:09:23.61596 E, [2015-01-23T08:09:23.615720 #2586] ERROR -- : app error: Missing `secret_token` and `secret_key_base` for 'production' environment, set these values in `config/secrets.yml` (RuntimeError)

Any tips? I'm happy to update the docs once I get this figured out...

Add support for -e switch to application_puma

The application_puma resource should support specifying an -e switch parameter since puma doesn't respect the RAILS_ENV environment variable - it only listens to RACK_ENV and the -e switch.

option to retry bundle install

I'm repeatedly encountering an issue where rubygems throws a 503 on one of my gems during the bundle install run. How would it be possible to retry that operation ?

Thanks !

Specify branch, tag, or revision for git clone

I want to use the application resource in such a way that I can specify the tag to clone using Git.
Like so:

application '/srv/my-app' do
  git 'https://github.com/daharon/my-app.git' do
    revision 'v1.0.0'  # A git tag.
  end

  bundle_install
  rails
  unicorn
end

The above fails, though.

How can I specify the tag or commit hash of the Git repository that I wish to clone?

Chef 14 Support

I am preparing for migrating to Chef 14 and am running into issues running this cookbook with that Chef client version. In particular, I am getting this traceback when the recipe compiles:

 NameError
         ---------
         instance variable @cwd not defined

         Cookbook Trace:
         ---------------
           /tmp/kitchen/cache/cookbooks/application_ruby/files/halite_gem/poise_application_ruby/resources/ruby_execute.rb:43:in `remove_instance_variable'
           /tmp/kitchen/cache/cookbooks/application_ruby/files/halite_gem/poise_application_ruby/resources/ruby_execute.rb:43:in `initialize'
           /tmp/kitchen/cache/cookbooks/poise/files/halite_gem/poise/helpers/subresources/container.rb:140:in `block in declare_resource'
           /tmp/kitchen/cache/cookbooks/poise/files/halite_gem/poise/helpers/subresources/container.rb:121:in `declare_resource'
           /tmp/kitchen/cache/cookbooks/application/files/halite_gem/poise_application/resources/application.rb:175:in `public_send'
           /tmp/kitchen/cache/cookbooks/application/files/halite_gem/poise_application/resources/application.rb:175:in `block (2 levels) in _rewire_dsl!'
           /tmp/kitchen/cache/cookbooks/my-redmine/recipes/default.rb:95:in `block in from_file'
           /tmp/kitchen/cache/cookbooks/my-redmine/recipes/default.rb:57:in `from_file'

         Relevant File Content:
         ----------------------
         /tmp/kitchen/cache/cookbooks/application_ruby/files/halite_gem/poise_application_ruby/resources/ruby_execute.rb:

          36:        class Resource < PoiseRuby::Resources::RubyExecute::Resource
          37:          include PoiseApplicationRuby::AppMixin
          38:          provides(:application_ruby_execute)
          39:
          40:          def initialize(*args)
          41:            super
          42:            # Clear some instance variables so my defaults work.
          43>>           remove_instance_variable(:@cwd)
          44:            remove_instance_variable(:@group)
          45:            remove_instance_variable(:@user)
          46:          end
          47:
          48:          # #!attribute cwd
          49:          #   Override the default directory to be the app path if unspecified.
          50:          #   @return [String]
          51:          attribute(:cwd, kind_of: [String, NilClass, FalseClass], default: lazy { parent && parent.path })
          52:

         System Info:
         ------------
         chef_version=14.6.47
         platform=centos
         platform_version=7.5.1804
         ruby=ruby 2.5.3p105 (2018-10-18 revision 65156) [x86_64-linux]
         program_name=/opt/chef/bin/chef-client
         executable=/opt/chef/bin/chef-client

Is Chef 14 support in the works already for the poise application family of cookbooks?

ruby_execute does not accept notifications within an application resource definition

I encountered an issue in which ruby_execute resources could not be called from within an application definition. The error is:

       Compiling Cookbooks...
       Converging 28 resources

       Running handlers:
       [2016-01-16T03:11:19+00:00] ERROR: Running exception handlers
       Running handlers complete
       [2016-01-16T03:11:19+00:00] ERROR: Exception handlers complete
       Chef Client failed. 0 resources updated in 02 seconds
       [2016-01-16T03:11:19+00:00] FATAL: Stacktrace dumped to /tmp/kitchen/cache/chef-stacktrace.out
       [2016-01-16T03:11:19+00:00] FATAL: Please provide the contents of the stacktrace.out file if you file a bug report
       [2016-01-16T03:11:19+00:00] ERROR: resource git[railstutorial] is configured to notify resource ruby_execute[notify-me] with action run, but ruby_execute[notify-me] cannot be found in the resource collection. git[railstutorial] is defined in /tmp/kitchen/cache/cookbooks/poise-ruby-example/recipes/default.rb:21:in `block in from_file'

       [2016-01-16T03:11:21+00:00] FATAL: Chef::Exceptions::ChildConvergeError: Chef run process exited unsuccessfully (exit code 1)

To DRY out reproducing this issue, I created the following cookbook: https://github.com/rhass/poise-ruby-example

It should be noted that taking the ruby_execute block out of the application resource causes it to be unaware of the ruby resource for the parent_ruby and parent_bundler properties.

CC @blt04 (Also affected by this bug.)

Rake conflict upgrading from application_ruby cookbook from 3.x to 4.x

We've been trying to move our deployment cookbooks over to the application_ruby 4.x and application 5.x releases, but it seems having the application_ruby cookbook manage our Ruby version has caused the new way of calling the Rake gem to get a bit confused.

We previously managed our own Ruby versions using the rbenv cookbook. Now when we run the deployment chef-client fails because it cannot find the Rake script/executable (binstub?). Manually installing the Rake Gem with:

  ruby_gem 'rake' do
    options '--force'
  end

did not help either.

Here is the output in both cases:

application_rails[myapp] action deploy
    * file[/path/to/myapp/config/database.yml] action create (up to date)
    * ruby_execute[rake assets:precompile] action run
      
      ================================================================================
      Error executing action `run` on resource 'ruby_execute[rake assets:precompile]'
      ================================================================================
      
      Mixlib::ShellOut::ShellCommandFailed
      ------------------------------------
      Expected process to exit with [0], but received '1'
      ---- Begin output of ["/usr/local/rbenv/shims/ruby", "rake", "assets:precompile"] ----
      STDOUT: 
      STDERR: ruby: No such file or directory -- rake (LoadError)
      ---- End output of ["/usr/local/rbenv/shims/ruby", "rake", "assets:precompile"] ----
      Ran ["/usr/local/rbenv/shims/ruby", "rake", "assets:precompile"] returned 1
      
      Cookbook Trace:
      ---------------
      /var/chef/cache/cookbooks/poise/files/halite_gem/poise/helpers/notifying_block.rb:69:in `notifying_block'
      /var/chef/cache/cookbooks/application_ruby/files/halite_gem/poise_application_ruby/resources/rails.rb:175:in `action_deploy'
      
      Resource Declaration:
      ---------------------
      # In /var/chef/cache/cookbooks/application_ruby/files/halite_gem/poise_application_ruby/resources/rails.rb
      
      231:           ruby_execute 'rake assets:precompile' do
      232:             command %w{rake assets:precompile}
      233:             user new_resource.parent.owner
      234:             group new_resource.parent.group
      235:             cwd new_resource.parent.path
      236:             environment new_resource.app_state_environment
      237:             ruby_from_parent new_resource
      238:             parent_bundle new_resource.parent_bundle if new_resource.parent_bundle
      239:           end
      240:         end

[CHEF-5027] Doesn't work under chef 11.10

The rails resource works find under chef 11.8, but updating it to chef 11.10 broke the cookbook. The following error occurs when I use chef 11.10.0 in vagrant ubuntu 13.10 :

Chef::Exceptions::CookbookNotFound
----------------------------------
Cookbook none not found. If you're loading none from another cookbook, make sure you configure the dependency in your metadata


Resource Declaration:
---------------------
# In /tmp/vagrant-chef-1/chef-solo-1/cookbooks/application_ruby/providers/rails.rb

181:   template "#{new_resource.path}/shared/database.yml" do
182:     source new_resource.database_template || "database.yml.erb"
183:     cookbook new_resource.database_template ? new_resource.cookbook_name.to_s : "application_ruby"
184:     owner new_resource.owner
185:     group new_resource.group
186:     mode "644"
187:     variables(
188:       :host => host,
189:       :database => new_resource.database,
190:       :rails_env => new_resource.environment_name
191:     )
192:   end
193: end



Compiled Resource:
------------------
# Declared in /tmp/vagrant-chef-1/chef-solo-1/cookbooks/application_ruby/providers/rails.rb:181:in `create_database_yml'

template("/srv/DelphiusApp/shared/database.yml") do
  provider Chef::Provider::Template
  action "create"
  retries 0
  retry_delay 2
  path "/srv/DelphiusApp/shared/database.yml"
  backup 5
  atomic_update true
  source "db.yml.erb"
  cookbook "none"
  variables {:host=>"mysql.staging.com", :database=>{"host"=>"mysql.staging.com", "database"=>"staging", "username"=>"dool2761j", "password"=>"cx792dh23739dj324nuosasdasdjkhawd2139", "adapter"=>"mysql2", "encoding"=>"utf8", "pool"=>5, "reconnect"=>"false", "read_timeout"=>60, "write_timeout"=>90, "connect_timeout"=>60}, :rails_env=>"staging"}
  cookbook_name "none"
  recipe_name "none"
  mode "644"
  owner "delphius-app"
  group "delphius-app"
end

The issue stems from the fact that the cookbook field is set to 'none', but Iโ€™m not sure where it's getting that value from.

Cannot find ruby runtime (with ruby build)

Hello! I apoligise if this should be within poise-ruby repository. I am using application_ruby and believe the issue I am experiencing involves this repo. I am sort of at a lose as to what I am doing wrong ๐Ÿ˜…

I would like to install and use Ruby 2.2.8. I am using ruby_build to achieve this, but bundle_install for some reason cannot find my ruby runtime.

Related cookbook versions

cookbook 'poise-ruby', '~> 2.4.0'
cookbook 'poise-ruby-build', '~> 1.1.0'
cookbook 'application', '~> 5.2.0'
cookbook 'application_git', '~> 1.2.0'
cookbook 'application_ruby', '~> 4.1.0'

Code and error pasted below.

app          = search("aws_opsworks_app", "shortname:passion_app").first
env_vars     = app[:environment]
app_path     = "#{node[:passion][:deploy_path]}/#{app[:shortname]}/repo"
shared_path  = "#{node[:passion][:deploy_path]}/#{app[:shortname]}/shared"
ruby_version = node[:passion][:ruby_version]
deploy_user  = node[:passion][:deploy_user]
deploy_group = node[:passion][:deploy_group]
app_name  = app[:shortname]

application app_path do
  ruby_runtime app_name do
    provider :ruby_build
    version '2.2.8'
  end

  git do
    repository app[:app_source][:url]
    destination app_path
    revision   app[:app_source][:revision]
    deploy_key app[:app_source][:ssh_key] if app[:app_source][:ssh_key]
    user deploy_user
  end

  bundle_install do
    deployment true
    ruby app_name
    without %w{development test}
  end
end
       Synchronizing Cookbooks:
         - deploy (0.1.0)
         - poise-ruby-build (1.1.0)
         - poise (2.8.1)
         - poise-languages (2.1.2)
         - poise-git (1.0.0)
         - application (5.2.0)
         - application_git (1.2.0)
         - application_ruby (4.1.0)
         - passion (0.1.0)
         - poise-ruby (2.4.0)
         - poise-archive (1.5.0)
         - poise-build-essential (1.0.0)
         - poise-service (1.5.2)
       Installing Cookbook Gems:
       Compiling Cookbooks...

       ================================================================================
       Recipe Compile Error in /tmp/kitchen/cache/cookbooks/passion/recipes/deploy.rb
       ================================================================================

       Chef::Exceptions::ResourceNotFound
       ----------------------------------
       Cannot find a resource matching ruby_runtime[passion_app] (did you define it first?)

       Cookbook Trace:
       ---------------
         /tmp/kitchen/cache/cookbooks/poise-languages/files/halite_gem/poise_languages/command/mixin.rb:61:in `language_command_runtime'
         /tmp/kitchen/cache/cookbooks/poise-languages/files/halite_gem/poise_languages/command/mixin.rb:136:in `block in language_command_mixin'
         /tmp/kitchen/cache/cookbooks/passion/recipes/deploy.rb:26:in `block (2 levels) in from_file'
         /tmp/kitchen/cache/cookbooks/application/files/halite_gem/poise_application/resources/application.rb:182:in `instance_exec'
         /tmp/kitchen/cache/cookbooks/application/files/halite_gem/poise_application/resources/application.rb:182:in `block (3 levels) in _rewire_dsl!'
         /tmp/kitchen/cache/cookbooks/poise/files/halite_gem/poise/helpers/subresources/container.rb:150:in `instance_exec'
         /tmp/kitchen/cache/cookbooks/poise/files/halite_gem/poise/helpers/subresources/container.rb:150:in `block (2 levels) in declare_resource'
         /tmp/kitchen/cache/cookbooks/poise/files/halite_gem/poise/helpers/subresources/container.rb:140:in `block in declare_resource'
         /tmp/kitchen/cache/cookbooks/poise/files/halite_gem/poise/helpers/subresources/container.rb:121:in `declare_resource'
         /tmp/kitchen/cache/cookbooks/application/files/halite_gem/poise_application/resources/application.rb:175:in `public_send'
         /tmp/kitchen/cache/cookbooks/application/files/halite_gem/poise_application/resources/application.rb:175:in `block (2 levels) in _rewire_dsl!'
         /tmp/kitchen/cache/cookbooks/passion/recipes/deploy.rb:24:in `block in from_file'
         /tmp/kitchen/cache/cookbooks/passion/recipes/deploy.rb:10:in `from_file'

       Relevant File Content:
       ----------------------
       /tmp/kitchen/cache/cookbooks/poise-languages/files/halite_gem/poise_languages/command/mixin.rb:

        54:          def language_command_runtime(name, runtime, default_binary, val=Poise::NOT_PASSED)
        55:            unless val == Poise::NOT_PASSED
        56:              path_arg = parent_arg = nil
        57:              # Figure out which property we are setting.
        58:              if val.is_a?(String)
        59:                # Check if it is a runtime resource.
        60:                begin
        61>>                 parent_arg = run_context.resource_collection.find("#{runtime}[#{val}]")
        62:                rescue Chef::Exceptions::ResourceNotFound
        63:                  # Check if something looks like a path, defined as containing
        64:                  # either / or \. While a single word could be a path, I think the
        65:                  # UX win of better error messages should take priority.
        66:                  might_be_path = val =~ %r{/|\\}
        67:                  if might_be_path
        68:                    Chef::Log.debug("[#{self}] #{runtime}[#{val}] not found, treating it as a path")
        69:                    path_arg = val
        70:                  else

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


       Running handlers:
       [2018-07-06T13:13:40+00:00] ERROR: Running exception handlers
       Running handlers complete
       [2018-07-06T13:13:40+00:00] ERROR: Exception handlers complete
       Chef Client failed. 0 resources updated in 01 seconds
       [2018-07-06T13:13:40+00:00] FATAL: Stacktrace dumped to /tmp/kitchen/cache/chef-stacktrace.out
       [2018-07-06T13:13:40+00:00] FATAL: Please provide the contents of the stacktrace.out file if you file a bug report
       [2018-07-06T13:13:40+00:00] FATAL: Chef::Exceptions::ResourceNotFound: Cannot find a resource matching ruby_runtime[passion_app] (did you define it first?)

Add a metadata.rb file

When trying to use a fork or a branch of this repo - berkshelf throws an error about The resource at '/var/folders/wp/5vk87yqj74s6db15lbjn16qr0000gn/T/d20160515-60205-qblbms' does not appear to be a valid cookbook. Does it have a metadata.rb?"

I also tried adding extension 'halite' to the top of the Berksfile file and using the dependency as a gem, but I'm getting the following: /opt/chefdk/embedded/lib/ruby/gems/2.1.0/gems/berkshelf-4.0.1/lib/berkshelf/berksfile.rb:89:inrescue in extension': Could not load an extension by the name halite'. Please make sure it is installed. (LoadError)

Creating database.yml should be optional

My database.yml looks something like this, according to http://12factor.net

default: &default
  adapter:  <%= ENV['RAILS_DB_ADAPTER'] %>
  encoding: <%= ENV['RAILS_DB_ENCODING'] %>
  database: <%= ENV['RAILS_DB_DATABASE'] %>
  host:     <%= ENV['RAILS_DB_HOST'] %>
  password: <%= ENV['RAILS_DB_PASSWORD'] %>
  pool:     <%= ENV['RAILS_DB_POOL'] %>
  username: <%= ENV['RAILS_DB_USERNAME'] %>

So it would be cool if I could instruct the application_ruby cookbook to not overwrite it. I'm injecting the necessary variables via the environment.

If you think this makes sense, I'll prepare a pull request for that.

Thanks,
plu

database subresoruce not working when using option_collector

I have deployed an application_ruby resource using the folloging sintax and it's not writting database name in config/database.yml

application '/opt/applications/xxx' do
  rails do
    database do
      adapter: 'mysql2'
      username: 'user'
      host: '127.0.0.1'
      database: 'name'
      password: '
    end
  end 
end

So changing the above configuration with the following now is working:

application '/opt/applications/xxx' do
  rails do
    database(
      adapter: 'mysql2',
      username: 'user',
      host: '127.0.0.1',
      database: 'name',
      password: 'password',
    )    
  end 
end

Basically, the first case generates a database.yml without database name. The second one is working

why does memcached node search exclude current node?

The memcached provider searches for nodes in the current chef environment with the provided role to configure into memcached.yml. However it specifically excludes the current node unless no nodes are returned in which case it will add the current node if it has the role.

What is the thinking there?

If we want to add memcached to every app node for example, then an app with multiple nodes will generate cache misses since every memcached.yml will have a different list of servers and the cache hash algorithm will store any given value into a different server.

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.