From 2bc9c51cb5d98f20b7eeaf5079734487b9c2cf4f Mon Sep 17 00:00:00 2001 From: Igor Rzegocki Date: Mon, 24 Apr 2017 16:57:06 +0200 Subject: [PATCH] feat(logrotate) implement logrotate Currently, frameworks (rails) and webservers (apache2 and nginx) are supported. Resolves #78 --- .kitchen.yml | 1 + .ruby-version | 2 +- Berksfile | 1 + Dockerfile | 43 +++++++++++++ Gemfile | 5 +- Gemfile.lock | 61 ++++++++++--------- Rakefile | 3 +- attributes/default.rb | 9 +-- docker-compose.yml | 8 +++ libraries/all.rb | 1 + libraries/core_ext.rb | 1 + libraries/drivers_appserver_base.rb | 1 + libraries/drivers_appserver_factory.rb | 1 + libraries/drivers_appserver_null.rb | 1 + libraries/drivers_appserver_puma.rb | 3 +- libraries/drivers_appserver_thin.rb | 3 +- libraries/drivers_appserver_unicorn.rb | 5 +- libraries/drivers_base.rb | 1 + libraries/drivers_db_mysql.rb | 1 + libraries/drivers_db_postgresql.rb | 1 + libraries/drivers_db_sqlite.rb | 1 + libraries/drivers_dsl_defaults.rb | 1 + libraries/drivers_dsl_logrotate.rb | 48 +++++++++++++++ libraries/drivers_dsl_notifies.rb | 1 + libraries/drivers_dsl_output.rb | 1 + libraries/drivers_dsl_packages.rb | 1 + libraries/drivers_framework_base.rb | 6 ++ libraries/drivers_framework_factory.rb | 1 + libraries/drivers_framework_hanami.rb | 6 +- libraries/drivers_framework_null.rb | 1 + libraries/drivers_framework_padrino.rb | 5 +- libraries/drivers_framework_rails.rb | 15 ++++- libraries/drivers_scm_base.rb | 1 + libraries/drivers_scm_factory.rb | 1 + libraries/drivers_scm_git.rb | 3 +- libraries/drivers_webserver_apache2.rb | 17 ++++-- libraries/drivers_webserver_base.rb | 6 ++ libraries/drivers_webserver_factory.rb | 1 + libraries/drivers_webserver_nginx.rb | 15 +++-- libraries/drivers_webserver_null.rb | 1 + libraries/drivers_worker_base.rb | 1 + libraries/drivers_worker_delayed_job.rb | 3 +- libraries/drivers_worker_factory.rb | 1 + libraries/drivers_worker_null.rb | 1 + libraries/drivers_worker_resque.rb | 3 +- libraries/drivers_worker_sidekiq.rb | 3 +- libraries/helpers.rb | 2 +- metadata.rb | 5 +- recipes/configure.rb | 1 + recipes/default.rb | 1 + recipes/provision.rb | 1 + recipes/setup.rb | 8 ++- recipes/shutdown.rb | 1 + spec/fixtures/aws_opsworks_app.rb | 1 + spec/fixtures/aws_opsworks_rds_db_instance.rb | 1 + spec/fixtures/node.rb | 7 ++- spec/spec_helper.rb | 1 + .../examples/db_parameters_and_connection.rb | 1 + .../db_validate_adapter_and_engine.rb | 1 + spec/unit/libraries/core_ext_spec.rb | 1 + .../drivers_appserver_factory_spec.rb | 1 + .../libraries/drivers_appserver_null_spec.rb | 1 + .../libraries/drivers_appserver_puma_spec.rb | 1 + .../libraries/drivers_appserver_thin_spec.rb | 1 + .../drivers_appserver_unicorn_spec.rb | 1 + .../unit/libraries/drivers_db_factory_spec.rb | 1 + spec/unit/libraries/drivers_db_mysql_spec.rb | 1 + .../libraries/drivers_db_postgresql_spec.rb | 1 + .../drivers_framework_factory_spec.rb | 1 + .../drivers_framework_hanami_spec.rb | 1 + .../libraries/drivers_framework_null_spec.rb | 1 + .../drivers_framework_padrino_spec.rb | 1 + .../libraries/drivers_framework_rails_spec.rb | 1 + .../libraries/drivers_scm_factory_spec.rb | 1 + spec/unit/libraries/drivers_scm_git_spec.rb | 1 + .../drivers_webserver_apache2_spec.rb | 1 + .../drivers_webserver_factory_spec.rb | 1 + .../libraries/drivers_webserver_nginx_spec.rb | 1 + .../libraries/drivers_webserver_null_spec.rb | 1 + .../drivers_worker_delayed_job_spec.rb | 1 + .../libraries/drivers_worker_factory_spec.rb | 1 + .../libraries/drivers_worker_null_spec.rb | 1 + .../libraries/drivers_worker_resque_spec.rb | 1 + .../libraries/drivers_worker_sidekiq_spec.rb | 1 + spec/unit/recipes/configure_spec.rb | 44 ++++++++++--- spec/unit/recipes/deploy_spec.rb | 10 ++- spec/unit/recipes/setup_spec.rb | 1 + spec/unit/recipes/shutdown_spec.rb | 1 + spec/unit/recipes/undeploy_spec.rb | 1 + .../serverspec/all_options_spec.rb | 1 + .../default/serverspec/default_spec.rb | 28 +++++++++ .../helpers/serverspec/spec_helper.rb | 1 + .../nullified/serverspec/nullified_spec.rb | 1 + .../thin_nginx_padrino_delayed_job_spec.rb | 1 + .../unicorn_apache_hanami_resque_spec.rb | 16 +++++ 95 files changed, 380 insertions(+), 77 deletions(-) create mode 100644 Dockerfile create mode 100644 docker-compose.yml create mode 100644 libraries/drivers_dsl_logrotate.rb diff --git a/.kitchen.yml b/.kitchen.yml index 589d7c3c..7df5fe64 100644 --- a/.kitchen.yml +++ b/.kitchen.yml @@ -4,6 +4,7 @@ driver: provisioner: name: chef_zero + require_chef_omnibus: 12 # Uncomment the following verifier to leverage Inspec instead of Busser (the # default verifier) diff --git a/.ruby-version b/.ruby-version index 262714f1..55bc9834 100644 --- a/.ruby-version +++ b/.ruby-version @@ -1 +1 @@ -ruby-2.4.0 +ruby-2.4.1 diff --git a/Berksfile b/Berksfile index 30c95447..b3280c65 100644 --- a/Berksfile +++ b/Berksfile @@ -1,4 +1,5 @@ # frozen_string_literal: true + source 'https://supermarket.chef.io' solver :ruby, :required diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 00000000..2b7f8aab --- /dev/null +++ b/Dockerfile @@ -0,0 +1,43 @@ +FROM ruby:2.4.1 + +RUN printf "deb http://deb.debian.org/debian testing main\ndeb http://deb.debian.org/debian testing-updates main\ndeb http://security.debian.org testing/updates main" >> /etc/apt/sources.list +RUN apt-get update && \ + apt-get install --yes --no-install-recommends apt-transport-https=1.0.* && \ + apt-get clean && \ + rm -rf /var/lib/apt/lists/* +RUN echo 'deb https://deb.nodesource.com/node_6.x jessie main' > /etc/apt/sources.list.d/nodesource.list && \ + curl -s https://deb.nodesource.com/gpgkey/nodesource.gpg.key | apt-key add - && \ + apt-get update && \ + apt-get install --yes --target-release=stable --no-install-recommends python-pip python-yaml locales nodejs=6.* build-essential && \ + apt-get install --yes --target-release=testing --no-install-recommends git && \ + apt-get clean && \ + rm -rf /var/lib/apt/lists/* +RUN gem update --no-document --system +RUN npm install -g conventional-changelog-cli + +RUN echo 'en_US.UTF-8 UTF-8' >> /etc/locale.gen +RUN locale-gen +ENV LC_ALL en_US.UTF-8 + +ENV APP_HOME /app +RUN mkdir "$APP_HOME" + +RUN curl -o /tmp/chefdk.deb https://packages.chef.io/files/stable/chefdk/1.3.43/debian/8/chefdk_1.3.43-1_amd64.deb && \ + dpkg -i /tmp/chefdk.deb && \ + rm -rf /tmp/chefdk.deb + +RUN gem install bundler +RUN pip install yamllint>=1 + +WORKDIR $APP_HOME +COPY package.json $APP_HOME/ +RUN npm install + +COPY Gemfile* $APP_HOME/ +RUN bundle install -j 4 +RUN chef exec bundle install -j 4 + +COPY Berksfile* $APP_HOME/ +COPY metadata.rb $APP_HOME/ +COPY README.md $APP_HOME/ +RUN chef exec berks diff --git a/Gemfile b/Gemfile index 7e3fc7f8..86493a3d 100644 --- a/Gemfile +++ b/Gemfile @@ -1,4 +1,5 @@ # frozen_string_literal: true + source 'https://rubygems.org/' group :lint do @@ -15,7 +16,9 @@ end group :chef do gem 'berkshelf' - gem 'chefspec' + gem 'chef', '~> 12.0' + gem 'chef-zero', '~> 5.3' + gem 'chefspec', '~> 6.0' gem 'kitchen-docker' gem 'kitchen-vagrant' gem 'rspec' diff --git a/Gemfile.lock b/Gemfile.lock index 5f8e8691..7cdb7505 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -2,10 +2,10 @@ GEM remote: https://rubygems.org/ specs: addressable (2.4.0) - artifactory (2.7.0) + artifactory (2.8.1) ast (2.3.0) - backports (3.6.8) - berkshelf (5.6.3) + backports (3.7.0) + berkshelf (5.6.4) addressable (~> 2.3, >= 2.3.4) berkshelf-api-client (>= 2.0.2, < 4.0) buff-config (~> 2.0) @@ -25,7 +25,7 @@ GEM faraday (~> 0.9) httpclient (~> 2.7) ridley (>= 4.5, < 6.0) - brakeman (3.5.0) + brakeman (3.6.1) buff-config (2.0.0) buff-extensions (~> 2.0) varia_model (~> 0.6) @@ -77,7 +77,7 @@ GEM fuzzyurl mixlib-config (~> 2.0) mixlib-shellout (~> 2.0) - chef-zero (5.3.0) + chef-zero (5.3.2) ffi-yajl (~> 2.2) hashie (>= 2.0, < 4.0) mixlib-log (~> 1.3) @@ -87,7 +87,7 @@ GEM chef (>= 12.0) fauxhai (~> 3.6) rspec (~> 3.0) - childprocess (0.5.9) + childprocess (0.6.3) ffi (~> 1.0, >= 1.0.11) cleanroom (1.0.0) colorize (0.8.1) @@ -114,10 +114,10 @@ GEM ruby_parser (~> 3.7) fauxhai (3.10.0) net-ssh - ffi (1.9.17) + ffi (1.9.18) ffi-yajl (2.3.0) libyajl2 (~> 1.2) - foodcritic (9.0.0) + foodcritic (10.4.1) cucumber-core (>= 1.3) erubis nokogiri (>= 1.5, < 2.0) @@ -126,24 +126,24 @@ GEM treetop (~> 1.4) yajl-ruby (~> 1.1) fuzzyurl (0.9.0) - gh (0.15.0) + gh (0.15.1) addressable (~> 2.4.0) backports faraday (~> 0.8) multi_json (~> 1.0) net-http-persistent (~> 2.9) net-http-pipeline - gherkin (4.0.0) + gherkin (4.1.1) hashie (3.5.5) highline (1.7.8) hitimes (1.2.4) httpclient (2.8.3) iniparse (1.4.2) ipaddress (0.8.3) - json (2.0.3) + json (2.1.0) kitchen-docker (2.6.0) test-kitchen (>= 1.0.0) - kitchen-vagrant (1.0.2) + kitchen-vagrant (1.1.0) test-kitchen (~> 1.4) kramdown (1.13.2) launchy (2.4.3) @@ -169,7 +169,7 @@ GEM mixlib-log (1.7.1) mixlib-shellout (2.2.7) mixlib-versioning (1.1.0) - molinillo (0.5.6) + molinillo (0.5.7) multi_json (1.12.1) multipart-post (2.0.0) net-http-persistent (2.9.4) @@ -186,9 +186,9 @@ GEM net-ssh-gateway (>= 1.2.0) net-telnet (0.1.1) nio4r (2.0.0) - nokogiri (1.7.0.1) + nokogiri (1.7.1) mini_portile2 (~> 2.1.0) - octokit (4.6.2) + octokit (4.7.0) sawyer (~> 0.8.0, >= 0.5.3) ohai (8.23.0) chef-config (>= 12.5.0.alpha.1, < 13) @@ -202,8 +202,8 @@ GEM plist (~> 3.1) systemu (~> 2.6.4) wmi-lite (~> 1.0) - overcommit (0.38.0) - childprocess (~> 0.5.8) + overcommit (0.39.1) + childprocess (~> 0.6.3) iniparse (~> 1.4) parser (2.4.0.0) ast (~> 2.2) @@ -215,7 +215,8 @@ GEM json websocket (~> 1.0) rack (2.0.1) - rainbow (2.2.1) + rainbow (2.2.2) + rake rake (12.0.0) retryable (2.0.4) ridley (5.1.0) @@ -255,14 +256,14 @@ GEM rspec_junit_formatter (0.2.3) builder (< 4) rspec-core (>= 2, < 4, != 2.12.0) - rubocop (0.47.1) + rubocop (0.48.1) parser (>= 2.3.3.1, < 3.0) powerpack (~> 0.1) rainbow (>= 1.99.1, < 3.0) ruby-progressbar (~> 1.7) unicode-display_width (~> 1.0, >= 1.0.1) ruby-progressbar (1.8.1) - ruby_parser (3.8.4) + ruby_parser (3.9.0) sexp_processor (~> 4.1) rufus-lru (1.1.0) safe_yaml (1.0.4) @@ -275,7 +276,7 @@ GEM rspec (~> 3.0) rspec-its specinfra (~> 2.53) - sexp_processor (4.8.0) + sexp_processor (4.9.0) sfl (2.3) simplecov (0.12.0) docile (~> 1.1.0) @@ -285,28 +286,28 @@ GEM solve (3.1.0) molinillo (>= 0.5) semverse (>= 1.1, < 3.0) - specinfra (2.67.2) + specinfra (2.67.8) net-scp net-ssh (>= 2.7, < 5.0) net-telnet sfl syslog-logger (1.6.8) systemu (2.6.5) - term-ansicolor (1.4.0) + term-ansicolor (1.6.0) tins (~> 1.0) - test-kitchen (1.15.0) + test-kitchen (1.16.0) mixlib-install (>= 1.2, < 3.0) mixlib-shellout (>= 1.2, < 3.0) net-scp (~> 1.1) net-ssh (>= 2.9, < 5.0) net-ssh-gateway (~> 1.2) safe_yaml (~> 1.0) - thor (~> 0.18) + thor (~> 0.19, < 0.19.2) thor (0.19.1) timers (4.0.4) hitimes tins (1.13.2) - travis (1.8.6) + travis (1.8.8) backports faraday (~> 0.9) faraday_middleware (~> 0.9, >= 0.9.1) @@ -319,7 +320,7 @@ GEM polyglot (~> 0.3) typhoeus (0.8.0) ethon (>= 0.8.0) - unicode-display_width (1.1.3) + unicode-display_width (1.2.1) uuidtools (2.1.5) varia_model (0.6.0) buff-extensions (~> 2.0) @@ -335,7 +336,9 @@ DEPENDENCIES berkshelf brakeman bundler-audit - chefspec + chef (~> 12.0) + chef-zero (~> 5.3) + chefspec (~> 6.0) coveralls fasterer foodcritic @@ -349,4 +352,4 @@ DEPENDENCIES travis BUNDLED WITH - 1.14.5 + 1.14.6 diff --git a/Rakefile b/Rakefile index 6ce47fd1..cd55d6a3 100644 --- a/Rakefile +++ b/Rakefile @@ -1,4 +1,5 @@ # frozen_string_literal: true + require 'bundler/setup' desc 'Run Test Kitchen integration tests' @@ -22,4 +23,4 @@ namespace :integration do end end -task default: %w(integration:vagrant) +task default: %w[integration:vagrant] diff --git a/attributes/default.rb b/attributes/default.rb index 63135e53..21afd493 100644 --- a/attributes/default.rb +++ b/attributes/default.rb @@ -4,10 +4,10 @@ default['build-essential']['compile_time'] = true default['ruby-ng']['ruby_version'] = node['ruby'].try(:[], 'version') || '2.4' -default['nginx']['source']['modules'] = %w( +default['nginx']['source']['modules'] = %w[ nginx::http_ssl_module nginx::http_realip_module nginx::http_gzip_static_module nginx::headers_more_module nginx::http_stub_status_module -) +] default['deploy']['timeout'] = 600 @@ -21,9 +21,10 @@ 'log' => 'log' } default['defaults']['global']['create_dirs_before_symlink'] = - %w(tmp public config ../../shared/cache ../../shared/assets) -default['defaults']['global']['purge_before_symlink'] = %w(log tmp/cache tmp/pids public/system public/assets) + %w[tmp public config ../../shared/cache ../../shared/assets] +default['defaults']['global']['purge_before_symlink'] = %w[log tmp/cache tmp/pids public/system public/assets] default['defaults']['global']['rollback_on_error'] = true +default['defaults']['global']['logrotate_rotate'] = 30 # database ## common diff --git a/docker-compose.yml b/docker-compose.yml new file mode 100644 index 00000000..d9b0b80e --- /dev/null +++ b/docker-compose.yml @@ -0,0 +1,8 @@ +--- +version: '2' + +services: + chef: + build: . + volumes: + - ".:/app" diff --git a/libraries/all.rb b/libraries/all.rb index 172819f0..4e529467 100644 --- a/libraries/all.rb +++ b/libraries/all.rb @@ -1,4 +1,5 @@ # frozen_string_literal: true + libdir = File.expand_path('..', __FILE__) require File.join(libdir, 'core_ext') require File.join(libdir, 'helpers') diff --git a/libraries/core_ext.rb b/libraries/core_ext.rb index c1efa6b5..696cb4d4 100644 --- a/libraries/core_ext.rb +++ b/libraries/core_ext.rb @@ -1,4 +1,5 @@ # frozen_string_literal: true + class Object def try(*a, &b) try!(*a, &b) if a.empty? || respond_to?(a.first) diff --git a/libraries/drivers_appserver_base.rb b/libraries/drivers_appserver_base.rb index f60da6fa..2cf63c05 100644 --- a/libraries/drivers_appserver_base.rb +++ b/libraries/drivers_appserver_base.rb @@ -1,4 +1,5 @@ # frozen_string_literal: true + module Drivers module Appserver class Base < Drivers::Base diff --git a/libraries/drivers_appserver_factory.rb b/libraries/drivers_appserver_factory.rb index 888ad3d6..afaa2718 100644 --- a/libraries/drivers_appserver_factory.rb +++ b/libraries/drivers_appserver_factory.rb @@ -1,4 +1,5 @@ # frozen_string_literal: true + module Drivers module Appserver class Factory diff --git a/libraries/drivers_appserver_null.rb b/libraries/drivers_appserver_null.rb index 7e6e6672..d5a26ca1 100644 --- a/libraries/drivers_appserver_null.rb +++ b/libraries/drivers_appserver_null.rb @@ -1,4 +1,5 @@ # frozen_string_literal: true + module Drivers module Appserver class Null < Drivers::Appserver::Base diff --git a/libraries/drivers_appserver_puma.rb b/libraries/drivers_appserver_puma.rb index efff8a32..d12a4566 100644 --- a/libraries/drivers_appserver_puma.rb +++ b/libraries/drivers_appserver_puma.rb @@ -1,10 +1,11 @@ # frozen_string_literal: true + module Drivers module Appserver class Puma < Drivers::Appserver::Base adapter :puma allowed_engines :puma - output filter: [:log_requests, :preload_app, :thread_max, :thread_min, :timeout, :worker_processes] + output filter: %i[log_requests preload_app thread_max thread_min timeout worker_processes] def appserver_config 'puma.rb' diff --git a/libraries/drivers_appserver_thin.rb b/libraries/drivers_appserver_thin.rb index 6f7e3274..8390cf6e 100644 --- a/libraries/drivers_appserver_thin.rb +++ b/libraries/drivers_appserver_thin.rb @@ -1,10 +1,11 @@ # frozen_string_literal: true + module Drivers module Appserver class Thin < Drivers::Appserver::Base adapter :thin allowed_engines :thin - output filter: [:max_connections, :max_persistent_connections, :timeout, :worker_processes] + output filter: %i[max_connections max_persistent_connections timeout worker_processes] def appserver_config 'thin.yml' diff --git a/libraries/drivers_appserver_unicorn.rb b/libraries/drivers_appserver_unicorn.rb index ba9a8eb5..2c799fcb 100644 --- a/libraries/drivers_appserver_unicorn.rb +++ b/libraries/drivers_appserver_unicorn.rb @@ -1,11 +1,12 @@ # frozen_string_literal: true + module Drivers module Appserver class Unicorn < Drivers::Appserver::Base adapter :unicorn allowed_engines :unicorn - output filter: [ - :backlog, :delay, :preload_app, :tcp_nodelay, :tcp_nopush, :tries, :timeout, :worker_processes + output filter: %i[ + backlog delay preload_app tcp_nodelay tcp_nopush tries timeout worker_processes ] def appserver_config diff --git a/libraries/drivers_base.rb b/libraries/drivers_base.rb index 21eba3e3..e4a244eb 100644 --- a/libraries/drivers_base.rb +++ b/libraries/drivers_base.rb @@ -1,4 +1,5 @@ # frozen_string_literal: true + module Drivers class Base attr_reader :app, :options, :configuration_data_source diff --git a/libraries/drivers_db_mysql.rb b/libraries/drivers_db_mysql.rb index 6f221f99..816f50a2 100644 --- a/libraries/drivers_db_mysql.rb +++ b/libraries/drivers_db_mysql.rb @@ -1,4 +1,5 @@ # frozen_string_literal: true + module Drivers module Db class Mysql < Base diff --git a/libraries/drivers_db_postgresql.rb b/libraries/drivers_db_postgresql.rb index eb3364b7..91464995 100644 --- a/libraries/drivers_db_postgresql.rb +++ b/libraries/drivers_db_postgresql.rb @@ -1,4 +1,5 @@ # frozen_string_literal: true + module Drivers module Db class Postgresql < Base diff --git a/libraries/drivers_db_sqlite.rb b/libraries/drivers_db_sqlite.rb index e4d40343..fd5c1954 100644 --- a/libraries/drivers_db_sqlite.rb +++ b/libraries/drivers_db_sqlite.rb @@ -1,4 +1,5 @@ # frozen_string_literal: true + module Drivers module Db class Sqlite < Base diff --git a/libraries/drivers_dsl_defaults.rb b/libraries/drivers_dsl_defaults.rb index 0d0ecd87..4858ade6 100644 --- a/libraries/drivers_dsl_defaults.rb +++ b/libraries/drivers_dsl_defaults.rb @@ -1,4 +1,5 @@ # frozen_string_literal: true + module Drivers module Dsl module Defaults diff --git a/libraries/drivers_dsl_logrotate.rb b/libraries/drivers_dsl_logrotate.rb new file mode 100644 index 00000000..18d95a7d --- /dev/null +++ b/libraries/drivers_dsl_logrotate.rb @@ -0,0 +1,48 @@ +# frozen_string_literal: true + +module Drivers + module Dsl + module Logrotate + def self.included(klass) + klass.instance_eval do + def log_paths(*log_paths) + @log_paths ||= [] + @log_paths += Array.wrap(log_paths) + @log_paths + end + end + end + # rubocop:enable Metrics/MethodLength + + def log_paths + self.class.log_paths.presence || + (self.class.superclass.respond_to?(:log_paths) && self.class.superclass.log_paths) + end + + def configure_logrotate + return if (log_paths || []).empty? + lr_path = logrotate_log_paths + lr_rotate = logrotate_rotate + + context.logrotate_app "#{app['shortname']}-#{adapter}-#{deploy_env}" do + path lr_path + frequency 'daily' + rotate lr_rotate + options %w[missingok compress delaycompress notifempty copytruncate sharedscripts] + end + end + + def logrotate_log_paths + log_paths.map do |log_path| + next log_path.call(self) if log_path.is_a?(Proc) + next log_path if log_path.start_with?('/') + File.join(deploy_dir(app), log_path) + end.flatten.uniq + end + + def logrotate_rotate + globals(:logrotate_rotate, app['shortname']) + end + end + end +end diff --git a/libraries/drivers_dsl_notifies.rb b/libraries/drivers_dsl_notifies.rb index c7c81e05..df7694cf 100644 --- a/libraries/drivers_dsl_notifies.rb +++ b/libraries/drivers_dsl_notifies.rb @@ -1,4 +1,5 @@ # frozen_string_literal: true + module Drivers module Dsl module Notifies diff --git a/libraries/drivers_dsl_output.rb b/libraries/drivers_dsl_output.rb index f673c96d..f4f54368 100644 --- a/libraries/drivers_dsl_output.rb +++ b/libraries/drivers_dsl_output.rb @@ -1,4 +1,5 @@ # frozen_string_literal: true + module Drivers module Dsl module Output diff --git a/libraries/drivers_dsl_packages.rb b/libraries/drivers_dsl_packages.rb index 9c842368..75dfc8a4 100644 --- a/libraries/drivers_dsl_packages.rb +++ b/libraries/drivers_dsl_packages.rb @@ -1,4 +1,5 @@ # frozen_string_literal: true + module Drivers module Dsl module Packages diff --git a/libraries/drivers_framework_base.rb b/libraries/drivers_framework_base.rb index 5490d783..7648eb71 100644 --- a/libraries/drivers_framework_base.rb +++ b/libraries/drivers_framework_base.rb @@ -1,7 +1,9 @@ # frozen_string_literal: true + module Drivers module Framework class Base < Drivers::Base + include Drivers::Dsl::Logrotate include Drivers::Dsl::Output include Drivers::Dsl::Packages @@ -9,6 +11,10 @@ def setup handle_packages end + def configure + configure_logrotate + end + def deploy_before_migrate link_sqlite_database end diff --git a/libraries/drivers_framework_factory.rb b/libraries/drivers_framework_factory.rb index 5c71bd13..94e1f727 100644 --- a/libraries/drivers_framework_factory.rb +++ b/libraries/drivers_framework_factory.rb @@ -1,4 +1,5 @@ # frozen_string_literal: true + module Drivers module Framework class Factory diff --git a/libraries/drivers_framework_hanami.rb b/libraries/drivers_framework_hanami.rb index 3736dd92..e7440a21 100644 --- a/libraries/drivers_framework_hanami.rb +++ b/libraries/drivers_framework_hanami.rb @@ -1,11 +1,12 @@ # frozen_string_literal: true + module Drivers module Framework class Hanami < Drivers::Framework::Base adapter :hanami allowed_engines :hanami - output filter: [ - :migrate, :migration_command, :deploy_environment, :assets_precompile, :assets_precompilation_command + output filter: %i[ + migrate migration_command deploy_environment assets_precompile assets_precompilation_command ] def raw_out @@ -24,6 +25,7 @@ def raw_out def configure build_env + super end def deploy_before_restart diff --git a/libraries/drivers_framework_null.rb b/libraries/drivers_framework_null.rb index e7d86a50..355a240f 100644 --- a/libraries/drivers_framework_null.rb +++ b/libraries/drivers_framework_null.rb @@ -1,4 +1,5 @@ # frozen_string_literal: true + module Drivers module Framework class Null < Drivers::Framework::Base diff --git a/libraries/drivers_framework_padrino.rb b/libraries/drivers_framework_padrino.rb index 52061a73..d1e0c424 100644 --- a/libraries/drivers_framework_padrino.rb +++ b/libraries/drivers_framework_padrino.rb @@ -1,11 +1,12 @@ # frozen_string_literal: true + module Drivers module Framework class Padrino < Drivers::Framework::Base adapter :padrino allowed_engines :padrino - output filter: [ - :migrate, :migration_command, :deploy_environment, :assets_precompile, :assets_precompilation_command + output filter: %i[ + migrate migration_command deploy_environment assets_precompile assets_precompilation_command ] def raw_out diff --git a/libraries/drivers_framework_rails.rb b/libraries/drivers_framework_rails.rb index 3cf8d779..7c2d6c6c 100644 --- a/libraries/drivers_framework_rails.rb +++ b/libraries/drivers_framework_rails.rb @@ -1,14 +1,18 @@ # frozen_string_literal: true + module Drivers module Framework class Rails < Drivers::Framework::Base adapter :rails allowed_engines :rails - output filter: [ - :migrate, :migration_command, :deploy_environment, :assets_precompile, :assets_precompilation_command, - :envs_in_console + output filter: %i[ + migrate migration_command deploy_environment assets_precompile assets_precompilation_command + envs_in_console ] packages debian: 'zlib1g-dev', rhel: 'zlib-devel' + log_paths lambda { |context| + File.join(context.send(:deploy_dir, context.app), 'shared', 'log', "#{context.send(:deploy_env)}.log") + } def raw_out super.merge(deploy_environment: { 'RAILS_ENV' => deploy_env }) @@ -20,6 +24,7 @@ def configure rdses.each do |rds| database_yml(Drivers::Db::Factory.build(context, app, rds: rds)) end + super end def deploy_after_restart @@ -28,6 +33,10 @@ def deploy_after_restart private + def logs_path + File.join(deploy_dir(app), 'shared', 'log', "#{deploy_env}.log") + end + def database_yml(db) return unless db.applicable_for_configuration? diff --git a/libraries/drivers_scm_base.rb b/libraries/drivers_scm_base.rb index 447d21fd..66cc1355 100644 --- a/libraries/drivers_scm_base.rb +++ b/libraries/drivers_scm_base.rb @@ -1,4 +1,5 @@ # frozen_string_literal: true + module Drivers module Scm class Base < Drivers::Base diff --git a/libraries/drivers_scm_factory.rb b/libraries/drivers_scm_factory.rb index 5fd012e5..10c8b43c 100644 --- a/libraries/drivers_scm_factory.rb +++ b/libraries/drivers_scm_factory.rb @@ -1,4 +1,5 @@ # frozen_string_literal: true + module Drivers module Scm class Factory diff --git a/libraries/drivers_scm_git.rb b/libraries/drivers_scm_git.rb index f88e9001..66775a26 100644 --- a/libraries/drivers_scm_git.rb +++ b/libraries/drivers_scm_git.rb @@ -1,11 +1,12 @@ # frozen_string_literal: true + module Drivers module Scm class Git < Drivers::Scm::Base adapter Chef::Provider::Git allowed_engines :git packages :git - output filter: [:scm_provider, :repository, :revision, :enable_submodules, :ssh_wrapper, :remove_scm_files] + output filter: %i[scm_provider repository revision enable_submodules ssh_wrapper remove_scm_files] defaults enable_submodules: true, ssh_wrapper: '/tmp/ssh-git-wrapper.sh' def before_deploy diff --git a/libraries/drivers_webserver_apache2.rb b/libraries/drivers_webserver_apache2.rb index e33551b2..1234bb5e 100644 --- a/libraries/drivers_webserver_apache2.rb +++ b/libraries/drivers_webserver_apache2.rb @@ -1,18 +1,24 @@ # frozen_string_literal: true + module Drivers module Webserver class Apache2 < Drivers::Webserver::Base adapter :apache2 allowed_engines :apache2 - packages debian: 'apache2', rhel: %w(httpd24 mod24_ssl) - output filter: [ - :dhparams, :keepalive_timeout, :limit_request_body, :log_dir, :log_level, :proxy_timeout, - :ssl_for_legacy_browsers, :extra_config, :extra_config_ssl + packages debian: 'apache2', rhel: %w[httpd24 mod24_ssl] + output filter: %i[ + dhparams keepalive_timeout limit_request_body log_dir log_level proxy_timeout + ssl_for_legacy_browsers extra_config extra_config_ssl ] notifies :deploy, action: :restart, resource: { debian: 'service[apache2]', rhel: 'service[httpd]' }, timer: :delayed notifies :undeploy, action: :restart, resource: { debian: 'service[apache2]', rhel: 'service[httpd]' }, timer: :delayed + log_paths lambda { |context| + %w[access.log error.log].map do |log_type| + File.join(context.raw_out[:log_dir], "#{context.app[:domains].first}.#{log_type}") + end + } def raw_out output = node['defaults']['webserver'].merge( @@ -25,7 +31,7 @@ def raw_out def setup handle_packages - enable_modules(%w(expires headers lbmethod_byrequests proxy proxy_balancer proxy_http rewrite ssl)) + enable_modules(%w[expires headers lbmethod_byrequests proxy proxy_balancer proxy_http rewrite ssl]) add_sites_available_enabled define_service(:start) end @@ -40,6 +46,7 @@ def configure remove_defaults add_appserver_config enable_appserver_config + super end def before_deploy diff --git a/libraries/drivers_webserver_base.rb b/libraries/drivers_webserver_base.rb index 68626fd0..c172cbf6 100644 --- a/libraries/drivers_webserver_base.rb +++ b/libraries/drivers_webserver_base.rb @@ -1,11 +1,17 @@ # frozen_string_literal: true + module Drivers module Webserver class Base < Drivers::Base + include Drivers::Dsl::Logrotate include Drivers::Dsl::Notifies include Drivers::Dsl::Output include Drivers::Dsl::Packages + def configure + configure_logrotate + end + def out handle_output(raw_out) end diff --git a/libraries/drivers_webserver_factory.rb b/libraries/drivers_webserver_factory.rb index 2f20086a..2393fcfa 100644 --- a/libraries/drivers_webserver_factory.rb +++ b/libraries/drivers_webserver_factory.rb @@ -1,4 +1,5 @@ # frozen_string_literal: true + module Drivers module Webserver class Factory diff --git a/libraries/drivers_webserver_nginx.rb b/libraries/drivers_webserver_nginx.rb index 63f30a2f..1058c237 100644 --- a/libraries/drivers_webserver_nginx.rb +++ b/libraries/drivers_webserver_nginx.rb @@ -1,16 +1,22 @@ # frozen_string_literal: true + module Drivers module Webserver class Nginx < Drivers::Webserver::Base adapter :nginx allowed_engines :nginx - output filter: [ - :build_type, :client_body_timeout, :client_header_timeout, :client_max_body_size, :dhparams, :keepalive_timeout, - :log_dir, :log_level, :proxy_read_timeout, :proxy_send_timeout, :send_timeout, :ssl_for_legacy_browsers, - :extra_config, :extra_config_ssl + output filter: %i[ + build_type client_body_timeout client_header_timeout client_max_body_size dhparams keepalive_timeout + log_dir log_level proxy_read_timeout proxy_send_timeout send_timeout ssl_for_legacy_browsers + extra_config extra_config_ssl ] notifies :deploy, action: :restart, resource: 'service[nginx]', timer: :delayed notifies :undeploy, action: :restart, resource: 'service[nginx]', timer: :delayed + log_paths lambda { |context| + %w[access.log error.log].map do |log_type| + File.join(context.raw_out[:log_dir], "#{context.app[:domains].first}.#{log_type}") + end + } def raw_out output = node['defaults']['webserver'].merge(node['nginx']).merge( @@ -36,6 +42,7 @@ def configure add_appserver_config enable_appserver_config + super end def before_deploy diff --git a/libraries/drivers_webserver_null.rb b/libraries/drivers_webserver_null.rb index 196d9f67..3cd34824 100644 --- a/libraries/drivers_webserver_null.rb +++ b/libraries/drivers_webserver_null.rb @@ -1,4 +1,5 @@ # frozen_string_literal: true + module Drivers module Webserver class Null < Drivers::Webserver::Base diff --git a/libraries/drivers_worker_base.rb b/libraries/drivers_worker_base.rb index 24427cf0..c32eb809 100644 --- a/libraries/drivers_worker_base.rb +++ b/libraries/drivers_worker_base.rb @@ -1,4 +1,5 @@ # frozen_string_literal: true + module Drivers module Worker class Base < Drivers::Base diff --git a/libraries/drivers_worker_delayed_job.rb b/libraries/drivers_worker_delayed_job.rb index 08c9bc59..ea60377e 100644 --- a/libraries/drivers_worker_delayed_job.rb +++ b/libraries/drivers_worker_delayed_job.rb @@ -1,10 +1,11 @@ # frozen_string_literal: true + module Drivers module Worker class DelayedJob < Drivers::Worker::Base adapter :delayed_job allowed_engines :delayed_job - output filter: [:process_count, :syslog, :queues] + output filter: %i[process_count syslog queues] packages :monit def after_deploy diff --git a/libraries/drivers_worker_factory.rb b/libraries/drivers_worker_factory.rb index 93d543d7..5ddee7f4 100644 --- a/libraries/drivers_worker_factory.rb +++ b/libraries/drivers_worker_factory.rb @@ -1,4 +1,5 @@ # frozen_string_literal: true + module Drivers module Worker class Factory diff --git a/libraries/drivers_worker_null.rb b/libraries/drivers_worker_null.rb index 0423bf92..ec8c0b32 100644 --- a/libraries/drivers_worker_null.rb +++ b/libraries/drivers_worker_null.rb @@ -1,4 +1,5 @@ # frozen_string_literal: true + module Drivers module Worker class Null < Drivers::Worker::Base diff --git a/libraries/drivers_worker_resque.rb b/libraries/drivers_worker_resque.rb index e3d74b07..dece6f92 100644 --- a/libraries/drivers_worker_resque.rb +++ b/libraries/drivers_worker_resque.rb @@ -1,10 +1,11 @@ # frozen_string_literal: true + module Drivers module Worker class Resque < Drivers::Worker::Base adapter :resque allowed_engines :resque - output filter: [:process_count, :syslog, :workers, :queues] + output filter: %i[process_count syslog workers queues] packages :monit, debian: 'redis-server', rhel: 'redis' def configure diff --git a/libraries/drivers_worker_sidekiq.rb b/libraries/drivers_worker_sidekiq.rb index 3d962711..4b72d3f9 100644 --- a/libraries/drivers_worker_sidekiq.rb +++ b/libraries/drivers_worker_sidekiq.rb @@ -1,10 +1,11 @@ # frozen_string_literal: true + module Drivers module Worker class Sidekiq < Drivers::Worker::Base adapter :sidekiq allowed_engines :sidekiq - output filter: [:config, :process_count, :require, :syslog] + output filter: %i[config process_count require syslog] packages 'monit', debian: 'redis-server', rhel: 'redis' def configure diff --git a/libraries/helpers.rb b/libraries/helpers.rb index a4976aa6..3085bb84 100644 --- a/libraries/helpers.rb +++ b/libraries/helpers.rb @@ -100,5 +100,5 @@ def prepare_recipe def apps_not_included return [] if node['applications'].blank? - node['deploy'].keys.select { |app_name| !node['applications'].include?(app_name) } + node['deploy'].keys.reject { |app_name| node['applications'].include?(app_name) } end diff --git a/metadata.rb b/metadata.rb index ffc4bd9a..2b08ad1a 100644 --- a/metadata.rb +++ b/metadata.rb @@ -1,4 +1,5 @@ # frozen_string_literal: true + name 'opsworks_ruby' maintainer 'Igor Rzegocki' maintainer_email 'igor@rzegocki.pl' @@ -6,10 +7,12 @@ description 'Set of chef recipes for OpsWorks based Ruby projects' long_description IO.read(File.join(File.dirname(__FILE__), 'README.md')) version '1.4.0' +chef_version '~> 12.0' if respond_to?(:chef_version) depends 'deployer' -depends 'ruby-ng' depends 'chef_nginx' +depends 'logrotate' +depends 'ruby-ng' supports 'amazon', '>= 2015.03' supports 'ubuntu', '>= 12.04' diff --git a/recipes/configure.rb b/recipes/configure.rb index 7d3ea690..1d4899b0 100644 --- a/recipes/configure.rb +++ b/recipes/configure.rb @@ -1,4 +1,5 @@ # frozen_string_literal: true + # # Cookbook Name:: opsworks_ruby # Recipe:: configure diff --git a/recipes/default.rb b/recipes/default.rb index fb4972af..9d5191d7 100644 --- a/recipes/default.rb +++ b/recipes/default.rb @@ -1,2 +1,3 @@ # frozen_string_literal: true + include_recipe 'opsworks_ruby::deploy' diff --git a/recipes/provision.rb b/recipes/provision.rb index f13ceed5..d18ab74d 100644 --- a/recipes/provision.rb +++ b/recipes/provision.rb @@ -1,4 +1,5 @@ # frozen_string_literal: true + # Used for tests, don't touch! file '/etc/monit/conf.d/00_httpd.monitrc' do diff --git a/recipes/setup.rb b/recipes/setup.rb index a88a3f5e..91b324fb 100644 --- a/recipes/setup.rb +++ b/recipes/setup.rb @@ -1,4 +1,5 @@ # frozen_string_literal: true + # # Cookbook Name:: opsworks_ruby # Recipe:: setup @@ -20,13 +21,16 @@ apt_repository 'apache2' do uri 'http://ppa.launchpad.net/ondrej/apache2/ubuntu' distribution node['lsb']['codename'] - components %w(main) + components %w[main] keyserver 'keyserver.ubuntu.com' key 'E5267A6C' only_if { node['platform'] == 'ubuntu' } end -gem_package 'bundler' +gem_package 'bundler' do + action :install +end + if node['platform_family'] == 'debian' link '/usr/local/bin/bundle' do to '/usr/bin/bundle' diff --git a/recipes/shutdown.rb b/recipes/shutdown.rb index ca55857c..28ace4cb 100644 --- a/recipes/shutdown.rb +++ b/recipes/shutdown.rb @@ -1,4 +1,5 @@ # frozen_string_literal: true + # # Cookbook Name:: opsworks_ruby # Recipe:: shutdown diff --git a/spec/fixtures/aws_opsworks_app.rb b/spec/fixtures/aws_opsworks_app.rb index b47cab99..fb417f57 100644 --- a/spec/fixtures/aws_opsworks_app.rb +++ b/spec/fixtures/aws_opsworks_app.rb @@ -1,4 +1,5 @@ # frozen_string_literal: true + # rubocop:disable Metrics/MethodLength def aws_opsworks_app(override = {}) item = { diff --git a/spec/fixtures/aws_opsworks_rds_db_instance.rb b/spec/fixtures/aws_opsworks_rds_db_instance.rb index c65d6c69..45f1f904 100644 --- a/spec/fixtures/aws_opsworks_rds_db_instance.rb +++ b/spec/fixtures/aws_opsworks_rds_db_instance.rb @@ -1,4 +1,5 @@ # frozen_string_literal: true + # rubocop:disable Metrics/MethodLength def aws_opsworks_rds_db_instance(override = {}) item = { diff --git a/spec/fixtures/node.rb b/spec/fixtures/node.rb index e5f8b0d4..88844018 100644 --- a/spec/fixtures/node.rb +++ b/spec/fixtures/node.rb @@ -1,4 +1,5 @@ # frozen_string_literal: true + # rubocop:disable Metrics/MethodLength def node(override = {}) item = { @@ -14,7 +15,7 @@ def node(override = {}) global: { environment: 'staging', create_dirs_before_symlink: %(../shared/test), - purge_before_symlink: %w(public/test), + purge_before_symlink: %w[public/test], symlinks: { 'test' => 'public/test' } }, # database: { @@ -73,8 +74,8 @@ def node(override = {}) pids: 'tmp/pids', log: 'log' }, - create_dirs_before_symlink: %w(tmp public config ../../shared/cache ../../shared/assets), - purge_before_symlink: %w(log tmp/cache tmp/pids public/system public/assets) + create_dirs_before_symlink: %w[tmp public config ../../shared/cache ../../shared/assets], + purge_before_symlink: %w[log tmp/cache tmp/pids public/system public/assets] }, scm: { remove_scm_files: true diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 1cdbbeec..df379fc6 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -1,4 +1,5 @@ # frozen_string_literal: true + require 'chefspec' require 'chefspec/berkshelf' diff --git a/spec/unit/examples/db_parameters_and_connection.rb b/spec/unit/examples/db_parameters_and_connection.rb index b565c718..ed2d0fe7 100644 --- a/spec/unit/examples/db_parameters_and_connection.rb +++ b/spec/unit/examples/db_parameters_and_connection.rb @@ -1,4 +1,5 @@ # frozen_string_literal: true + RSpec.shared_examples 'db parameters and connection' do |rdbms, options = {}| it 'receives and exposes app, node and database bag' do driver = described_class.new( diff --git a/spec/unit/examples/db_validate_adapter_and_engine.rb b/spec/unit/examples/db_validate_adapter_and_engine.rb index fe5f517a..e73c6884 100644 --- a/spec/unit/examples/db_validate_adapter_and_engine.rb +++ b/spec/unit/examples/db_validate_adapter_and_engine.rb @@ -1,4 +1,5 @@ # frozen_string_literal: true + RSpec.shared_examples 'db validate adapter and engine' do |rdbms| context "#{rdbms}: validate adapter and engine" do it 'adapter = missing, engine = missing' do diff --git a/spec/unit/libraries/core_ext_spec.rb b/spec/unit/libraries/core_ext_spec.rb index 6f50a7a6..df5dd9a1 100644 --- a/spec/unit/libraries/core_ext_spec.rb +++ b/spec/unit/libraries/core_ext_spec.rb @@ -1,4 +1,5 @@ # frozen_string_literal: true + require 'spec_helper' describe 'Core extensions' do diff --git a/spec/unit/libraries/drivers_appserver_factory_spec.rb b/spec/unit/libraries/drivers_appserver_factory_spec.rb index 99fa4195..9d9d9852 100644 --- a/spec/unit/libraries/drivers_appserver_factory_spec.rb +++ b/spec/unit/libraries/drivers_appserver_factory_spec.rb @@ -1,4 +1,5 @@ # frozen_string_literal: true + require 'spec_helper' describe Drivers::Appserver::Factory do diff --git a/spec/unit/libraries/drivers_appserver_null_spec.rb b/spec/unit/libraries/drivers_appserver_null_spec.rb index 5b669a82..e01cfd1b 100644 --- a/spec/unit/libraries/drivers_appserver_null_spec.rb +++ b/spec/unit/libraries/drivers_appserver_null_spec.rb @@ -1,4 +1,5 @@ # frozen_string_literal: true + require 'spec_helper' describe Drivers::Appserver::Null do diff --git a/spec/unit/libraries/drivers_appserver_puma_spec.rb b/spec/unit/libraries/drivers_appserver_puma_spec.rb index 4d674b09..2afb50e5 100644 --- a/spec/unit/libraries/drivers_appserver_puma_spec.rb +++ b/spec/unit/libraries/drivers_appserver_puma_spec.rb @@ -1,4 +1,5 @@ # frozen_string_literal: true + require 'spec_helper' describe Drivers::Appserver::Puma do diff --git a/spec/unit/libraries/drivers_appserver_thin_spec.rb b/spec/unit/libraries/drivers_appserver_thin_spec.rb index 987b069f..8d7e10e1 100644 --- a/spec/unit/libraries/drivers_appserver_thin_spec.rb +++ b/spec/unit/libraries/drivers_appserver_thin_spec.rb @@ -1,4 +1,5 @@ # frozen_string_literal: true + require 'spec_helper' describe Drivers::Appserver::Thin do diff --git a/spec/unit/libraries/drivers_appserver_unicorn_spec.rb b/spec/unit/libraries/drivers_appserver_unicorn_spec.rb index e84fa373..02339bfd 100644 --- a/spec/unit/libraries/drivers_appserver_unicorn_spec.rb +++ b/spec/unit/libraries/drivers_appserver_unicorn_spec.rb @@ -1,4 +1,5 @@ # frozen_string_literal: true + require 'spec_helper' describe Drivers::Appserver::Unicorn do diff --git a/spec/unit/libraries/drivers_db_factory_spec.rb b/spec/unit/libraries/drivers_db_factory_spec.rb index d43e14e2..9a26ff33 100644 --- a/spec/unit/libraries/drivers_db_factory_spec.rb +++ b/spec/unit/libraries/drivers_db_factory_spec.rb @@ -1,4 +1,5 @@ # frozen_string_literal: true + require 'spec_helper' describe Drivers::Db::Factory do diff --git a/spec/unit/libraries/drivers_db_mysql_spec.rb b/spec/unit/libraries/drivers_db_mysql_spec.rb index aabe4ac2..0f0b5e13 100644 --- a/spec/unit/libraries/drivers_db_mysql_spec.rb +++ b/spec/unit/libraries/drivers_db_mysql_spec.rb @@ -1,4 +1,5 @@ # frozen_string_literal: true + require 'spec_helper' require 'unit/examples/db_validate_adapter_and_engine' require 'unit/examples/db_parameters_and_connection' diff --git a/spec/unit/libraries/drivers_db_postgresql_spec.rb b/spec/unit/libraries/drivers_db_postgresql_spec.rb index 2bc75520..1e3d75a9 100644 --- a/spec/unit/libraries/drivers_db_postgresql_spec.rb +++ b/spec/unit/libraries/drivers_db_postgresql_spec.rb @@ -1,4 +1,5 @@ # frozen_string_literal: true + require 'spec_helper' require 'unit/examples/db_validate_adapter_and_engine' require 'unit/examples/db_parameters_and_connection' diff --git a/spec/unit/libraries/drivers_framework_factory_spec.rb b/spec/unit/libraries/drivers_framework_factory_spec.rb index 4b63844a..4a75f93e 100644 --- a/spec/unit/libraries/drivers_framework_factory_spec.rb +++ b/spec/unit/libraries/drivers_framework_factory_spec.rb @@ -1,4 +1,5 @@ # frozen_string_literal: true + require 'spec_helper' describe Drivers::Framework::Factory do diff --git a/spec/unit/libraries/drivers_framework_hanami_spec.rb b/spec/unit/libraries/drivers_framework_hanami_spec.rb index e1f3b173..689fedab 100644 --- a/spec/unit/libraries/drivers_framework_hanami_spec.rb +++ b/spec/unit/libraries/drivers_framework_hanami_spec.rb @@ -1,4 +1,5 @@ # frozen_string_literal: true + require 'spec_helper' describe Drivers::Framework::Hanami do diff --git a/spec/unit/libraries/drivers_framework_null_spec.rb b/spec/unit/libraries/drivers_framework_null_spec.rb index e9c15537..77b0ac51 100644 --- a/spec/unit/libraries/drivers_framework_null_spec.rb +++ b/spec/unit/libraries/drivers_framework_null_spec.rb @@ -1,4 +1,5 @@ # frozen_string_literal: true + require 'spec_helper' describe Drivers::Framework::Null do diff --git a/spec/unit/libraries/drivers_framework_padrino_spec.rb b/spec/unit/libraries/drivers_framework_padrino_spec.rb index 57375b35..195bf872 100644 --- a/spec/unit/libraries/drivers_framework_padrino_spec.rb +++ b/spec/unit/libraries/drivers_framework_padrino_spec.rb @@ -1,4 +1,5 @@ # frozen_string_literal: true + require 'spec_helper' describe Drivers::Framework::Padrino do diff --git a/spec/unit/libraries/drivers_framework_rails_spec.rb b/spec/unit/libraries/drivers_framework_rails_spec.rb index d28f1d38..5c4e46df 100644 --- a/spec/unit/libraries/drivers_framework_rails_spec.rb +++ b/spec/unit/libraries/drivers_framework_rails_spec.rb @@ -1,4 +1,5 @@ # frozen_string_literal: true + require 'spec_helper' describe Drivers::Framework::Rails do diff --git a/spec/unit/libraries/drivers_scm_factory_spec.rb b/spec/unit/libraries/drivers_scm_factory_spec.rb index 55ce7e81..7ef8b837 100644 --- a/spec/unit/libraries/drivers_scm_factory_spec.rb +++ b/spec/unit/libraries/drivers_scm_factory_spec.rb @@ -1,4 +1,5 @@ # frozen_string_literal: true + require 'spec_helper' describe Drivers::Scm::Factory do diff --git a/spec/unit/libraries/drivers_scm_git_spec.rb b/spec/unit/libraries/drivers_scm_git_spec.rb index e995ec2d..1bc1e89c 100644 --- a/spec/unit/libraries/drivers_scm_git_spec.rb +++ b/spec/unit/libraries/drivers_scm_git_spec.rb @@ -1,4 +1,5 @@ # frozen_string_literal: true + require 'spec_helper' describe Drivers::Scm::Git do diff --git a/spec/unit/libraries/drivers_webserver_apache2_spec.rb b/spec/unit/libraries/drivers_webserver_apache2_spec.rb index 18abad0c..92958512 100644 --- a/spec/unit/libraries/drivers_webserver_apache2_spec.rb +++ b/spec/unit/libraries/drivers_webserver_apache2_spec.rb @@ -1,4 +1,5 @@ # frozen_string_literal: true + require 'spec_helper' describe Drivers::Webserver::Apache2 do diff --git a/spec/unit/libraries/drivers_webserver_factory_spec.rb b/spec/unit/libraries/drivers_webserver_factory_spec.rb index 5254b2fa..20b9ffb7 100644 --- a/spec/unit/libraries/drivers_webserver_factory_spec.rb +++ b/spec/unit/libraries/drivers_webserver_factory_spec.rb @@ -1,4 +1,5 @@ # frozen_string_literal: true + require 'spec_helper' describe Drivers::Webserver::Factory do diff --git a/spec/unit/libraries/drivers_webserver_nginx_spec.rb b/spec/unit/libraries/drivers_webserver_nginx_spec.rb index 07a0d959..e8422da5 100644 --- a/spec/unit/libraries/drivers_webserver_nginx_spec.rb +++ b/spec/unit/libraries/drivers_webserver_nginx_spec.rb @@ -1,4 +1,5 @@ # frozen_string_literal: true + require 'spec_helper' describe Drivers::Webserver::Nginx do diff --git a/spec/unit/libraries/drivers_webserver_null_spec.rb b/spec/unit/libraries/drivers_webserver_null_spec.rb index 6ef117eb..670b451d 100644 --- a/spec/unit/libraries/drivers_webserver_null_spec.rb +++ b/spec/unit/libraries/drivers_webserver_null_spec.rb @@ -1,4 +1,5 @@ # frozen_string_literal: true + require 'spec_helper' describe Drivers::Webserver::Null do diff --git a/spec/unit/libraries/drivers_worker_delayed_job_spec.rb b/spec/unit/libraries/drivers_worker_delayed_job_spec.rb index 6ddb54fe..c22f23cb 100644 --- a/spec/unit/libraries/drivers_worker_delayed_job_spec.rb +++ b/spec/unit/libraries/drivers_worker_delayed_job_spec.rb @@ -1,4 +1,5 @@ # frozen_string_literal: true + require 'spec_helper' describe Drivers::Worker::DelayedJob do diff --git a/spec/unit/libraries/drivers_worker_factory_spec.rb b/spec/unit/libraries/drivers_worker_factory_spec.rb index d9209f8a..a49b96f7 100644 --- a/spec/unit/libraries/drivers_worker_factory_spec.rb +++ b/spec/unit/libraries/drivers_worker_factory_spec.rb @@ -1,4 +1,5 @@ # frozen_string_literal: true + require 'spec_helper' describe Drivers::Worker::Factory do diff --git a/spec/unit/libraries/drivers_worker_null_spec.rb b/spec/unit/libraries/drivers_worker_null_spec.rb index 4c4156df..6ce72082 100644 --- a/spec/unit/libraries/drivers_worker_null_spec.rb +++ b/spec/unit/libraries/drivers_worker_null_spec.rb @@ -1,4 +1,5 @@ # frozen_string_literal: true + require 'spec_helper' describe Drivers::Worker::Null do diff --git a/spec/unit/libraries/drivers_worker_resque_spec.rb b/spec/unit/libraries/drivers_worker_resque_spec.rb index ec6704dc..941fe957 100644 --- a/spec/unit/libraries/drivers_worker_resque_spec.rb +++ b/spec/unit/libraries/drivers_worker_resque_spec.rb @@ -1,4 +1,5 @@ # frozen_string_literal: true + require 'spec_helper' describe Drivers::Worker::Resque do diff --git a/spec/unit/libraries/drivers_worker_sidekiq_spec.rb b/spec/unit/libraries/drivers_worker_sidekiq_spec.rb index 4fc85967..712466a9 100644 --- a/spec/unit/libraries/drivers_worker_sidekiq_spec.rb +++ b/spec/unit/libraries/drivers_worker_sidekiq_spec.rb @@ -1,4 +1,5 @@ # frozen_string_literal: true + require 'spec_helper' describe Drivers::Worker::Sidekiq do diff --git a/spec/unit/recipes/configure_spec.rb b/spec/unit/recipes/configure_spec.rb index 920c9846..9927f258 100644 --- a/spec/unit/recipes/configure_spec.rb +++ b/spec/unit/recipes/configure_spec.rb @@ -1,4 +1,5 @@ # frozen_string_literal: true + # # Cookbook Name:: opsworks_ruby # Spec:: configure @@ -64,6 +65,16 @@ ) end + it 'creates logrotate file for rails' do + expect(chef_run) + .to enable_logrotate_app("#{aws_opsworks_app['shortname']}-rails-staging") + end + + it 'creates logrotate file for nginx' do + expect(chef_run) + .to enable_logrotate_app("#{aws_opsworks_app['shortname']}-nginx-staging") + end + it 'creates proper unicorn.conf file' do expect(chef_run) .to render_file("/srv/www/#{aws_opsworks_app['shortname']}/shared/config/unicorn.conf") @@ -332,6 +343,11 @@ stub_search(:aws_opsworks_rds_db_instance, '*:*').and_return([aws_opsworks_rds_db_instance(engine: 'mysql')]) end + it 'creates logrotate file for apache2' do + expect(chef_run) + .to enable_logrotate_app("#{aws_opsworks_app['shortname']}-apache2-staging") + end + it 'creates proper .env.*' do db_config = Drivers::Db::Mysql.new(chef_run, aws_opsworks_app, rds: aws_opsworks_rds_db_instance(engine: 'mysql')).out @@ -895,13 +911,27 @@ end end - it 'empty node[\'deploy\']' do - chef_run = ChefSpec::SoloRunner.new(platform: 'ubuntu', version: '14.04') do |solo_node| - solo_node.set['lsb'] = node['lsb'] - end.converge(described_recipe) + context 'empty node[\'deploy\']' do + let(:chef_run) do + ChefSpec::SoloRunner.new(platform: 'ubuntu', version: '14.04') do |solo_node| + solo_node.set['lsb'] = node['lsb'] + end.converge(described_recipe) + end + + it 'not raises error' do + expect do + chef_run + end.not_to raise_error + end - expect do - chef_run - end.not_to raise_error + it 'creates logrotate file for rails' do + expect(chef_run) + .to enable_logrotate_app("#{aws_opsworks_app['shortname']}-rails-production") + end + + it 'creates logrotate file for rails' do + expect(chef_run) + .to enable_logrotate_app("#{aws_opsworks_app['shortname']}-nginx-production") + end end end diff --git a/spec/unit/recipes/deploy_spec.rb b/spec/unit/recipes/deploy_spec.rb index e1c2103a..30e7bd24 100644 --- a/spec/unit/recipes/deploy_spec.rb +++ b/spec/unit/recipes/deploy_spec.rb @@ -1,4 +1,5 @@ # frozen_string_literal: true + # # Cookbook Name:: opsworks_ruby # Spec:: deploy @@ -93,8 +94,8 @@ 'log' => 'log', 'test' => 'public/test' }, - 'create_dirs_before_symlink' => %w(tmp public config ../../shared/cache ../../shared/assets ../shared/test), - 'purge_before_symlink' => %w(log tmp/cache tmp/pids public/system public/assets public/test) + 'create_dirs_before_symlink' => %w[tmp public config ../../shared/cache ../../shared/assets ../shared/test], + 'purge_before_symlink' => %w[log tmp/cache tmp/pids public/system public/assets public/test] ) expect(chef_run).to run_execute('stop unicorn') @@ -204,7 +205,7 @@ 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' => {}, 'a3' => {} } - solo_node.set['applications'] = %w(a1 a2) + solo_node.set['applications'] = %w[a1 a2] end.converge(described_recipe) service = chef_run.service('puma_a1') @@ -220,6 +221,9 @@ expect(chef_run).to create_template('/srv/www/a1/shared/scripts/puma.service') expect(chef_run).to create_template('/etc/nginx/sites-available/a1.conf') expect(chef_run).to create_link('/etc/nginx/sites-enabled/a1.conf') + expect(chef_run).to enable_logrotate_app('a1-nginx-production') + expect(chef_run).to enable_logrotate_app('a1-rails-production') + expect(service).to do_nothing expect(chef_run).to deploy_deploy('a1') expect(chef_run).not_to deploy_deploy('a2') diff --git a/spec/unit/recipes/setup_spec.rb b/spec/unit/recipes/setup_spec.rb index 2491545b..282138fe 100644 --- a/spec/unit/recipes/setup_spec.rb +++ b/spec/unit/recipes/setup_spec.rb @@ -1,4 +1,5 @@ # frozen_string_literal: true + # # Cookbook Name:: opsworks_ruby # Spec:: default diff --git a/spec/unit/recipes/shutdown_spec.rb b/spec/unit/recipes/shutdown_spec.rb index 50d78df8..74f6ecfb 100644 --- a/spec/unit/recipes/shutdown_spec.rb +++ b/spec/unit/recipes/shutdown_spec.rb @@ -1,4 +1,5 @@ # frozen_string_literal: true + # # Cookbook Name:: opsworks_ruby # Spec:: shutdown diff --git a/spec/unit/recipes/undeploy_spec.rb b/spec/unit/recipes/undeploy_spec.rb index da014721..83dedb5d 100644 --- a/spec/unit/recipes/undeploy_spec.rb +++ b/spec/unit/recipes/undeploy_spec.rb @@ -1,4 +1,5 @@ # frozen_string_literal: true + # # Cookbook Name:: opsworks_ruby # Spec:: undeploy diff --git a/test/integration/all_options/serverspec/all_options_spec.rb b/test/integration/all_options/serverspec/all_options_spec.rb index fa63ede3..ff4907d5 100644 --- a/test/integration/all_options/serverspec/all_options_spec.rb +++ b/test/integration/all_options/serverspec/all_options_spec.rb @@ -1,4 +1,5 @@ # frozen_string_literal: true + require 'spec_helper' describe 'opsworks_ruby::setup' do diff --git a/test/integration/default/serverspec/default_spec.rb b/test/integration/default/serverspec/default_spec.rb index 07bcd013..9e80a711 100644 --- a/test/integration/default/serverspec/default_spec.rb +++ b/test/integration/default/serverspec/default_spec.rb @@ -1,4 +1,5 @@ # frozen_string_literal: true + require 'spec_helper' describe 'opsworks_ruby::setup' do @@ -29,6 +30,21 @@ describe 'opsworks_ruby::configure' do context 'webserver' do + describe file('/etc/logrotate.d/dummy_project-nginx-production') do + its(:content) do + should include '"/var/log/nginx/dummy-project.example.com.access.log" ' \ + '"/var/log/nginx/dummy-project.example.com.error.log" {' + end + its(:content) { should include ' daily' } + its(:content) { should include ' rotate 30' } + its(:content) { should include ' missingok' } + its(:content) { should include ' compress' } + its(:content) { should include ' delaycompress' } + its(:content) { should include ' notifempty' } + its(:content) { should include ' copytruncate' } + its(:content) { should include ' sharedscripts' } + end + describe file('/etc/nginx/ssl/dummy-project.example.com.key') do its(:content) { should include '-----BEGIN RSA PRIVATE KEY-----' } end @@ -68,6 +84,18 @@ end context 'framework' do + describe file('/etc/logrotate.d/dummy_project-rails-production') do + its(:content) { should include '"/srv/www/dummy_project/shared/log/production.log" {' } + its(:content) { should include ' daily' } + its(:content) { should include ' rotate 30' } + its(:content) { should include ' missingok' } + its(:content) { should include ' compress' } + its(:content) { should include ' delaycompress' } + its(:content) { should include ' notifempty' } + its(:content) { should include ' copytruncate' } + its(:content) { should include ' sharedscripts' } + end + describe file('/srv/www/dummy_project/current/config/database.yml') do its(:content) { should include 'adapter: sqlite3' } end diff --git a/test/integration/helpers/serverspec/spec_helper.rb b/test/integration/helpers/serverspec/spec_helper.rb index a536a0d7..0af9df37 100644 --- a/test/integration/helpers/serverspec/spec_helper.rb +++ b/test/integration/helpers/serverspec/spec_helper.rb @@ -1,4 +1,5 @@ # frozen_string_literal: true + require 'serverspec' if (/cygwin|mswin|mingw|bccwin|wince|emx/ =~ RUBY_PLATFORM).nil? diff --git a/test/integration/nullified/serverspec/nullified_spec.rb b/test/integration/nullified/serverspec/nullified_spec.rb index 3dde1521..08dd16fd 100644 --- a/test/integration/nullified/serverspec/nullified_spec.rb +++ b/test/integration/nullified/serverspec/nullified_spec.rb @@ -1,4 +1,5 @@ # frozen_string_literal: true + require 'spec_helper' describe 'opsworks_ruby::setup' do diff --git a/test/integration/thin_nginx_padrino_delayed_job/serverspec/thin_nginx_padrino_delayed_job_spec.rb b/test/integration/thin_nginx_padrino_delayed_job/serverspec/thin_nginx_padrino_delayed_job_spec.rb index 5639c88c..e5c44653 100644 --- a/test/integration/thin_nginx_padrino_delayed_job/serverspec/thin_nginx_padrino_delayed_job_spec.rb +++ b/test/integration/thin_nginx_padrino_delayed_job/serverspec/thin_nginx_padrino_delayed_job_spec.rb @@ -1,4 +1,5 @@ # frozen_string_literal: true + require 'spec_helper' describe 'opsworks_ruby::setup' do diff --git a/test/integration/unicorn_apache_hanami_resque/serverspec/unicorn_apache_hanami_resque_spec.rb b/test/integration/unicorn_apache_hanami_resque/serverspec/unicorn_apache_hanami_resque_spec.rb index 1d1cb871..7ac6671e 100644 --- a/test/integration/unicorn_apache_hanami_resque/serverspec/unicorn_apache_hanami_resque_spec.rb +++ b/test/integration/unicorn_apache_hanami_resque/serverspec/unicorn_apache_hanami_resque_spec.rb @@ -1,4 +1,5 @@ # frozen_string_literal: true + require 'spec_helper' describe 'opsworks_ruby::setup' do @@ -29,6 +30,21 @@ describe 'opsworks_ruby::configure' do context 'webserver' do + describe file('/etc/logrotate.d/dummy_project-apache2-production') do + its(:content) do + should include '"/var/log/apache2/dummy-project.example.com.access.log" ' \ + '"/var/log/apache2/dummy-project.example.com.error.log" {' + end + its(:content) { should include ' daily' } + its(:content) { should include ' rotate 30' } + its(:content) { should include ' missingok' } + its(:content) { should include ' compress' } + its(:content) { should include ' delaycompress' } + its(:content) { should include ' notifempty' } + its(:content) { should include ' copytruncate' } + its(:content) { should include ' sharedscripts' } + end + describe file('/etc/apache2/ssl/dummy-project.example.com.key') do its(:content) { should include '-----BEGIN RSA PRIVATE KEY-----' } end