From 5fc42c3f627a4e0ff3d4af6b64680a5a22bd5c87 Mon Sep 17 00:00:00 2001 From: Igor Rzegocki Date: Wed, 26 Oct 2016 18:31:12 +0200 Subject: [PATCH] fix: `node['applications']` are back Unfortunatelly during the setup phase, OpsWorks deploys all applications in given stack - there is no way to assign some applications to some layers only. This parameter resolves this issue (and thus - should be kept) by filtering supported applications in given layer, to only listed in it. Notice, that with this option enabled, it won't be possible to deploy to a given layer an application which is not listed in it. Resolves #55 --- docs/source/attributes.rst | 58 +++++++++++++++++++++++--------- docs/source/troubleshooting.rst | 7 ++++ libraries/helpers.rb | 8 +++++ spec/unit/recipes/deploy_spec.rb | 10 +++--- 4 files changed, 63 insertions(+), 20 deletions(-) diff --git a/docs/source/attributes.rst b/docs/source/attributes.rst index 2c61fa0f..de4601b1 100644 --- a/docs/source/attributes.rst +++ b/docs/source/attributes.rst @@ -14,8 +14,31 @@ Attributes | so for example ``app['framework']['adapter']`` actually means | ``node['deploy'][]['framework']['adapter']``. +Stack attributes +---------------- + +These attributes are used on Stack/Layer level globally to configure +the opsworks_ruby cookbook itself. They should'nt be used under +``node['deploy'][]`` (notice lack of the ``app[]`` +convention). + +- ``node['applications']`` + + - An array of application shortnames which should be deployed to given layer. + If set, only applications witch ``deploy`` flag set (on OpsWorks side) included + in this list will be deployed. If not set, all ``deploy`` application will be + supported. This parameter mostly matters during the setup phase, since all + application in given stack are deployed to the given layer. Using this paramter + you can narrow the list to application which you actually intend to use. + **Important** thing is, that when you try to do a manual deploy from OpsWorks + of an application, not included in this list - it will be skipped, as this list + takes precedence over anything else. + +Application attributes +---------------------- + global ------- +~~~~~~ | Global parameters apply to the whole application, and can be used by any section @@ -29,7 +52,7 @@ global in Rails) actions in the project (server, worker, etc.) database --------- +~~~~~~~~ | Those parameters will be passed without any alteration to the ``database.yml`` @@ -67,7 +90,7 @@ database the ``database.yml`` scm ---- +~~~ | Those parameters can also be determined from OpsWorks application, and usually @@ -113,7 +136,7 @@ scm also be fetched. framework ---------- +~~~~~~~~~ | Pre-optimalization for specific frameworks (like migrations, cache etc.). | Currently ``hanami.rb`` and ``Rails`` are supported. @@ -146,7 +169,7 @@ framework - A command which will be invoked to precompile assets. padrino -~~~~~~~ +^^^^^^^ | For Padrino, slight adjustments needs to be made. Since there are many database | adapters supported, instead of creating configuration for each one, the @@ -163,7 +186,7 @@ padrino } rails -~~~~~ +^^^^^ - ``app['framework']['envs_in_console']`` @@ -176,7 +199,7 @@ rails it as a first step in your debugging process. appserver ---------- +~~~~~~~~~ | Configuration parameters for the ruby application server. Currently ``Puma``, | ``Thin`` and ``Unicorn`` are supported. @@ -220,7 +243,7 @@ appserver serve exactly one client at a time. unicorn -~~~~~~~ +^^^^^^^ - |app['appserver']['backlog']|_ @@ -245,7 +268,7 @@ unicorn - **Default:** ``5`` puma -~~~~ +^^^^ - |app['appserver']['log_requests']|_ @@ -261,7 +284,7 @@ puma - **Default:** ``0`` thin -~~~~ +^^^^ - ``app['appserver']['max_connections']`` @@ -280,7 +303,7 @@ thin - **Default:** ``4`` webserver ---------- +~~~~~~~~~ | Webserver configuration. Proxy passing to application is handled out-of-the-box. | Currently Apache2 and nginx is supported. @@ -315,7 +338,7 @@ webserver application needs a support for those browsers, set this parameter to ``true``. apache -~~~~~~ +^^^^^^ - ``app['webserver']['extra_config']`` @@ -346,7 +369,7 @@ apache - **Default**: ``60`` nginx -~~~~~ +^^^^^ - ``app['webserver']['build_type']`` @@ -402,8 +425,11 @@ nginx | as well (notice that ``node['deploy'][]`` logic | doesn't apply here.) +worker +~~~~~~ + sidekiq -~~~~~~~ +^^^^^^^ - ``app['worker']['config']`` @@ -412,14 +438,14 @@ sidekiq `sidekiq.yml config file`_. delayed\_job -~~~~~~~~~~~~ +^^^^^^^^^^^^ - ``app['worker']['queues']`` - Array of queues which should be processed by delayed\_job resque -~~~~~~ +^^^^^^ - ``app['worker']['workers']`` diff --git a/docs/source/troubleshooting.rst b/docs/source/troubleshooting.rst index 435104d2..d510bd9b 100644 --- a/docs/source/troubleshooting.rst +++ b/docs/source/troubleshooting.rst @@ -15,5 +15,12 @@ By default webserver is configured to follow strict SSL security standards, `cov old browsers (like IE < 9 or Android < 2.2) wouldn't work with this configuration very well. If your application needs a support for those browsers, set ``app['webserver']['ssl_for_legacy_browsers']`` to true. +Some applications on my Layer deploys, some of them not +------------------------------------------------------- + +Check the ``node['applications']`` parameter in :ref:`Attributes` section. +If set, it narrows down the list of applications allowed to deploy, to its value. +If not sure what to do - try to remove from your Stack/Layer config and see if this helps. + .. _covered in this article: https://cipherli.st/ diff --git a/libraries/helpers.rb b/libraries/helpers.rb index e610ef51..9454c82a 100644 --- a/libraries/helpers.rb +++ b/libraries/helpers.rb @@ -80,4 +80,12 @@ def perform_bundle_install(shared_path, envs = {}) def prepare_recipe node.default['deploy'] = Hash[applications.map { |app| [app['shortname'], {}] }].merge(node['deploy'] || {}) + apps_not_included.each do |app_for_removal| + node.rm('deploy', app_for_removal) + end +end + +def apps_not_included + return [] if node['applications'].blank? + node['deploy'].keys.select { |app_name| !node['applications'].include?(app_name) } end diff --git a/spec/unit/recipes/deploy_spec.rb b/spec/unit/recipes/deploy_spec.rb index 08078625..8f5e7e8d 100644 --- a/spec/unit/recipes/deploy_spec.rb +++ b/spec/unit/recipes/deploy_spec.rb @@ -155,14 +155,16 @@ end.not_to raise_error end - it 'app[\'deploy\'] = false' do + it 'node[\'applications\']' do stub_search(:aws_opsworks_app, '*:*').and_return([ - aws_opsworks_app.merge(shortname: 'a1'), - aws_opsworks_app.merge(shortname: 'a2', deploy: false) + aws_opsworks_app.merge(shortname: 'a1', deploy: true), + aws_opsworks_app.merge(shortname: 'a2', deploy: false), + aws_opsworks_app.merge(shortname: 'a3', deploy: true) ]) chef_run = ChefSpec::SoloRunner.new(platform: 'ubuntu', version: '14.04') do |solo_node| solo_node.set['lsb'] = node['lsb'] - solo_node.set['deploy'] = { 'a1' => {}, 'a2' => {} } + solo_node.set['deploy'] = { 'a1' => {}, 'a2' => {}, 'a3' => {} } + solo_node.set['applications'] = %w(a1 a2) end.converge(described_recipe) service = chef_run.service('puma_a1')