From b3b1f1745c07569eddee031603351d40aa707e91 Mon Sep 17 00:00:00 2001 From: Dan Elbert Date: Mon, 18 Jan 2016 20:50:19 -0600 Subject: [PATCH] Added docker configs --- Dockerfile | 38 ++++++++++++++ Gemfile | 1 + Gemfile.lock | 2 + app/models/unit_conversion.rb | 3 +- config/database.yml | 18 ++++++- config/environments/docker.rb | 79 +++++++++++++++++++++++++++++ config/environments/production.rb | 2 +- config/secrets.yml | 3 ++ db/seeds.rb | 7 ++- docker-compose-rlyeh.yml | 9 ++++ docker-compose.yml | 17 +++++++ docker/nginx_env.conf | 5 ++ docker/nginx_server.conf | 15 ++++++ spec/models/unit_conversion_spec.rb | 3 +- 14 files changed, 196 insertions(+), 6 deletions(-) create mode 100644 Dockerfile create mode 100644 config/environments/docker.rb create mode 100644 docker-compose-rlyeh.yml create mode 100644 docker-compose.yml create mode 100644 docker/nginx_env.conf create mode 100644 docker/nginx_server.conf diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..e07bedc --- /dev/null +++ b/Dockerfile @@ -0,0 +1,38 @@ +FROM phusion/passenger-ruby22:latest + +# Use baseimage-docker's init process. +CMD ["/sbin/my_init"] + +# Enable Nginx / Passenger +RUN rm -f /etc/service/nginx/down + +# Install nginx config files +RUN rm /etc/nginx/sites-enabled/default +ADD docker/nginx_server.conf /etc/nginx/sites-enabled/parsley.conf +ADD docker/nginx_env.conf /etc/nginx/main.d/env.conf + +# Set Default RAILS_ENV +ENV PASSENGER_APP_ENV docker + +# Setup directory and install gems +RUN mkdir -p /home/app/parsley/ +COPY Gemfile /home/app/parsley/ +COPY Gemfile.lock /home/app/parsley/ +RUN cd /home/app/parsley/ && bundle install --deployment + +# Copy the app into the image +COPY . /home/app/parsley/ +WORKDIR /home/app/parsley/ + +# Set log permissions +RUN mkdir -p /home/app/parsley/log +RUN chmod 0777 /home/app/parsley/log + +# Compile assets +RUN env RAILS_ENV=production bundle exec rake assets:clobber assets:precompile + +# Set ownership of the tmp folder +RUN chown -R app:app /home/app/parsley/tmp + +# Clean up APT when done. +RUN apt-get clean && rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/* diff --git a/Gemfile b/Gemfile index a61a247..86c8b99 100644 --- a/Gemfile +++ b/Gemfile @@ -4,6 +4,7 @@ source 'https://rubygems.org' # Bundle edge Rails instead: gem 'rails', github: 'rails/rails' gem 'rails', '4.2.5' gem 'sqlite3' +gem 'mysql2', '~> 0.3.18' gem 'sass-rails', '~> 5.0' gem 'uglifier', '>= 1.3.0' diff --git a/Gemfile.lock b/Gemfile.lock index 372c90a..be65b38 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -90,6 +90,7 @@ GEM mini_portile2 (2.0.0) minitest (5.8.3) multi_json (1.11.2) + mysql2 (0.3.20) nokogiri (1.6.7.1) mini_portile2 (~> 2.0.0.rc2) parslet (1.7.1) @@ -191,6 +192,7 @@ DEPENDENCIES factory_girl_rails (~> 4.5.0) jbuilder (~> 2.0) jquery-rails + mysql2 (~> 0.3.18) rails (= 4.2.5) rspec-rails (~> 3.4.0) sass-rails (~> 5.0) diff --git a/app/models/unit_conversion.rb b/app/models/unit_conversion.rb index 6dbfd0a..4528003 100644 --- a/app/models/unit_conversion.rb +++ b/app/models/unit_conversion.rb @@ -16,7 +16,8 @@ module UnitConversion gallon: %w(gallons ga), gram: %w(grams g), - kilogram: %w(kilograms kg) + kilogram: %w(kilograms kg), + milliliter: %w(ml milliliters) } UNIT_ALIAS_MAP = Hash[UNIT_ALIASES.map { |unit, values| values.map { |v| [v, unit] } }.flatten(1)] diff --git a/config/database.yml b/config/database.yml index 1c1a37c..e826bac 100644 --- a/config/database.yml +++ b/config/database.yml @@ -19,7 +19,21 @@ development: test: <<: *default database: db/test.sqlite3 + +docker: + adapter: mysql2 + pool: 5 + timeout: 5000 + host: mysql + username: parsley + password: password + database: parsley production: - <<: *default - database: db/production.sqlite3 + adapter: mysql2 + pool: 5 + timeout: 5000 + host: <%= ENV['PARSLEY_DB_HOST'] || 'mysql' %> + username: <%= ENV['PARSLEY_DB_USER'] || 'parsley_user' %> + password: <%= ENV['PARSLEY_DB_PASSWORD'] || 'parsley_password' %> + database: <%= ENV['PARSLEY_DB_NAME'] || 'parsley' %> diff --git a/config/environments/docker.rb b/config/environments/docker.rb new file mode 100644 index 0000000..9d8e4de --- /dev/null +++ b/config/environments/docker.rb @@ -0,0 +1,79 @@ +Rails.application.configure do + # Settings specified here will take precedence over those in config/application.rb. + + # Code is not reloaded between requests. + config.cache_classes = true + + # Eager load code on boot. This eager loads most of Rails and + # your application in memory, allowing both threaded web servers + # and those relying on copy on write to perform better. + # Rake tasks automatically ignore this option for performance. + config.eager_load = true + + # Full error reports are disabled and caching is turned on. + config.consider_all_requests_local = false + config.action_controller.perform_caching = true + + # Enable Rack::Cache to put a simple HTTP cache in front of your application + # Add `rack-cache` to your Gemfile before enabling this. + # For large-scale production use, consider using a caching reverse proxy like + # NGINX, varnish or squid. + # config.action_dispatch.rack_cache = true + + # Disable serving static files from the `/public` folder by default since + # Apache or NGINX already handles this. + config.serve_static_files = ENV['RAILS_SERVE_STATIC_FILES'].present? + + # Compress JavaScripts and CSS. + config.assets.js_compressor = :uglifier + # config.assets.css_compressor = :sass + + # Do not fallback to assets pipeline if a precompiled asset is missed. + config.assets.compile = false + + # Asset digests allow you to set far-future HTTP expiration dates on all assets, + # yet still be able to expire them through the digest params. + config.assets.digest = true + + # `config.assets.precompile` and `config.assets.version` have moved to config/initializers/assets.rb + + # Specifies the header that your server uses for sending files. + # config.action_dispatch.x_sendfile_header = 'X-Sendfile' # for Apache + config.action_dispatch.x_sendfile_header = 'X-Accel-Redirect' # for NGINX + + # Force all access to the app over SSL, use Strict-Transport-Security, and use secure cookies. + # config.force_ssl = true + + # Use the lowest log level to ensure availability of diagnostic information + # when problems arise. + config.log_level = :debug + + # Prepend all log lines with the following tags. + # config.log_tags = [ :subdomain, :uuid ] + + # Use a different logger for distributed setups. + # config.logger = ActiveSupport::TaggedLogging.new(SyslogLogger.new) + + # Use a different cache store in production. + # config.cache_store = :mem_cache_store + + # Enable serving of images, stylesheets, and JavaScripts from an asset server. + # config.action_controller.asset_host = 'http://assets.example.com' + + # Ignore bad email addresses and do not raise email delivery errors. + # Set this to true and configure the email server for immediate delivery to raise delivery errors. + # config.action_mailer.raise_delivery_errors = false + + # Enable locale fallbacks for I18n (makes lookups for any locale fall back to + # the I18n.default_locale when a translation cannot be found). + config.i18n.fallbacks = true + + # Send deprecation notices to registered listeners. + config.active_support.deprecation = :notify + + # Use default logging formatter so that PID and timestamp are not suppressed. + config.log_formatter = ::Logger::Formatter.new + + # Do not dump schema after migrations. + config.active_record.dump_schema_after_migration = false +end diff --git a/config/environments/production.rb b/config/environments/production.rb index 5c1b32e..9d8e4de 100644 --- a/config/environments/production.rb +++ b/config/environments/production.rb @@ -39,7 +39,7 @@ Rails.application.configure do # Specifies the header that your server uses for sending files. # config.action_dispatch.x_sendfile_header = 'X-Sendfile' # for Apache - # config.action_dispatch.x_sendfile_header = 'X-Accel-Redirect' # for NGINX + config.action_dispatch.x_sendfile_header = 'X-Accel-Redirect' # for NGINX # Force all access to the app over SSL, use Strict-Transport-Security, and use secure cookies. # config.force_ssl = true diff --git a/config/secrets.yml b/config/secrets.yml index 114bedc..817111f 100644 --- a/config/secrets.yml +++ b/config/secrets.yml @@ -16,6 +16,9 @@ development: test: secret_key_base: 1cf4b0a7e92c645ce88bc6909fa66ad706a7b4d8dcfc6c80a472b309cb1c745dead17d3c633ae971da164b7b82555a8f33033229f598b72a35b74ae199cc93e0 +docker: + secret_key_base: 2076eaf1e343d03eb0cc8477c17ba17ba50dd664acb730b0531c9a5fd73fd42e8b979ca887ad78a14b0ea0828e2abc9b205ab82d0252cec6382d397e3c879754 + # Do not keep production secrets in the repository, # instead read values from the environment. production: diff --git a/db/seeds.rb b/db/seeds.rb index 0b4187a..c602b78 100644 --- a/db/seeds.rb +++ b/db/seeds.rb @@ -22,7 +22,12 @@ Ingredient.create!([ {name: 'Sugar, Brown, Lightly Packed', density: '210 gram/cup'}, {name: 'Sugar, Powdered', density: '120 gram/cup'}, {name: 'Chocolate Chips', density: '170 gram/cup'}, - {name: 'Cocoa Powder', density: '100 gram/cup'} + {name: 'Cocoa Powder', density: '100 gram/cup'}, + {name: 'Salt, Kosher', density: '248 gram/cup'}, + {name: 'Salt, Table', density: '304 gram/cup'}, + {name: 'Milk, Whole', density: '1.028 gram/ml'}, + {name: 'Milk, Skim', density: '1.032 gram/ml'}, + {name: 'Milk, 2%', density: '1.03 gram/ml'} ]) diff --git a/docker-compose-rlyeh.yml b/docker-compose-rlyeh.yml new file mode 100644 index 0000000..e2bcdf8 --- /dev/null +++ b/docker-compose-rlyeh.yml @@ -0,0 +1,9 @@ +web: + image: danelbert/parsley:production + ports: + - "7000:80" + environment: + - PASSENGER_APP_ENV=production + env_file: /etc/default/parsley + volumes: + - /var/log/parsley/:/home/app/parsley/log \ No newline at end of file diff --git a/docker-compose.yml b/docker-compose.yml new file mode 100644 index 0000000..8d9c6d2 --- /dev/null +++ b/docker-compose.yml @@ -0,0 +1,17 @@ +mysql: + image: mysql:5.6 + environment: + - MYSQL_ROOT_PASSWORD=mysupersecret + - MYSQL_DATABASE=parsley + - MYSQL_USER=parsley + - MYSQL_PASSWORD=password + volumes_from: + - parsley_db_data + + +web: + build: . + ports: + - "3000:80" + links: + - mysql \ No newline at end of file diff --git a/docker/nginx_env.conf b/docker/nginx_env.conf new file mode 100644 index 0000000..2cfb9cf --- /dev/null +++ b/docker/nginx_env.conf @@ -0,0 +1,5 @@ +env PARSLEY_DB_HOST; +env PARSLEY_DB_USER; +env PARSLEY_DB_PASSWORD; +env PARSLEY_DB_NAME; +env SECRET_KEY_BASE; \ No newline at end of file diff --git a/docker/nginx_server.conf b/docker/nginx_server.conf new file mode 100644 index 0000000..8570cca --- /dev/null +++ b/docker/nginx_server.conf @@ -0,0 +1,15 @@ +server { + listen 80; + root /home/app/parsley/public; + + passenger_enabled on; + passenger_user app; + + passenger_ruby /usr/bin/ruby2.2; + + location ~ ^/(assets)/ { + gzip_static on; + expires max; + add_header Cache-Control public; + } +} \ No newline at end of file diff --git a/spec/models/unit_conversion_spec.rb b/spec/models/unit_conversion_spec.rb index a00f6cc..ba601a7 100644 --- a/spec/models/unit_conversion_spec.rb +++ b/spec/models/unit_conversion_spec.rb @@ -75,7 +75,8 @@ RSpec.describe UnitConversion do '223 g/c' => Unitwise(223, 'gram/cup'), '1/3 c' => Unitwise("1/3".to_r, 'cup'), '-5/16 g' => Unitwise("-5/16".to_r, 'gram'), - '2 1/2 c' => Unitwise("5/2".to_r, 'cup') + '2 1/2 c' => Unitwise("5/2".to_r, 'cup'), + '1.03 gram/ml' => Unitwise(1.03, 'gram/milliliter') } data.each do |input, output|