├── 9781484224144.jpg ├── LICENSE.txt ├── README.md ├── contributing.md └── webapp ├── .dockerignore ├── Dockerfile ├── Gemfile ├── Gemfile.lock ├── README.md ├── Rakefile ├── app ├── channels │ └── application_cable │ │ ├── channel.rb │ │ └── connection.rb ├── controllers │ ├── application_controller.rb │ ├── articles_controller.rb │ ├── concerns │ │ └── .keep │ └── pages_controller.rb ├── jobs │ └── application_job.rb ├── mailers │ └── application_mailer.rb ├── models │ ├── application_record.rb │ ├── article.rb │ └── concerns │ │ └── .keep └── views │ └── layouts │ ├── mailer.html.erb │ └── mailer.text.erb ├── bin ├── bundle ├── rails ├── rake ├── setup └── update ├── config.ru ├── config ├── application.rb ├── boot.rb ├── cable.yml ├── database.yml ├── environment.rb ├── environments │ ├── development.rb │ ├── production.rb │ └── test.rb ├── initializers │ ├── application_controller_renderer.rb │ ├── backtrace_silencers.rb │ ├── cors.rb │ ├── filter_parameter_logging.rb │ ├── inflections.rb │ ├── mime_types.rb │ ├── new_framework_defaults.rb │ └── wrap_parameters.rb ├── locales │ └── en.yml ├── puma.rb ├── routes.rb ├── secrets.yml └── spring.rb ├── db ├── migrate │ ├── 20160925220117_create_articles.rb │ └── 20160928030155_add_slug_to_articles.rb ├── schema.rb └── seeds.rb ├── deploy ├── migrate.sh └── push.sh ├── docker-compose.test.yml ├── docker-compose.yml ├── ecs ├── deploy │ ├── migrate.sh │ └── push.sh ├── services │ └── webapp-service.json └── task-definitions │ ├── migrate-overrides.json │ └── webapp.json ├── kube ├── deployments │ ├── postgres-deployment.yaml │ └── webapp-deployment.yaml ├── jobs │ └── setup-job.yaml └── minikube │ └── deployments │ ├── postgres-deployment.yaml │ └── webapp-deployment.yaml ├── lib └── tasks │ └── .keep ├── log ├── .keep ├── development.log └── test.log ├── public └── robots.txt ├── rails-env.conf ├── setup.production.sh ├── setup.sh ├── setup.test.sh ├── test ├── controllers │ ├── .keep │ └── articles_controller_test.rb ├── fixtures │ ├── .keep │ ├── articles.yml │ └── files │ │ └── .keep ├── integration │ └── .keep ├── mailers │ └── .keep ├── models │ ├── .keep │ └── article_test.rb └── test_helper.rb ├── tmp └── .keep └── webapp.conf /9781484224144.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Apress/deploying-rails-w-docker/212bac6ddf03f6c710134c2b6333ee314124ddcf/9781484224144.jpg -------------------------------------------------------------------------------- /LICENSE.txt: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Apress/deploying-rails-w-docker/212bac6ddf03f6c710134c2b6333ee314124ddcf/LICENSE.txt -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Apress/deploying-rails-w-docker/212bac6ddf03f6c710134c2b6333ee314124ddcf/README.md -------------------------------------------------------------------------------- /contributing.md: -------------------------------------------------------------------------------- 1 | # Contributing to Apress Source Code 2 | 3 | Copyright for Apress source code belongs to the author(s). However, under fair use you are encouraged to fork and contribute minor corrections and updates for the benefit of the author(s) and other readers. 4 | 5 | ## How to Contribute 6 | 7 | 1. Make sure you have a GitHub account. 8 | 2. Fork the repository for the relevant book. 9 | 3. Create a new branch on which to make your change, e.g. 10 | `git checkout -b my_code_contribution` 11 | 4. Commit your change. Include a commit message describing the correction. Please note that if your commit message is not clear, the correction will not be accepted. 12 | 5. Submit a pull request. 13 | 14 | Thank you for your contribution! -------------------------------------------------------------------------------- /webapp/.dockerignore: -------------------------------------------------------------------------------- 1 | # Ignore bundler config. 2 | /.bundle 3 | 4 | # Ignore all logfiles and tempfiles. 5 | /log/* 6 | /tmp/* 7 | !/log/.keep 8 | !/tmp/.keep 9 | 10 | # Ignore Byebug command history file. 11 | .byebug_history 12 | -------------------------------------------------------------------------------- /webapp/Dockerfile: -------------------------------------------------------------------------------- 1 | FROM phusion/passenger-ruby23:0.9.19 2 | 3 | # Set correct environment variables. 4 | ENV HOME /root 5 | 6 | # Use baseimage-docker's init process. 7 | CMD ["/sbin/my_init"] 8 | 9 | # Additional packages: we are adding the netcat package so we can 10 | # make pings to the database service 11 | RUN apt-get update && apt-get install -y -o Dpkg::Options::="--force-confold" netcat 12 | 13 | # Enable Nginx and Passenger 14 | RUN rm -f /etc/service/nginx/down 15 | 16 | # Add virtual host entry for the application. Make sure 17 | # the file is in the correct path 18 | RUN rm /etc/nginx/sites-enabled/default 19 | ADD webapp.conf /etc/nginx/sites-enabled/webapp.conf 20 | 21 | # In case we need some environmental variables in Nginx. Make sure 22 | # the file is in the correct path 23 | ADD rails-env.conf /etc/nginx/main.d/rails-env.conf 24 | 25 | # Install gems: it's better to build an independent layer for the gems 26 | # so they are cached during builds unless Gemfile changes 27 | WORKDIR /tmp 28 | ADD Gemfile /tmp/ 29 | ADD Gemfile.lock /tmp/ 30 | RUN bundle install 31 | 32 | # Copy application into the container and use right permissions: passenger 33 | # uses the app user for running the application 34 | RUN mkdir /home/app/webapp 35 | COPY . /home/app/webapp 36 | RUN usermod -u 1000 app 37 | RUN chown -R app:app /home/app/webapp 38 | WORKDIR /home/app/webapp 39 | 40 | 41 | # Clean up APT when done. 42 | RUN apt-get clean && rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/* 43 | 44 | EXPOSE 80 45 | -------------------------------------------------------------------------------- /webapp/Gemfile: -------------------------------------------------------------------------------- 1 | source 'https://rubygems.org' 2 | 3 | 4 | # Bundle edge Rails instead: gem 'rails', github: 'rails/rails' 5 | gem 'rails', '~> 5.0.0', '>= 5.0.0.1' 6 | # Use postgresql as the database for Active Record 7 | gem 'pg', '~> 0.18' 8 | # Use Puma as the app server 9 | gem 'puma', '~> 3.0' 10 | # Build JSON APIs with ease. Read more: https://github.com/rails/jbuilder 11 | # gem 'jbuilder', '~> 2.5' 12 | # Use Redis adapter to run Action Cable in production 13 | # gem 'redis', '~> 3.0' 14 | # Use ActiveModel has_secure_password 15 | # gem 'bcrypt', '~> 3.1.7' 16 | 17 | # Use Capistrano for deployment 18 | # gem 'capistrano-rails', group: :development 19 | 20 | # Use Rack CORS for handling Cross-Origin Resource Sharing (CORS), making cross-origin AJAX possible 21 | # gem 'rack-cors' 22 | 23 | group :development, :test do 24 | # Call 'byebug' anywhere in the code to stop execution and get a debugger console 25 | gem 'byebug', platform: :mri 26 | end 27 | 28 | group :development do 29 | gem 'listen', '~> 3.0.5' 30 | # Spring speeds up development by keeping your application running in the background. Read more: https://github.com/rails/spring 31 | gem 'spring' 32 | gem 'spring-watcher-listen', '~> 2.0.0' 33 | end 34 | 35 | # Windows does not include zoneinfo files, so bundle the tzinfo-data gem 36 | gem 'tzinfo-data', platforms: [:mingw, :mswin, :x64_mingw, :jruby] 37 | -------------------------------------------------------------------------------- /webapp/Gemfile.lock: -------------------------------------------------------------------------------- 1 | GEM 2 | remote: https://rubygems.org/ 3 | specs: 4 | actioncable (5.0.0.1) 5 | actionpack (= 5.0.0.1) 6 | nio4r (~> 1.2) 7 | websocket-driver (~> 0.6.1) 8 | actionmailer (5.0.0.1) 9 | actionpack (= 5.0.0.1) 10 | actionview (= 5.0.0.1) 11 | activejob (= 5.0.0.1) 12 | mail (~> 2.5, >= 2.5.4) 13 | rails-dom-testing (~> 2.0) 14 | actionpack (5.0.0.1) 15 | actionview (= 5.0.0.1) 16 | activesupport (= 5.0.0.1) 17 | rack (~> 2.0) 18 | rack-test (~> 0.6.3) 19 | rails-dom-testing (~> 2.0) 20 | rails-html-sanitizer (~> 1.0, >= 1.0.2) 21 | actionview (5.0.0.1) 22 | activesupport (= 5.0.0.1) 23 | builder (~> 3.1) 24 | erubis (~> 2.7.0) 25 | rails-dom-testing (~> 2.0) 26 | rails-html-sanitizer (~> 1.0, >= 1.0.2) 27 | activejob (5.0.0.1) 28 | activesupport (= 5.0.0.1) 29 | globalid (>= 0.3.6) 30 | activemodel (5.0.0.1) 31 | activesupport (= 5.0.0.1) 32 | activerecord (5.0.0.1) 33 | activemodel (= 5.0.0.1) 34 | activesupport (= 5.0.0.1) 35 | arel (~> 7.0) 36 | activesupport (5.0.0.1) 37 | concurrent-ruby (~> 1.0, >= 1.0.2) 38 | i18n (~> 0.7) 39 | minitest (~> 5.1) 40 | tzinfo (~> 1.1) 41 | arel (7.1.2) 42 | builder (3.2.2) 43 | byebug (9.0.5) 44 | concurrent-ruby (1.0.2) 45 | erubis (2.7.0) 46 | ffi (1.9.14) 47 | globalid (0.3.7) 48 | activesupport (>= 4.1.0) 49 | i18n (0.7.0) 50 | listen (3.0.8) 51 | rb-fsevent (~> 0.9, >= 0.9.4) 52 | rb-inotify (~> 0.9, >= 0.9.7) 53 | loofah (2.0.3) 54 | nokogiri (>= 1.5.9) 55 | mail (2.6.4) 56 | mime-types (>= 1.16, < 4) 57 | method_source (0.8.2) 58 | mime-types (3.1) 59 | mime-types-data (~> 3.2015) 60 | mime-types-data (3.2016.0521) 61 | mini_portile2 (2.1.0) 62 | minitest (5.9.0) 63 | nio4r (1.2.1) 64 | nokogiri (1.6.8) 65 | mini_portile2 (~> 2.1.0) 66 | pkg-config (~> 1.1.7) 67 | pg (0.19.0) 68 | pkg-config (1.1.7) 69 | puma (3.6.0) 70 | rack (2.0.1) 71 | rack-test (0.6.3) 72 | rack (>= 1.0) 73 | rails (5.0.0.1) 74 | actioncable (= 5.0.0.1) 75 | actionmailer (= 5.0.0.1) 76 | actionpack (= 5.0.0.1) 77 | actionview (= 5.0.0.1) 78 | activejob (= 5.0.0.1) 79 | activemodel (= 5.0.0.1) 80 | activerecord (= 5.0.0.1) 81 | activesupport (= 5.0.0.1) 82 | bundler (>= 1.3.0, < 2.0) 83 | railties (= 5.0.0.1) 84 | sprockets-rails (>= 2.0.0) 85 | rails-dom-testing (2.0.1) 86 | activesupport (>= 4.2.0, < 6.0) 87 | nokogiri (~> 1.6.0) 88 | rails-html-sanitizer (1.0.3) 89 | loofah (~> 2.0) 90 | railties (5.0.0.1) 91 | actionpack (= 5.0.0.1) 92 | activesupport (= 5.0.0.1) 93 | method_source 94 | rake (>= 0.8.7) 95 | thor (>= 0.18.1, < 2.0) 96 | rake (11.3.0) 97 | rb-fsevent (0.9.7) 98 | rb-inotify (0.9.7) 99 | ffi (>= 0.5.0) 100 | spring (1.7.2) 101 | spring-watcher-listen (2.0.0) 102 | listen (>= 2.7, < 4.0) 103 | spring (~> 1.2) 104 | sprockets (3.7.0) 105 | concurrent-ruby (~> 1.0) 106 | rack (> 1, < 3) 107 | sprockets-rails (3.2.0) 108 | actionpack (>= 4.0) 109 | activesupport (>= 4.0) 110 | sprockets (>= 3.0.0) 111 | thor (0.19.1) 112 | thread_safe (0.3.5) 113 | tzinfo (1.2.2) 114 | thread_safe (~> 0.1) 115 | websocket-driver (0.6.4) 116 | websocket-extensions (>= 0.1.0) 117 | websocket-extensions (0.1.2) 118 | 119 | PLATFORMS 120 | ruby 121 | 122 | DEPENDENCIES 123 | byebug 124 | listen (~> 3.0.5) 125 | pg (~> 0.18) 126 | puma (~> 3.0) 127 | rails (~> 5.0.0, >= 5.0.0.1) 128 | spring 129 | spring-watcher-listen (~> 2.0.0) 130 | tzinfo-data 131 | 132 | BUNDLED WITH 133 | 1.13.1 134 | -------------------------------------------------------------------------------- /webapp/README.md: -------------------------------------------------------------------------------- 1 | # README 2 | 3 | TODO 4 | -------------------------------------------------------------------------------- /webapp/Rakefile: -------------------------------------------------------------------------------- 1 | # Add your own tasks in files placed in lib/tasks ending in .rake, 2 | # for example lib/tasks/capistrano.rake, and they will automatically be available to Rake. 3 | 4 | require_relative 'config/application' 5 | 6 | Rails.application.load_tasks 7 | -------------------------------------------------------------------------------- /webapp/app/channels/application_cable/channel.rb: -------------------------------------------------------------------------------- 1 | module ApplicationCable 2 | class Channel < ActionCable::Channel::Base 3 | end 4 | end 5 | -------------------------------------------------------------------------------- /webapp/app/channels/application_cable/connection.rb: -------------------------------------------------------------------------------- 1 | module ApplicationCable 2 | class Connection < ActionCable::Connection::Base 3 | end 4 | end 5 | -------------------------------------------------------------------------------- /webapp/app/controllers/application_controller.rb: -------------------------------------------------------------------------------- 1 | class ApplicationController < ActionController::API 2 | end 3 | -------------------------------------------------------------------------------- /webapp/app/controllers/articles_controller.rb: -------------------------------------------------------------------------------- 1 | class ArticlesController < ApplicationController 2 | before_action :set_article, only: [:show, :update, :destroy] 3 | 4 | # GET /articles 5 | def index 6 | @articles = Article.all 7 | 8 | render json: @articles 9 | end 10 | 11 | # GET /articles/1 12 | def show 13 | render json: @article 14 | end 15 | 16 | # POST /articles 17 | def create 18 | @article = Article.new(article_params) 19 | @article.slug = @article.title.parameterize 20 | 21 | if @article.save 22 | render json: @article, status: :created, location: @article 23 | else 24 | render json: @article.errors, status: :unprocessable_entity 25 | end 26 | end 27 | 28 | # PATCH/PUT /articles/1 29 | def update 30 | if @article.update(article_params) 31 | render json: @article 32 | else 33 | render json: @article.errors, status: :unprocessable_entity 34 | end 35 | end 36 | 37 | # DELETE /articles/1 38 | def destroy 39 | @article.destroy 40 | end 41 | 42 | private 43 | # Use callbacks to share common setup or constraints between actions. 44 | def set_article 45 | @article = Article.find(params[:id]) 46 | end 47 | 48 | # Only allow a trusted parameter "white list" through. 49 | def article_params 50 | params.require(:article).permit(:title, :body) 51 | end 52 | end 53 | -------------------------------------------------------------------------------- /webapp/app/controllers/concerns/.keep: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Apress/deploying-rails-w-docker/212bac6ddf03f6c710134c2b6333ee314124ddcf/webapp/app/controllers/concerns/.keep -------------------------------------------------------------------------------- /webapp/app/controllers/pages_controller.rb: -------------------------------------------------------------------------------- 1 | class PagesController < ApplicationController 2 | def welcome 3 | render json: {message: 'hello!'}, status: 200 4 | end 5 | end 6 | -------------------------------------------------------------------------------- /webapp/app/jobs/application_job.rb: -------------------------------------------------------------------------------- 1 | class ApplicationJob < ActiveJob::Base 2 | end 3 | -------------------------------------------------------------------------------- /webapp/app/mailers/application_mailer.rb: -------------------------------------------------------------------------------- 1 | class ApplicationMailer < ActionMailer::Base 2 | default from: 'from@example.com' 3 | layout 'mailer' 4 | end 5 | -------------------------------------------------------------------------------- /webapp/app/models/application_record.rb: -------------------------------------------------------------------------------- 1 | class ApplicationRecord < ActiveRecord::Base 2 | self.abstract_class = true 3 | end 4 | -------------------------------------------------------------------------------- /webapp/app/models/article.rb: -------------------------------------------------------------------------------- 1 | class Article < ApplicationRecord 2 | end 3 | -------------------------------------------------------------------------------- /webapp/app/models/concerns/.keep: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Apress/deploying-rails-w-docker/212bac6ddf03f6c710134c2b6333ee314124ddcf/webapp/app/models/concerns/.keep -------------------------------------------------------------------------------- /webapp/app/views/layouts/mailer.html.erb: -------------------------------------------------------------------------------- 1 | 2 | 3 |
4 | 5 | 8 | 9 | 10 | 11 | <%= yield %> 12 | 13 | 14 | -------------------------------------------------------------------------------- /webapp/app/views/layouts/mailer.text.erb: -------------------------------------------------------------------------------- 1 | <%= yield %> 2 | -------------------------------------------------------------------------------- /webapp/bin/bundle: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env ruby 2 | ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../../Gemfile', __FILE__) 3 | load Gem.bin_path('bundler', 'bundle') 4 | -------------------------------------------------------------------------------- /webapp/bin/rails: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env ruby 2 | APP_PATH = File.expand_path('../config/application', __dir__) 3 | require_relative '../config/boot' 4 | require 'rails/commands' 5 | -------------------------------------------------------------------------------- /webapp/bin/rake: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env ruby 2 | require_relative '../config/boot' 3 | require 'rake' 4 | Rake.application.run 5 | -------------------------------------------------------------------------------- /webapp/bin/setup: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env ruby 2 | require 'pathname' 3 | require 'fileutils' 4 | include FileUtils 5 | 6 | # path to your application root. 7 | APP_ROOT = Pathname.new File.expand_path('../../', __FILE__) 8 | 9 | def system!(*args) 10 | system(*args) || abort("\n== Command #{args} failed ==") 11 | end 12 | 13 | chdir APP_ROOT do 14 | # This script is a starting point to setup your application. 15 | # Add necessary setup steps to this file. 16 | 17 | puts '== Installing dependencies ==' 18 | system! 'gem install bundler --conservative' 19 | system('bundle check') || system!('bundle install') 20 | 21 | # puts "\n== Copying sample files ==" 22 | # unless File.exist?('config/database.yml') 23 | # cp 'config/database.yml.sample', 'config/database.yml' 24 | # end 25 | 26 | puts "\n== Preparing database ==" 27 | system! 'bin/rails db:setup' 28 | 29 | puts "\n== Removing old logs and tempfiles ==" 30 | system! 'bin/rails log:clear tmp:clear' 31 | 32 | puts "\n== Restarting application server ==" 33 | system! 'bin/rails restart' 34 | end 35 | -------------------------------------------------------------------------------- /webapp/bin/update: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env ruby 2 | require 'pathname' 3 | require 'fileutils' 4 | include FileUtils 5 | 6 | # path to your application root. 7 | APP_ROOT = Pathname.new File.expand_path('../../', __FILE__) 8 | 9 | def system!(*args) 10 | system(*args) || abort("\n== Command #{args} failed ==") 11 | end 12 | 13 | chdir APP_ROOT do 14 | # This script is a way to update your development environment automatically. 15 | # Add necessary update steps to this file. 16 | 17 | puts '== Installing dependencies ==' 18 | system! 'gem install bundler --conservative' 19 | system('bundle check') || system!('bundle install') 20 | 21 | puts "\n== Updating database ==" 22 | system! 'bin/rails db:migrate' 23 | 24 | puts "\n== Removing old logs and tempfiles ==" 25 | system! 'bin/rails log:clear tmp:clear' 26 | 27 | puts "\n== Restarting application server ==" 28 | system! 'bin/rails restart' 29 | end 30 | -------------------------------------------------------------------------------- /webapp/config.ru: -------------------------------------------------------------------------------- 1 | # This file is used by Rack-based servers to start the application. 2 | 3 | require_relative 'config/environment' 4 | 5 | run Rails.application 6 | -------------------------------------------------------------------------------- /webapp/config/application.rb: -------------------------------------------------------------------------------- 1 | require_relative 'boot' 2 | 3 | require "rails" 4 | # Pick the frameworks you want: 5 | require "active_model/railtie" 6 | require "active_job/railtie" 7 | require "active_record/railtie" 8 | require "action_controller/railtie" 9 | require "action_mailer/railtie" 10 | require "action_view/railtie" 11 | require "action_cable/engine" 12 | # require "sprockets/railtie" 13 | require "rails/test_unit/railtie" 14 | 15 | # Require the gems listed in Gemfile, including any gems 16 | # you've limited to :test, :development, or :production. 17 | Bundler.require(*Rails.groups) 18 | 19 | module Webapp 20 | class Application < Rails::Application 21 | # Settings in config/environments/* take precedence over those specified here. 22 | # Application configuration should go into files in config/initializers 23 | # -- all .rb files in that directory are automatically loaded. 24 | 25 | # Only loads a smaller set of middleware suitable for API only apps. 26 | # Middleware like session, flash, cookies can be added back manually. 27 | # Skip views, helpers and assets when generating a new resource. 28 | config.api_only = true 29 | config.logger = Logger.new(STDOUT) 30 | end 31 | end 32 | -------------------------------------------------------------------------------- /webapp/config/boot.rb: -------------------------------------------------------------------------------- 1 | ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../Gemfile', __dir__) 2 | 3 | require 'bundler/setup' # Set up gems listed in the Gemfile. 4 | -------------------------------------------------------------------------------- /webapp/config/cable.yml: -------------------------------------------------------------------------------- 1 | development: 2 | adapter: async 3 | 4 | test: 5 | adapter: async 6 | 7 | production: 8 | adapter: redis 9 | url: redis://localhost:6379/1 10 | -------------------------------------------------------------------------------- /webapp/config/database.yml: -------------------------------------------------------------------------------- 1 | # PostgreSQL. Versions 9.1 and up are supported. 2 | # 3 | # Install the pg driver: 4 | # gem install pg 5 | # On OS X with Homebrew: 6 | # gem install pg -- --with-pg-config=/usr/local/bin/pg_config 7 | # On OS X with MacPorts: 8 | # gem install pg -- --with-pg-config=/opt/local/lib/postgresql84/bin/pg_config 9 | # On Windows: 10 | # gem install pg 11 | # Choose the win32 build. 12 | # Install PostgreSQL and put its /bin directory on your path. 13 | # 14 | # Configure Using Gemfile 15 | # gem 'pg' 16 | # 17 | default: &default 18 | adapter: postgresql 19 | encoding: unicode 20 | user: webapp 21 | password: mysecretpassword 22 | host: postgres 23 | pool: <%= ENV.fetch("RAILS_MAX_THREADS") { 5 } %> 24 | 25 | development: 26 | <<: *default 27 | database: webapp_development 28 | 29 | # The specified database role being used to connect to postgres. 30 | # To create additional roles in postgres see `$ createuser --help`. 31 | # When left blank, postgres will use the default role. This is 32 | # the same name as the operating system user that initialized the database. 33 | #username: webapp 34 | 35 | # The password associated with the postgres role (username). 36 | #password: 37 | 38 | # Connect on a TCP socket. Omitted by default since the client uses a 39 | # domain socket that doesn't need configuration. Windows does not have 40 | # domain sockets, so uncomment these lines. 41 | #host: localhost 42 | 43 | # The TCP port the server listens on. Defaults to 5432. 44 | # If your server runs on a different port number, change accordingly. 45 | #port: 5432 46 | 47 | # Schema search path. The server defaults to $user,public 48 | #schema_search_path: myapp,sharedapp,public 49 | 50 | # Minimum log levels, in increasing order: 51 | # debug5, debug4, debug3, debug2, debug1, 52 | # log, notice, warning, error, fatal, and panic 53 | # Defaults to warning. 54 | #min_messages: notice 55 | 56 | # Warning: The database defined as "test" will be erased and 57 | # re-generated from your development database when you run "rake". 58 | # Do not set this db to the same as development or production. 59 | test: 60 | <<: *default 61 | database: webapp_test 62 | 63 | # As with config/secrets.yml, you never want to store sensitive information, 64 | # like your database password, in your source code. If your source code is 65 | # ever seen by anyone, they now have access to your database. 66 | # 67 | # Instead, provide the password as a unix environment variable when you boot 68 | # the app. Read http://guides.rubyonrails.org/configuring.html#configuring-a-database 69 | # for a full rundown on how to provide these environment variables in a 70 | # production deployment. 71 | # 72 | # On Heroku and other platform providers, you may have a full connection URL 73 | # available as an environment variable. For example: 74 | # 75 | # DATABASE_URL="postgres://myuser:mypass@localhost/somedatabase" 76 | # 77 | # You can use this database configuration with: 78 | # 79 | # production: 80 | # url: <%= ENV['DATABASE_URL'] %> 81 | # 82 | production: 83 | <<: *default 84 | # host: use postgres for k8s, and the ELB dns name with ECS 85 | host: postgres 86 | database: webapp_production 87 | username: webapp 88 | password: mysecretpassword 89 | -------------------------------------------------------------------------------- /webapp/config/environment.rb: -------------------------------------------------------------------------------- 1 | # Load the Rails application. 2 | require_relative 'application' 3 | 4 | # Initialize the Rails application. 5 | Rails.application.initialize! 6 | -------------------------------------------------------------------------------- /webapp/config/environments/development.rb: -------------------------------------------------------------------------------- 1 | Rails.application.configure do 2 | # Settings specified here will take precedence over those in config/application.rb. 3 | 4 | # In the development environment your application's code is reloaded on 5 | # every request. This slows down response time but is perfect for development 6 | # since you don't have to restart the web server when you make code changes. 7 | config.cache_classes = false 8 | 9 | # Do not eager load code on boot. 10 | config.eager_load = false 11 | 12 | # Show full error reports. 13 | config.consider_all_requests_local = true 14 | 15 | # Enable/disable caching. By default caching is disabled. 16 | if Rails.root.join('tmp/caching-dev.txt').exist? 17 | config.action_controller.perform_caching = true 18 | 19 | config.cache_store = :memory_store 20 | config.public_file_server.headers = { 21 | 'Cache-Control' => 'public, max-age=172800' 22 | } 23 | else 24 | config.action_controller.perform_caching = false 25 | 26 | config.cache_store = :null_store 27 | end 28 | 29 | # Don't care if the mailer can't send. 30 | config.action_mailer.raise_delivery_errors = false 31 | 32 | config.action_mailer.perform_caching = false 33 | 34 | # Print deprecation notices to the Rails logger. 35 | config.active_support.deprecation = :log 36 | 37 | # Raise an error on page load if there are pending migrations. 38 | config.active_record.migration_error = :page_load 39 | 40 | 41 | # Raises error for missing translations 42 | # config.action_view.raise_on_missing_translations = true 43 | 44 | # Use an evented file watcher to asynchronously detect changes in source code, 45 | # routes, locales, etc. This feature depends on the listen gem. 46 | config.file_watcher = ActiveSupport::EventedFileUpdateChecker 47 | end 48 | -------------------------------------------------------------------------------- /webapp/config/environments/production.rb: -------------------------------------------------------------------------------- 1 | Rails.application.configure do 2 | # Settings specified here will take precedence over those in config/application.rb. 3 | 4 | # Code is not reloaded between requests. 5 | config.cache_classes = true 6 | 7 | # Eager load code on boot. This eager loads most of Rails and 8 | # your application in memory, allowing both threaded web servers 9 | # and those relying on copy on write to perform better. 10 | # Rake tasks automatically ignore this option for performance. 11 | config.eager_load = true 12 | 13 | # Full error reports are disabled and caching is turned on. 14 | config.consider_all_requests_local = false 15 | config.action_controller.perform_caching = true 16 | 17 | # Disable serving static files from the `/public` folder by default since 18 | # Apache or NGINX already handles this. 19 | config.public_file_server.enabled = ENV['RAILS_SERVE_STATIC_FILES'].present? 20 | 21 | 22 | # Enable serving of images, stylesheets, and JavaScripts from an asset server. 23 | # config.action_controller.asset_host = 'http://assets.example.com' 24 | 25 | # Specifies the header that your server uses for sending files. 26 | # config.action_dispatch.x_sendfile_header = 'X-Sendfile' # for Apache 27 | # config.action_dispatch.x_sendfile_header = 'X-Accel-Redirect' # for NGINX 28 | 29 | # Mount Action Cable outside main process or domain 30 | # config.action_cable.mount_path = nil 31 | # config.action_cable.url = 'wss://example.com/cable' 32 | # config.action_cable.allowed_request_origins = [ 'http://example.com', /http:\/\/example.*/ ] 33 | 34 | # Force all access to the app over SSL, use Strict-Transport-Security, and use secure cookies. 35 | # config.force_ssl = true 36 | 37 | # Use the lowest log level to ensure availability of diagnostic information 38 | # when problems arise. 39 | config.log_level = :debug 40 | 41 | # Prepend all log lines with the following tags. 42 | config.log_tags = [ :request_id ] 43 | 44 | # Use a different cache store in production. 45 | # config.cache_store = :mem_cache_store 46 | 47 | # Use a real queuing backend for Active Job (and separate queues per environment) 48 | # config.active_job.queue_adapter = :resque 49 | # config.active_job.queue_name_prefix = "webapp_#{Rails.env}" 50 | config.action_mailer.perform_caching = false 51 | 52 | # Ignore bad email addresses and do not raise email delivery errors. 53 | # Set this to true and configure the email server for immediate delivery to raise delivery errors. 54 | # config.action_mailer.raise_delivery_errors = false 55 | 56 | # Enable locale fallbacks for I18n (makes lookups for any locale fall back to 57 | # the I18n.default_locale when a translation cannot be found). 58 | config.i18n.fallbacks = true 59 | 60 | # Send deprecation notices to registered listeners. 61 | config.active_support.deprecation = :notify 62 | 63 | # Use default logging formatter so that PID and timestamp are not suppressed. 64 | config.log_formatter = ::Logger::Formatter.new 65 | 66 | # Use a different logger for distributed setups. 67 | # require 'syslog/logger' 68 | # config.logger = ActiveSupport::TaggedLogging.new(Syslog::Logger.new 'app-name') 69 | 70 | if ENV["RAILS_LOG_TO_STDOUT"].present? 71 | logger = ActiveSupport::Logger.new(STDOUT) 72 | logger.formatter = config.log_formatter 73 | config.logger = ActiveSupport::TaggedLogging.new(logger) 74 | end 75 | 76 | # Do not dump schema after migrations. 77 | config.active_record.dump_schema_after_migration = false 78 | end 79 | -------------------------------------------------------------------------------- /webapp/config/environments/test.rb: -------------------------------------------------------------------------------- 1 | Rails.application.configure do 2 | # Settings specified here will take precedence over those in config/application.rb. 3 | 4 | # The test environment is used exclusively to run your application's 5 | # test suite. You never need to work with it otherwise. Remember that 6 | # your test database is "scratch space" for the test suite and is wiped 7 | # and recreated between test runs. Don't rely on the data there! 8 | config.cache_classes = true 9 | 10 | # Do not eager load code on boot. This avoids loading your whole application 11 | # just for the purpose of running a single test. If you are using a tool that 12 | # preloads Rails for running tests, you may have to set it to true. 13 | config.eager_load = false 14 | 15 | # Configure public file server for tests with Cache-Control for performance. 16 | config.public_file_server.enabled = true 17 | config.public_file_server.headers = { 18 | 'Cache-Control' => 'public, max-age=3600' 19 | } 20 | 21 | # Show full error reports and disable caching. 22 | config.consider_all_requests_local = true 23 | config.action_controller.perform_caching = false 24 | 25 | # Raise exceptions instead of rendering exception templates. 26 | config.action_dispatch.show_exceptions = false 27 | 28 | # Disable request forgery protection in test environment. 29 | config.action_controller.allow_forgery_protection = false 30 | config.action_mailer.perform_caching = false 31 | 32 | # Tell Action Mailer not to deliver emails to the real world. 33 | # The :test delivery method accumulates sent emails in the 34 | # ActionMailer::Base.deliveries array. 35 | config.action_mailer.delivery_method = :test 36 | 37 | # Print deprecation notices to the stderr. 38 | config.active_support.deprecation = :stderr 39 | 40 | # Raises error for missing translations 41 | # config.action_view.raise_on_missing_translations = true 42 | end 43 | -------------------------------------------------------------------------------- /webapp/config/initializers/application_controller_renderer.rb: -------------------------------------------------------------------------------- 1 | # Be sure to restart your server when you modify this file. 2 | 3 | # ApplicationController.renderer.defaults.merge!( 4 | # http_host: 'example.org', 5 | # https: false 6 | # ) 7 | -------------------------------------------------------------------------------- /webapp/config/initializers/backtrace_silencers.rb: -------------------------------------------------------------------------------- 1 | # Be sure to restart your server when you modify this file. 2 | 3 | # You can add backtrace silencers for libraries that you're using but don't wish to see in your backtraces. 4 | # Rails.backtrace_cleaner.add_silencer { |line| line =~ /my_noisy_library/ } 5 | 6 | # You can also remove all the silencers if you're trying to debug a problem that might stem from framework code. 7 | # Rails.backtrace_cleaner.remove_silencers! 8 | -------------------------------------------------------------------------------- /webapp/config/initializers/cors.rb: -------------------------------------------------------------------------------- 1 | # Be sure to restart your server when you modify this file. 2 | 3 | # Avoid CORS issues when API is called from the frontend app. 4 | # Handle Cross-Origin Resource Sharing (CORS) in order to accept cross-origin AJAX requests. 5 | 6 | # Read more: https://github.com/cyu/rack-cors 7 | 8 | # Rails.application.config.middleware.insert_before 0, Rack::Cors do 9 | # allow do 10 | # origins 'example.com' 11 | # 12 | # resource '*', 13 | # headers: :any, 14 | # methods: [:get, :post, :put, :patch, :delete, :options, :head] 15 | # end 16 | # end 17 | -------------------------------------------------------------------------------- /webapp/config/initializers/filter_parameter_logging.rb: -------------------------------------------------------------------------------- 1 | # Be sure to restart your server when you modify this file. 2 | 3 | # Configure sensitive parameters which will be filtered from the log file. 4 | Rails.application.config.filter_parameters += [:password] 5 | -------------------------------------------------------------------------------- /webapp/config/initializers/inflections.rb: -------------------------------------------------------------------------------- 1 | # Be sure to restart your server when you modify this file. 2 | 3 | # Add new inflection rules using the following format. Inflections 4 | # are locale specific, and you may define rules for as many different 5 | # locales as you wish. All of these examples are active by default: 6 | # ActiveSupport::Inflector.inflections(:en) do |inflect| 7 | # inflect.plural /^(ox)$/i, '\1en' 8 | # inflect.singular /^(ox)en/i, '\1' 9 | # inflect.irregular 'person', 'people' 10 | # inflect.uncountable %w( fish sheep ) 11 | # end 12 | 13 | # These inflection rules are supported but not enabled by default: 14 | # ActiveSupport::Inflector.inflections(:en) do |inflect| 15 | # inflect.acronym 'RESTful' 16 | # end 17 | -------------------------------------------------------------------------------- /webapp/config/initializers/mime_types.rb: -------------------------------------------------------------------------------- 1 | # Be sure to restart your server when you modify this file. 2 | 3 | # Add new mime types for use in respond_to blocks: 4 | # Mime::Type.register "text/richtext", :rtf 5 | -------------------------------------------------------------------------------- /webapp/config/initializers/new_framework_defaults.rb: -------------------------------------------------------------------------------- 1 | # Be sure to restart your server when you modify this file. 2 | # 3 | # This file contains migration options to ease your Rails 5.0 upgrade. 4 | # 5 | # Read the Rails 5.0 release notes for more info on each option. 6 | 7 | # Make Ruby 2.4 preserve the timezone of the receiver when calling `to_time`. 8 | # Previous versions had false. 9 | ActiveSupport.to_time_preserves_timezone = true 10 | 11 | # Require `belongs_to` associations by default. Previous versions had false. 12 | Rails.application.config.active_record.belongs_to_required_by_default = true 13 | 14 | # Do not halt callback chains when a callback returns false. Previous versions had true. 15 | ActiveSupport.halt_callback_chains_on_return_false = false 16 | 17 | # Configure SSL options to enable HSTS with subdomains. Previous versions had false. 18 | Rails.application.config.ssl_options = { hsts: { subdomains: true } } 19 | -------------------------------------------------------------------------------- /webapp/config/initializers/wrap_parameters.rb: -------------------------------------------------------------------------------- 1 | # Be sure to restart your server when you modify this file. 2 | 3 | # This file contains settings for ActionController::ParamsWrapper which 4 | # is enabled by default. 5 | 6 | # Enable parameter wrapping for JSON. You can disable this by setting :format to an empty array. 7 | ActiveSupport.on_load(:action_controller) do 8 | wrap_parameters format: [:json] 9 | end 10 | 11 | # To enable root element in JSON for ActiveRecord objects. 12 | # ActiveSupport.on_load(:active_record) do 13 | # self.include_root_in_json = true 14 | # end 15 | -------------------------------------------------------------------------------- /webapp/config/locales/en.yml: -------------------------------------------------------------------------------- 1 | # Files in the config/locales directory are used for internationalization 2 | # and are automatically loaded by Rails. If you want to use locales other 3 | # than English, add the necessary files in this directory. 4 | # 5 | # To use the locales, use `I18n.t`: 6 | # 7 | # I18n.t 'hello' 8 | # 9 | # In views, this is aliased to just `t`: 10 | # 11 | # <%= t('hello') %> 12 | # 13 | # To use a different locale, set it with `I18n.locale`: 14 | # 15 | # I18n.locale = :es 16 | # 17 | # This would use the information in config/locales/es.yml. 18 | # 19 | # To learn more, please read the Rails Internationalization guide 20 | # available at http://guides.rubyonrails.org/i18n.html. 21 | 22 | en: 23 | hello: "Hello world" 24 | -------------------------------------------------------------------------------- /webapp/config/puma.rb: -------------------------------------------------------------------------------- 1 | # Puma can serve each request in a thread from an internal thread pool. 2 | # The `threads` method setting takes two numbers a minimum and maximum. 3 | # Any libraries that use thread pools should be configured to match 4 | # the maximum value specified for Puma. Default is set to 5 threads for minimum 5 | # and maximum, this matches the default thread size of Active Record. 6 | # 7 | threads_count = ENV.fetch("RAILS_MAX_THREADS") { 5 }.to_i 8 | threads threads_count, threads_count 9 | 10 | # Specifies the `port` that Puma will listen on to receive requests, default is 3000. 11 | # 12 | port ENV.fetch("PORT") { 3000 } 13 | 14 | # Specifies the `environment` that Puma will run in. 15 | # 16 | environment ENV.fetch("RAILS_ENV") { "development" } 17 | 18 | # Specifies the number of `workers` to boot in clustered mode. 19 | # Workers are forked webserver processes. If using threads and workers together 20 | # the concurrency of the application would be max `threads` * `workers`. 21 | # Workers do not work on JRuby or Windows (both of which do not support 22 | # processes). 23 | # 24 | # workers ENV.fetch("WEB_CONCURRENCY") { 2 } 25 | 26 | # Use the `preload_app!` method when specifying a `workers` number. 27 | # This directive tells Puma to first boot the application and load code 28 | # before forking the application. This takes advantage of Copy On Write 29 | # process behavior so workers use less memory. If you use this option 30 | # you need to make sure to reconnect any threads in the `on_worker_boot` 31 | # block. 32 | # 33 | # preload_app! 34 | 35 | # The code in the `on_worker_boot` will be called if you are using 36 | # clustered mode by specifying a number of `workers`. After each worker 37 | # process is booted this block will be run, if you are using `preload_app!` 38 | # option you will want to use this block to reconnect to any threads 39 | # or connections that may have been created at application boot, Ruby 40 | # cannot share connections between processes. 41 | # 42 | # on_worker_boot do 43 | # ActiveRecord::Base.establish_connection if defined?(ActiveRecord) 44 | # end 45 | 46 | # Allow puma to be restarted by `rails restart` command. 47 | plugin :tmp_restart 48 | -------------------------------------------------------------------------------- /webapp/config/routes.rb: -------------------------------------------------------------------------------- 1 | Rails.application.routes.draw do 2 | resources :articles 3 | # For details on the DSL available within this file, see http://guides.rubyonrails.org/routing.html 4 | get '/', to: "pages#welcome" 5 | end 6 | -------------------------------------------------------------------------------- /webapp/config/secrets.yml: -------------------------------------------------------------------------------- 1 | # Be sure to restart your server when you modify this file. 2 | 3 | # Your secret key is used for verifying the integrity of signed cookies. 4 | # If you change this key, all old signed cookies will become invalid! 5 | 6 | # Make sure the secret is at least 30 characters and all random, 7 | # no regular words or you'll be exposed to dictionary attacks. 8 | # You can use `rails secret` to generate a secure secret key. 9 | 10 | # Make sure the secrets in this file are kept private 11 | # if you're sharing your code publicly. 12 | 13 | development: 14 | secret_key_base: 58b15f5dcf0025cdc659f12c167b0008ecf422c4d99e62f33e65b27a5172c7b0f4b41f9a5de7e3f7d8e15153b2211485ddee9a6eb04d37c945f6c094b50baea7 15 | 16 | test: 17 | secret_key_base: 5f0cdd21641e1e2b48df499de7cc17673fec2a16aa3db56b08b9cb7c559a4578a80035fe7526fe4a56ef9a2795366d308cfa9c33a7a0149959d1ad74c699a10c 18 | 19 | # Do not keep production secrets in the repository, 20 | # instead read values from the environment. 21 | production: 22 | secret_key_base: b8d319395ae98c61936b0e8395d9bed9c50bdeaa0dd1ae7856f80f7b1a9c58248c756cd67df51fd5d9eba31f32fb0869d2eeb25272c3079ad690741bb1bfd74f 23 | -------------------------------------------------------------------------------- /webapp/config/spring.rb: -------------------------------------------------------------------------------- 1 | %w( 2 | .ruby-version 3 | .rbenv-vars 4 | tmp/restart.txt 5 | tmp/caching-dev.txt 6 | ).each { |path| Spring.watch(path) } 7 | -------------------------------------------------------------------------------- /webapp/db/migrate/20160925220117_create_articles.rb: -------------------------------------------------------------------------------- 1 | class CreateArticles < ActiveRecord::Migration[5.0] 2 | def change 3 | create_table :articles do |t| 4 | t.string :title 5 | t.text :body 6 | 7 | t.timestamps 8 | end 9 | end 10 | end 11 | -------------------------------------------------------------------------------- /webapp/db/migrate/20160928030155_add_slug_to_articles.rb: -------------------------------------------------------------------------------- 1 | class AddSlugToArticles < ActiveRecord::Migration[5.0] 2 | def change 3 | add_column :articles, :slug, :string 4 | end 5 | end 6 | -------------------------------------------------------------------------------- /webapp/db/schema.rb: -------------------------------------------------------------------------------- 1 | # This file is auto-generated from the current state of the database. Instead 2 | # of editing this file, please use the migrations feature of Active Record to 3 | # incrementally modify your database, and then regenerate this schema definition. 4 | # 5 | # Note that this schema.rb definition is the authoritative source for your 6 | # database schema. If you need to create the application database on another 7 | # system, you should be using db:schema:load, not running all the migrations 8 | # from scratch. The latter is a flawed and unsustainable approach (the more migrations 9 | # you'll amass, the slower it'll run and the greater likelihood for issues). 10 | # 11 | # It's strongly recommended that you check this file into your version control system. 12 | 13 | ActiveRecord::Schema.define(version: 20160928030155) do 14 | 15 | # These are extensions that must be enabled in order to support this database 16 | enable_extension "plpgsql" 17 | 18 | create_table "articles", force: :cascade do |t| 19 | t.string "title" 20 | t.text "body" 21 | t.datetime "created_at", null: false 22 | t.datetime "updated_at", null: false 23 | t.string "slug" 24 | end 25 | 26 | end 27 | -------------------------------------------------------------------------------- /webapp/db/seeds.rb: -------------------------------------------------------------------------------- 1 | # This file should contain all the record creation needed to seed the database with its default values. 2 | # The data can then be loaded with the rails db:seed command (or created alongside the database with db:setup). 3 | # 4 | # Examples: 5 | # 6 | # movies = Movie.create([{ name: 'Star Wars' }, { name: 'Lord of the Rings' }]) 7 | # Character.create(name: 'Luke', movie: movies.first) 8 | -------------------------------------------------------------------------------- /webapp/deploy/migrate.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | set -x 3 | 4 | # get latest commit hash 5 | LC=$(git rev-parse --short HEAD) 6 | 7 | # delete current migrate job 8 | kubectl delete jobs/setup || true 9 | 10 | # replace LAST_COMMIT with latest commit hash output the result to a tmp file 11 | sed "s/webapp:LAST_COMMIT/webapp:$LC/g" kube/jobs/setup-job.yaml > setup-job.yaml.tmp 12 | 13 | # run the updated tmp job in the cluster and then delete the file 14 | kubectl create -f setup-job.yaml.tmp && 15 | rm setup-job.yaml.tmp 16 | -------------------------------------------------------------------------------- /webapp/deploy/push.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | set -x 3 | 4 | LC=$(git rev-parse --short HEAD) 5 | docker build -f Dockerfile -t pacuna/webapp:${LC} . 6 | docker push pacuna/webapp:${LC} 7 | kubectl set image deployment webapp webapp=pacuna/webapp:${LC} 8 | -------------------------------------------------------------------------------- /webapp/docker-compose.test.yml: -------------------------------------------------------------------------------- 1 | version: '2' 2 | services: 3 | webapp_test: 4 | container_name: webapp_test 5 | build: . 6 | depends_on: 7 | - postgres 8 | environment: 9 | - PASSENGER_APP_ENV=development 10 | entrypoint: ./setup.test.sh 11 | postgres: 12 | image: postgres:9.5.3 13 | environment: 14 | - POSTGRES_PASSWORD=mysecretpassword 15 | - POSTGRES_USER=webapp 16 | - POSTGRES_DB=webapp_test 17 | -------------------------------------------------------------------------------- /webapp/docker-compose.yml: -------------------------------------------------------------------------------- 1 | version: '2' 2 | services: 3 | webapp_setup: 4 | build: . 5 | depends_on: 6 | - postgres 7 | environment: 8 | - PASSENGER_APP_ENV=development 9 | entrypoint: ./setup.sh 10 | webapp: 11 | container_name: webapp 12 | build: . 13 | depends_on: 14 | - postgres 15 | - webapp_setup 16 | environment: 17 | - PASSENGER_APP_ENV=development 18 | ports: 19 | - "80:80" 20 | volumes: 21 | - .:/home/app/webapp 22 | postgres: 23 | image: postgres:9.5.3 24 | environment: 25 | - POSTGRES_PASSWORD=mysecretpassword 26 | - POSTGRES_USER=webapp 27 | - POSTGRES_DB=webapp_development 28 | volumes_from: 29 | - postgres_data 30 | postgres_data: 31 | image: postgres:9.5.3 32 | volumes: 33 | - /var/lib/postgresql/data 34 | command: /bin/true 35 | -------------------------------------------------------------------------------- /webapp/ecs/deploy/migrate.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | set -x 3 | aws ecs run-task --task-definition webapp --overrides file://ecs/task-definitions/migrate-overrides.json --cluster ecs-cluster 4 | -------------------------------------------------------------------------------- /webapp/ecs/deploy/push.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | set -x 3 | 4 | LC=$(git rev-parse --short HEAD) 5 | docker build -f Dockerfile -t pacuna/webapp:${LC} . 6 | docker push pacuna/webapp:${LC} 7 | 8 | # replace LAST_COMMIT with latest commit hash output the result to a tmp file 9 | sed "s/webapp:LAST_COMMIT/webapp:$LC/g" ecs/task-definitions/webapp.json > webapp.json.tmp 10 | 11 | # register the new task definition and delete the tmp file 12 | aws ecs register-task-definition --cli-input-json file://webapp.json.tmp 13 | rm webapp.json.tmp 14 | 15 | # update the service 16 | aws ecs update-service --service webapp-service --task-definition webapp --desired-count 1 --cluster ecs-cluster 17 | -------------------------------------------------------------------------------- /webapp/ecs/services/webapp-service.json: -------------------------------------------------------------------------------- 1 | { 2 | "cluster": "ecs-cluster", 3 | "serviceName": "webapp-service", 4 | "taskDefinition": "webapp:1", 5 | "loadBalancers": [ 6 | { 7 | "loadBalancerName": "webapp-load-balancer", 8 | "containerName": "webapp", 9 | "containerPort": 80 10 | } 11 | ], 12 | "desiredCount": 3, 13 | "role": "ecsServiceRole" 14 | } 15 | -------------------------------------------------------------------------------- /webapp/ecs/task-definitions/migrate-overrides.json: -------------------------------------------------------------------------------- 1 | { 2 | "containerOverrides": [ 3 | { 4 | "name": "webapp", 5 | "command": ["bin/rails", "db:migrate", "RAILS_ENV=production"], 6 | "environment": [ 7 | { 8 | "name": "PASSENGER_APP_ENV", 9 | "value": "production" 10 | } 11 | ] 12 | } 13 | ] 14 | } 15 | -------------------------------------------------------------------------------- /webapp/ecs/task-definitions/webapp.json: -------------------------------------------------------------------------------- 1 | { 2 | "family": "webapp", 3 | "containerDefinitions": [ 4 | { 5 | "name": "webapp", 6 | "image": "pacuna/webapp:LAST_COMMIT", 7 | "cpu": 500, 8 | "memory": 500, 9 | "portMappings": [ 10 | { 11 | "containerPort": 80, 12 | "hostPort": 80, 13 | "protocol": "tcp" 14 | } 15 | ], 16 | "essential": true, 17 | "environment": [ 18 | { 19 | "name": "PASSENGER_APP_ENV", 20 | "value": "production" 21 | } 22 | ] 23 | } 24 | ] 25 | } 26 | -------------------------------------------------------------------------------- /webapp/kube/deployments/postgres-deployment.yaml: -------------------------------------------------------------------------------- 1 | apiVersion: v1 2 | kind: Service 3 | metadata: 4 | name: postgres 5 | labels: 6 | app: webapp 7 | spec: 8 | ports: 9 | - port: 5432 10 | selector: 11 | app: webapp 12 | tier: postgres 13 | clusterIP: None 14 | --- 15 | apiVersion: extensions/v1beta1 16 | kind: Deployment 17 | metadata: 18 | name: postgres 19 | labels: 20 | app: webapp 21 | spec: 22 | strategy: 23 | type: Recreate 24 | template: 25 | metadata: 26 | labels: 27 | app: webapp 28 | tier: postgres 29 | spec: 30 | containers: 31 | - image: postgres:9.5.3 32 | name: postgres 33 | env: 34 | - name: POSTGRES_PASSWORD 35 | value: mysecretpassword 36 | - name: POSTGRES_USER 37 | value: webapp 38 | - name: POSTGRES_DB 39 | value: webapp_production 40 | - name: PGDATA 41 | value: /var/lib/postgresql/data/pgdata 42 | ports: 43 | - containerPort: 5432 44 | name: postgres 45 | volumeMounts: 46 | - name: postgres-persistent-storage 47 | mountPath: /var/lib/postgresql/data 48 | volumes: 49 | - name: postgres-persistent-storage 50 | awsElasticBlockStore: 51 | volumeID: vol-fe268f4a 52 | fsType: ext4 53 | -------------------------------------------------------------------------------- /webapp/kube/deployments/webapp-deployment.yaml: -------------------------------------------------------------------------------- 1 | apiVersion: v1 2 | kind: Service 3 | metadata: 4 | name: webapp 5 | labels: 6 | app: webapp 7 | spec: 8 | ports: 9 | - port: 80 10 | selector: 11 | app: webapp 12 | tier: frontend 13 | type: LoadBalancer 14 | --- 15 | apiVersion: extensions/v1beta1 16 | kind: Deployment 17 | metadata: 18 | name: webapp 19 | labels: 20 | app: webapp 21 | spec: 22 | replicas: 3 23 | template: 24 | metadata: 25 | labels: 26 | app: webapp 27 | tier: frontend 28 | spec: 29 | containers: 30 | - image: pacuna/webapp:d15587c 31 | name: webapp 32 | env: 33 | - name: PASSENGER_APP_ENV 34 | value: production 35 | ports: 36 | - containerPort: 80 37 | name: webapp 38 | imagePullPolicy: Always 39 | -------------------------------------------------------------------------------- /webapp/kube/jobs/setup-job.yaml: -------------------------------------------------------------------------------- 1 | apiVersion: batch/v1 2 | kind: Job 3 | metadata: 4 | name: setup 5 | spec: 6 | template: 7 | metadata: 8 | name: setup 9 | spec: 10 | containers: 11 | - name: setup 12 | image: pacuna/webapp:LAST_COMMIT 13 | command: ["/bin/bash", "./setup.production.sh"] 14 | env: 15 | - name: PASSENGER_APP_ENV 16 | value: production 17 | restartPolicy: Never 18 | -------------------------------------------------------------------------------- /webapp/kube/minikube/deployments/postgres-deployment.yaml: -------------------------------------------------------------------------------- 1 | apiVersion: v1 2 | kind: Service 3 | metadata: 4 | name: postgres 5 | labels: 6 | app: webapp 7 | spec: 8 | ports: 9 | - port: 5432 10 | selector: 11 | app: webapp 12 | tier: postgres 13 | clusterIP: None 14 | --- 15 | apiVersion: extensions/v1beta1 16 | kind: Deployment 17 | metadata: 18 | name: postgres 19 | labels: 20 | app: webapp 21 | spec: 22 | strategy: 23 | type: Recreate 24 | template: 25 | metadata: 26 | labels: 27 | app: webapp 28 | tier: postgres 29 | spec: 30 | containers: 31 | - image: postgres:9.5.3 32 | name: postgres 33 | env: 34 | - name: POSTGRES_PASSWORD 35 | value: mysecretpassword 36 | - name: POSTGRES_USER 37 | value: webapp 38 | - name: POSTGRES_DB 39 | value: webapp_production 40 | ports: 41 | - containerPort: 5432 42 | name: postgres 43 | -------------------------------------------------------------------------------- /webapp/kube/minikube/deployments/webapp-deployment.yaml: -------------------------------------------------------------------------------- 1 | apiVersion: v1 2 | kind: Service 3 | metadata: 4 | name: webapp 5 | labels: 6 | app: webapp 7 | spec: 8 | ports: 9 | - port: 80 10 | selector: 11 | app: webapp 12 | tier: frontend 13 | type: NodePort 14 | --- 15 | apiVersion: extensions/v1beta1 16 | kind: Deployment 17 | metadata: 18 | name: webapp 19 | labels: 20 | app: webapp 21 | spec: 22 | replicas: 3 23 | template: 24 | metadata: 25 | labels: 26 | app: webapp 27 | tier: frontend 28 | spec: 29 | containers: 30 | - image: pacuna/webapp:d15587c 31 | name: webapp 32 | env: 33 | - name: PASSENGER_APP_ENV 34 | value: production 35 | ports: 36 | - containerPort: 80 37 | name: webapp 38 | imagePullPolicy: Always 39 | -------------------------------------------------------------------------------- /webapp/lib/tasks/.keep: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Apress/deploying-rails-w-docker/212bac6ddf03f6c710134c2b6333ee314124ddcf/webapp/lib/tasks/.keep -------------------------------------------------------------------------------- /webapp/log/.keep: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Apress/deploying-rails-w-docker/212bac6ddf03f6c710134c2b6333ee314124ddcf/webapp/log/.keep -------------------------------------------------------------------------------- /webapp/log/development.log: -------------------------------------------------------------------------------- 1 | Started GET "/" for 172.18.0.1 at 2016-09-25 21:52:52 +0000 2 | Processing by Rails::WelcomeController#index as */* 3 | Parameters: {"internal"=>true} 4 | Rendering /usr/local/rvm/gems/ruby-2.3.1/gems/railties-5.0.0.1/lib/rails/templates/rails/welcome/index.html.erb 5 | Rendered /usr/local/rvm/gems/ruby-2.3.1/gems/railties-5.0.0.1/lib/rails/templates/rails/welcome/index.html.erb (14.8ms) 6 | Completed 200 OK in 54ms (Views: 49.6ms | ActiveRecord: 0.0ms) 7 | 8 | 9 | Started HEAD "/" for 172.18.0.1 at 2016-09-25 21:52:55 +0000 10 | Processing by Rails::WelcomeController#index as */* 11 | Parameters: {"internal"=>true} 12 | Rendering /usr/local/rvm/gems/ruby-2.3.1/gems/railties-5.0.0.1/lib/rails/templates/rails/welcome/index.html.erb 13 | Rendered /usr/local/rvm/gems/ruby-2.3.1/gems/railties-5.0.0.1/lib/rails/templates/rails/welcome/index.html.erb (1.9ms) 14 | Completed 200 OK in 11ms (Views: 6.3ms | ActiveRecord: 0.0ms) 15 | 16 | 17 | Started HEAD "/" for 172.18.0.1 at 2016-09-25 21:57:01 +0000 18 | Processing by Rails::WelcomeController#index as */* 19 | Parameters: {"internal"=>true} 20 | Rendering /usr/local/rvm/gems/ruby-2.3.1/gems/railties-5.0.0.1/lib/rails/templates/rails/welcome/index.html.erb 21 | Rendered /usr/local/rvm/gems/ruby-2.3.1/gems/railties-5.0.0.1/lib/rails/templates/rails/welcome/index.html.erb (2.4ms) 22 | Completed 200 OK in 12ms (Views: 8.2ms | ActiveRecord: 0.0ms) 23 | 24 | 25 | [1m[35m (0.2ms)[0m [1m[34mSELECT pg_try_advisory_lock(1932410105524239390);[0m 26 | [1m[36mActiveRecord::SchemaMigration Load (0.6ms)[0m [1m[34mSELECT "schema_migrations".* FROM "schema_migrations"[0m 27 | Migrating to CreateArticles (20160925220117) 28 | [1m[35m (0.3ms)[0m [1m[35mBEGIN[0m 29 | [1m[35m (60.3ms)[0m [1m[35mCREATE TABLE "articles" ("id" serial primary key, "title" character varying, "body" text, "created_at" timestamp NOT NULL, "updated_at" timestamp NOT NULL)[0m 30 | [1m[35mSQL (0.7ms)[0m [1m[32mINSERT INTO "schema_migrations" ("version") VALUES ($1) RETURNING "version"[0m [["version", "20160925220117"]] 31 | [1m[35m (17.8ms)[0m [1m[35mCOMMIT[0m 32 | [1m[36mActiveRecord::InternalMetadata Load (0.4ms)[0m [1m[34mSELECT "ar_internal_metadata".* FROM "ar_internal_metadata" WHERE "ar_internal_metadata"."key" = $1 LIMIT $2[0m [["key", :environment], ["LIMIT", 1]] 33 | [1m[35m (0.3ms)[0m [1m[35mBEGIN[0m 34 | [1m[35m (0.2ms)[0m [1m[35mCOMMIT[0m 35 | [1m[35m (0.3ms)[0m [1m[34mSELECT pg_advisory_unlock(1932410105524239390)[0m 36 | [1m[36mActiveRecord::SchemaMigration Load (0.2ms)[0m [1m[34mSELECT "schema_migrations".* FROM "schema_migrations"[0m 37 | [1m[35m (2.0ms)[0m [1m[34mSELECT t2.oid::regclass::text AS to_table, a1.attname AS column, a2.attname AS primary_key, c.conname AS name, c.confupdtype AS on_update, c.confdeltype AS on_delete 38 | FROM pg_constraint c 39 | JOIN pg_class t1 ON c.conrelid = t1.oid 40 | JOIN pg_class t2 ON c.confrelid = t2.oid 41 | JOIN pg_attribute a1 ON a1.attnum = c.conkey[1] AND a1.attrelid = t1.oid 42 | JOIN pg_attribute a2 ON a2.attnum = c.confkey[1] AND a2.attrelid = t2.oid 43 | JOIN pg_namespace t3 ON c.connamespace = t3.oid 44 | WHERE c.contype = 'f' 45 | AND t1.relname = 'articles' 46 | AND t3.nspname = ANY (current_schemas(false)) 47 | ORDER BY c.conname 48 | [0m 49 | Started POST "/articles" for 172.18.0.1 at 2016-09-25 22:10:19 +0000 50 | [1m[36mActiveRecord::SchemaMigration Load (0.6ms)[0m [1m[34mSELECT "schema_migrations".* FROM "schema_migrations"[0m 51 | Processing by ArticlesController#create as */* 52 | Parameters: {"title"=>"my first article", "body"=>"Lorem ipsum dolor sit amet, consectetur adipiscing elit...", "article"=>{"title"=>"my first article", "body"=>"Lorem ipsum dolor sit amet, consectetur adipiscing elit..."}} 53 | [1m[35m (0.3ms)[0m [1m[35mBEGIN[0m 54 | [1m[35mSQL (1.0ms)[0m [1m[32mINSERT INTO "articles" ("title", "body", "created_at", "updated_at") VALUES ($1, $2, $3, $4) RETURNING "id"[0m [["title", "my first article"], ["body", "Lorem ipsum dolor sit amet, consectetur adipiscing elit..."], ["created_at", 2016-09-25 22:10:19 UTC], ["updated_at", 2016-09-25 22:10:19 UTC]] 55 | [1m[35m (12.8ms)[0m [1m[35mCOMMIT[0m 56 | Completed 201 Created in 31ms (Views: 1.1ms | ActiveRecord: 17.3ms) 57 | 58 | 59 | [1m[36mArticle Load (0.6ms)[0m [1m[34mSELECT "articles".* FROM "articles" ORDER BY "articles"."id" ASC LIMIT $1[0m [["LIMIT", 1]] 60 | -------------------------------------------------------------------------------- /webapp/log/test.log: -------------------------------------------------------------------------------- 1 | [1m[35m (220.1ms)[0m [1m[35mDROP DATABASE IF EXISTS "webapp_test"[0m 2 | [1m[35m (486.0ms)[0m [1m[35mCREATE DATABASE "webapp_test" ENCODING = 'unicode'[0m 3 | [1m[35mSQL (0.4ms)[0m [1m[35mCREATE EXTENSION IF NOT EXISTS "plpgsql"[0m 4 | [1m[35m (78.2ms)[0m [1m[35mCREATE TABLE "articles" ("id" serial primary key, "title" character varying, "body" text, "created_at" timestamp NOT NULL, "updated_at" timestamp NOT NULL)[0m 5 | [1m[35m (66.8ms)[0m [1m[35mCREATE TABLE "schema_migrations" ("version" character varying PRIMARY KEY)[0m 6 | [1m[35m (0.9ms)[0m [1m[34mSELECT version FROM "schema_migrations"[0m 7 | [1m[35m (12.3ms)[0m [1m[32mINSERT INTO "schema_migrations" (version) VALUES ('20160925220117')[0m 8 | [1m[35m (78.7ms)[0m [1m[35mCREATE TABLE "ar_internal_metadata" ("key" character varying PRIMARY KEY, "value" character varying, "created_at" timestamp NOT NULL, "updated_at" timestamp NOT NULL)[0m 9 | [1m[36mActiveRecord::InternalMetadata Load (0.5ms)[0m [1m[34mSELECT "ar_internal_metadata".* FROM "ar_internal_metadata" WHERE "ar_internal_metadata"."key" = $1 LIMIT $2[0m [["key", :environment], ["LIMIT", 1]] 10 | [1m[35m (0.3ms)[0m [1m[35mBEGIN[0m 11 | [1m[35mSQL (0.5ms)[0m [1m[32mINSERT INTO "ar_internal_metadata" ("key", "value", "created_at", "updated_at") VALUES ($1, $2, $3, $4) RETURNING "key"[0m [["key", "environment"], ["value", "test"], ["created_at", 2016-09-25 22:07:58 UTC], ["updated_at", 2016-09-25 22:07:58 UTC]] 12 | [1m[35m (13.0ms)[0m [1m[35mCOMMIT[0m 13 | [1m[36mActiveRecord::InternalMetadata Load (0.3ms)[0m [1m[34mSELECT "ar_internal_metadata".* FROM "ar_internal_metadata" WHERE "ar_internal_metadata"."key" = $1 LIMIT $2[0m [["key", :environment], ["LIMIT", 1]] 14 | [1m[35m (0.3ms)[0m [1m[35mBEGIN[0m 15 | [1m[35m (0.2ms)[0m [1m[35mCOMMIT[0m 16 | [1m[36mActiveRecord::SchemaMigration Load (0.6ms)[0m [1m[34mSELECT "schema_migrations".* FROM "schema_migrations"[0m 17 | [1m[35m (0.5ms)[0m [1m[35mBEGIN[0m 18 | [1m[35m (0.5ms)[0m [1m[35mALTER TABLE "articles" DISABLE TRIGGER ALL;ALTER TABLE "schema_migrations" DISABLE TRIGGER ALL;ALTER TABLE "ar_internal_metadata" DISABLE TRIGGER ALL[0m 19 | [1m[35m (0.3ms)[0m [1m[35mCOMMIT[0m 20 | [1m[35m (0.3ms)[0m [1m[35mBEGIN[0m 21 | [1m[36mFixture Delete (0.5ms)[0m [1m[31mDELETE FROM "articles"[0m 22 | [1m[36mFixture Insert (0.6ms)[0m [1m[32mINSERT INTO "articles" ("title", "body", "created_at", "updated_at", "id") VALUES ('MyString', 'MyText', '2016-09-25 22:07:58.377087', '2016-09-25 22:07:58.377087', 980190962)[0m 23 | [1m[36mFixture Insert (0.4ms)[0m [1m[32mINSERT INTO "articles" ("title", "body", "created_at", "updated_at", "id") VALUES ('MyString', 'MyText', '2016-09-25 22:07:58.377087', '2016-09-25 22:07:58.377087', 298486374)[0m 24 | [1m[35m (12.9ms)[0m [1m[35mCOMMIT[0m 25 | [1m[35m (0.8ms)[0m [1m[35mBEGIN[0m 26 | [1m[35m (0.3ms)[0m [1m[35mALTER TABLE "articles" ENABLE TRIGGER ALL;ALTER TABLE "schema_migrations" ENABLE TRIGGER ALL;ALTER TABLE "ar_internal_metadata" ENABLE TRIGGER ALL[0m 27 | [1m[35m (0.2ms)[0m [1m[35mCOMMIT[0m 28 | [1m[35m (0.2ms)[0m [1m[35mBEGIN[0m 29 | -------------------------------------------------- 30 | ArticlesControllerTest: test_should_create_article 31 | -------------------------------------------------- 32 | [1m[36mArticle Load (0.4ms)[0m [1m[34mSELECT "articles".* FROM "articles" WHERE "articles"."id" = $1 LIMIT $2[0m [["id", 980190962], ["LIMIT", 1]] 33 | [1m[35m (0.5ms)[0m [1m[34mSELECT COUNT(*) FROM "articles"[0m 34 | Started POST "/articles.json" for 127.0.0.1 at 2016-09-25 22:07:59 +0000 35 | Processing by ArticlesController#create as JSON 36 | Parameters: {"article"=>{"body"=>"MyText", "title"=>"MyString"}} 37 | [1m[35m (0.4ms)[0m [1m[35mSAVEPOINT active_record_1[0m 38 | [1m[35mSQL (0.6ms)[0m [1m[32mINSERT INTO "articles" ("title", "body", "created_at", "updated_at") VALUES ($1, $2, $3, $4) RETURNING "id"[0m [["title", "MyString"], ["body", "MyText"], ["created_at", 2016-09-25 22:07:59 UTC], ["updated_at", 2016-09-25 22:07:59 UTC]] 39 | [1m[35m (0.3ms)[0m [1m[35mRELEASE SAVEPOINT active_record_1[0m 40 | Completed 201 Created in 7ms (Views: 1.2ms | ActiveRecord: 1.3ms) 41 | [1m[35m (0.5ms)[0m [1m[34mSELECT COUNT(*) FROM "articles"[0m 42 | [1m[35m (0.4ms)[0m [1m[31mROLLBACK[0m 43 | [1m[35m (0.2ms)[0m [1m[35mBEGIN[0m 44 | ------------------------------------------------ 45 | ArticlesControllerTest: test_should_show_article 46 | ------------------------------------------------ 47 | [1m[36mArticle Load (0.5ms)[0m [1m[34mSELECT "articles".* FROM "articles" WHERE "articles"."id" = $1 LIMIT $2[0m [["id", 980190962], ["LIMIT", 1]] 48 | Started GET "/articles/980190962.json?null" for 127.0.0.1 at 2016-09-25 22:07:59 +0000 49 | Processing by ArticlesController#show as JSON 50 | Parameters: {"null"=>nil, "id"=>"980190962", "article"=>{}} 51 | [1m[36mArticle Load (0.5ms)[0m [1m[34mSELECT "articles".* FROM "articles" WHERE "articles"."id" = $1 LIMIT $2[0m [["id", 980190962], ["LIMIT", 1]] 52 | Completed 200 OK in 10ms (Views: 1.1ms | ActiveRecord: 0.5ms) 53 | [1m[35m (0.4ms)[0m [1m[31mROLLBACK[0m 54 | [1m[35m (0.3ms)[0m [1m[35mBEGIN[0m 55 | -------------------------------------------------- 56 | ArticlesControllerTest: test_should_update_article 57 | -------------------------------------------------- 58 | [1m[36mArticle Load (0.9ms)[0m [1m[34mSELECT "articles".* FROM "articles" WHERE "articles"."id" = $1 LIMIT $2[0m [["id", 980190962], ["LIMIT", 1]] 59 | Started PATCH "/articles/980190962.json" for 127.0.0.1 at 2016-09-25 22:07:59 +0000 60 | Processing by ArticlesController#update as JSON 61 | Parameters: {"article"=>{"body"=>"MyText", "title"=>"MyString"}, "id"=>"980190962"} 62 | [1m[36mArticle Load (0.5ms)[0m [1m[34mSELECT "articles".* FROM "articles" WHERE "articles"."id" = $1 LIMIT $2[0m [["id", 980190962], ["LIMIT", 1]] 63 | [1m[35m (0.4ms)[0m [1m[35mSAVEPOINT active_record_1[0m 64 | [1m[35m (0.3ms)[0m [1m[35mRELEASE SAVEPOINT active_record_1[0m 65 | Completed 200 OK in 6ms (Views: 0.5ms | ActiveRecord: 1.1ms) 66 | [1m[35m (0.3ms)[0m [1m[31mROLLBACK[0m 67 | [1m[35m (0.3ms)[0m [1m[35mBEGIN[0m 68 | --------------------------------------------------- 69 | ArticlesControllerTest: test_should_destroy_article 70 | --------------------------------------------------- 71 | [1m[36mArticle Load (0.5ms)[0m [1m[34mSELECT "articles".* FROM "articles" WHERE "articles"."id" = $1 LIMIT $2[0m [["id", 980190962], ["LIMIT", 1]] 72 | [1m[35m (0.4ms)[0m [1m[34mSELECT COUNT(*) FROM "articles"[0m 73 | Started DELETE "/articles/980190962.json" for 127.0.0.1 at 2016-09-25 22:07:59 +0000 74 | Processing by ArticlesController#destroy as JSON 75 | Parameters: {"_json"=>nil, "id"=>"980190962", "article"=>{}} 76 | [1m[36mArticle Load (0.5ms)[0m [1m[34mSELECT "articles".* FROM "articles" WHERE "articles"."id" = $1 LIMIT $2[0m [["id", 980190962], ["LIMIT", 1]] 77 | [1m[35m (0.3ms)[0m [1m[35mSAVEPOINT active_record_1[0m 78 | [1m[35mSQL (0.4ms)[0m [1m[31mDELETE FROM "articles" WHERE "articles"."id" = $1[0m [["id", 980190962]] 79 | [1m[35m (0.2ms)[0m [1m[35mRELEASE SAVEPOINT active_record_1[0m 80 | Completed 204 No Content in 5ms (ActiveRecord: 1.4ms) 81 | [1m[35m (0.5ms)[0m [1m[34mSELECT COUNT(*) FROM "articles"[0m 82 | [1m[35m (0.3ms)[0m [1m[31mROLLBACK[0m 83 | [1m[35m (0.3ms)[0m [1m[35mBEGIN[0m 84 | --------------------------------------------- 85 | ArticlesControllerTest: test_should_get_index 86 | --------------------------------------------- 87 | [1m[36mArticle Load (0.9ms)[0m [1m[34mSELECT "articles".* FROM "articles" WHERE "articles"."id" = $1 LIMIT $2[0m [["id", 980190962], ["LIMIT", 1]] 88 | Started GET "/articles.json?null" for 127.0.0.1 at 2016-09-25 22:07:59 +0000 89 | Processing by ArticlesController#index as JSON 90 | Parameters: {"null"=>nil, "article"=>{}} 91 | [1m[36mArticle Load (1.4ms)[0m [1m[34mSELECT "articles".* FROM "articles"[0m 92 | Completed 200 OK in 6ms (Views: 4.4ms | ActiveRecord: 1.4ms) 93 | [1m[35m (0.3ms)[0m [1m[31mROLLBACK[0m 94 | -------------------------------------------------------------------------------- /webapp/public/robots.txt: -------------------------------------------------------------------------------- 1 | # See http://www.robotstxt.org/robotstxt.html for documentation on how to use the robots.txt file 2 | # 3 | # To ban all spiders from the entire site uncomment the next two lines: 4 | # User-agent: * 5 | # Disallow: / 6 | -------------------------------------------------------------------------------- /webapp/rails-env.conf: -------------------------------------------------------------------------------- 1 | env SECRET_KEY_BASE; 2 | env DATABASE_URL; 3 | env DATABASE_PASSWORD; 4 | -------------------------------------------------------------------------------- /webapp/setup.production.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | echo "Waiting PostgreSQL to start on 5432..." 4 | 5 | while ! nc -z postgres 5432; do 6 | sleep 0.1 7 | done 8 | 9 | echo "PostgreSQL started" 10 | 11 | bin/rails db:migrate RAILS_ENV=production 12 | -------------------------------------------------------------------------------- /webapp/setup.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | echo "Waiting PostgreSQL to start on 5432..." 4 | 5 | while ! nc -z postgres 5432; do 6 | sleep 0.1 7 | done 8 | 9 | echo "PostgreSQL started" 10 | 11 | bin/rails db:migrate 12 | -------------------------------------------------------------------------------- /webapp/setup.test.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | echo "Waiting PostgreSQL to start on 5432..." 4 | 5 | while ! nc -z postgres 5432; do 6 | sleep 0.1 7 | done 8 | 9 | echo "PostgreSQL started" 10 | 11 | bin/rails db:create RAILS_ENV=test 12 | bin/rails db:migrate RAILS_ENV=test 13 | bin/rake RAILS_ENV=test 14 | -------------------------------------------------------------------------------- /webapp/test/controllers/.keep: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Apress/deploying-rails-w-docker/212bac6ddf03f6c710134c2b6333ee314124ddcf/webapp/test/controllers/.keep -------------------------------------------------------------------------------- /webapp/test/controllers/articles_controller_test.rb: -------------------------------------------------------------------------------- 1 | require 'test_helper' 2 | 3 | class ArticlesControllerTest < ActionDispatch::IntegrationTest 4 | setup do 5 | @article = articles(:one) 6 | end 7 | 8 | test "should get index" do 9 | get articles_url, as: :json 10 | assert_response :success 11 | end 12 | 13 | test "should create article" do 14 | assert_difference('Article.count') do 15 | post articles_url, params: { article: { body: @article.body, title: @article.title } }, as: :json 16 | end 17 | 18 | assert_response 201 19 | end 20 | 21 | test "should show article" do 22 | get article_url(@article), as: :json 23 | assert_response :success 24 | end 25 | 26 | test "should update article" do 27 | patch article_url(@article), params: { article: { body: @article.body, title: @article.title } }, as: :json 28 | assert_response 200 29 | end 30 | 31 | test "should destroy article" do 32 | assert_difference('Article.count', -1) do 33 | delete article_url(@article), as: :json 34 | end 35 | 36 | assert_response 204 37 | end 38 | end 39 | -------------------------------------------------------------------------------- /webapp/test/fixtures/.keep: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Apress/deploying-rails-w-docker/212bac6ddf03f6c710134c2b6333ee314124ddcf/webapp/test/fixtures/.keep -------------------------------------------------------------------------------- /webapp/test/fixtures/articles.yml: -------------------------------------------------------------------------------- 1 | # Read about fixtures at http://api.rubyonrails.org/classes/ActiveRecord/FixtureSet.html 2 | 3 | one: 4 | title: MyString 5 | body: MyText 6 | 7 | two: 8 | title: MyString 9 | body: MyText 10 | -------------------------------------------------------------------------------- /webapp/test/fixtures/files/.keep: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Apress/deploying-rails-w-docker/212bac6ddf03f6c710134c2b6333ee314124ddcf/webapp/test/fixtures/files/.keep -------------------------------------------------------------------------------- /webapp/test/integration/.keep: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Apress/deploying-rails-w-docker/212bac6ddf03f6c710134c2b6333ee314124ddcf/webapp/test/integration/.keep -------------------------------------------------------------------------------- /webapp/test/mailers/.keep: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Apress/deploying-rails-w-docker/212bac6ddf03f6c710134c2b6333ee314124ddcf/webapp/test/mailers/.keep -------------------------------------------------------------------------------- /webapp/test/models/.keep: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Apress/deploying-rails-w-docker/212bac6ddf03f6c710134c2b6333ee314124ddcf/webapp/test/models/.keep -------------------------------------------------------------------------------- /webapp/test/models/article_test.rb: -------------------------------------------------------------------------------- 1 | require 'test_helper' 2 | 3 | class ArticleTest < ActiveSupport::TestCase 4 | # test "the truth" do 5 | # assert true 6 | # end 7 | end 8 | -------------------------------------------------------------------------------- /webapp/test/test_helper.rb: -------------------------------------------------------------------------------- 1 | ENV['RAILS_ENV'] ||= 'test' 2 | require File.expand_path('../../config/environment', __FILE__) 3 | require 'rails/test_help' 4 | 5 | class ActiveSupport::TestCase 6 | # Setup all fixtures in test/fixtures/*.yml for all tests in alphabetical order. 7 | fixtures :all 8 | 9 | # Add more helper methods to be used by all tests here... 10 | end 11 | -------------------------------------------------------------------------------- /webapp/tmp/.keep: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Apress/deploying-rails-w-docker/212bac6ddf03f6c710134c2b6333ee314124ddcf/webapp/tmp/.keep -------------------------------------------------------------------------------- /webapp/webapp.conf: -------------------------------------------------------------------------------- 1 | server { 2 | listen 80; 3 | server_name _; 4 | root /home/app/webapp/public; 5 | 6 | passenger_enabled on; 7 | passenger_user app; 8 | 9 | passenger_ruby /usr/bin/ruby2.3; 10 | } 11 | --------------------------------------------------------------------------------