Added docker configs

This commit is contained in:
Dan Elbert 2016-01-18 20:50:19 -06:00
parent d46b26fcf5
commit b3b1f1745c
14 changed files with 196 additions and 6 deletions

38
Dockerfile Normal file
View File

@ -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/*

View File

@ -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'

View File

@ -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)

View File

@ -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)]

View File

@ -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' %>

View File

@ -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

View File

@ -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

View File

@ -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:

View File

@ -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'}
])

9
docker-compose-rlyeh.yml Normal file
View File

@ -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

17
docker-compose.yml Normal file
View File

@ -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

5
docker/nginx_env.conf Normal file
View File

@ -0,0 +1,5 @@
env PARSLEY_DB_HOST;
env PARSLEY_DB_USER;
env PARSLEY_DB_PASSWORD;
env PARSLEY_DB_NAME;
env SECRET_KEY_BASE;

15
docker/nginx_server.conf Normal file
View File

@ -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;
}
}

View File

@ -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|