├── .dockerignore ├── .gitignore ├── Dockerfile ├── Gemfile ├── Gemfile.lock ├── Guardfile ├── LICENSE ├── README.md ├── Rakefile ├── app ├── assets │ ├── images │ │ └── .keep │ ├── javascripts │ │ ├── application.js │ │ └── posts.coffee │ └── stylesheets │ │ ├── application.css │ │ ├── posts.scss │ │ └── scaffolds.scss ├── controllers │ ├── application_controller.rb │ ├── concerns │ │ └── .keep │ └── posts_controller.rb ├── helpers │ ├── application_helper.rb │ └── posts_helper.rb ├── mailers │ └── .keep ├── models │ ├── .keep │ ├── concerns │ │ └── .keep │ └── post.rb └── views │ ├── layouts │ └── application.html.erb │ └── posts │ ├── _form.html.erb │ ├── edit.html.erb │ ├── index.html.erb │ ├── index.json.jbuilder │ ├── new.html.erb │ ├── show.html.erb │ └── show.json.jbuilder ├── bin ├── bundle ├── check_or_setup_db ├── dumpdb ├── rails ├── rake ├── restoredb └── setup ├── config.ru ├── config ├── application.rb ├── boot.rb ├── database.yml ├── environment.rb ├── environments │ ├── development.rb │ ├── production.rb │ └── test.rb ├── initializers │ ├── assets.rb │ ├── backtrace_silencers.rb │ ├── cookies_serializer.rb │ ├── filter_parameter_logging.rb │ ├── inflections.rb │ ├── mime_types.rb │ ├── session_store.rb │ └── wrap_parameters.rb ├── locales │ └── en.yml └── routes.rb ├── db ├── dumps │ └── README.md ├── migrate │ └── 20150508192001_create_posts.rb ├── postgres-setup.sql ├── schema.rb └── seeds.rb ├── dev.Dockerfile ├── development-entrypoint ├── doc ├── CREATE_A_NEW_RAILS_PROJECT.md ├── DOCKER_SETUP_ON_LINUX.md ├── DOCKER_SETUP_ON_MAC.md └── DOCKER_SETUP_ON_WINDOWS.md ├── docker-compose.yml ├── lib ├── assets │ └── .keep ├── tasks │ └── .keep └── templates │ ├── dotenv.env │ └── secrets.yml.erb ├── log └── .keep ├── public ├── 404.html ├── 422.html ├── 500.html ├── favicon.ico └── robots.txt ├── test ├── controllers │ ├── .keep │ └── posts_controller_test.rb ├── fixtures │ ├── .keep │ └── posts.yml ├── helpers │ └── .keep ├── integration │ └── .keep ├── mailers │ └── .keep ├── models │ ├── .keep │ └── post_test.rb └── test_helper.rb └── vendor └── assets ├── javascripts └── .keep └── stylesheets └── .keep /.dockerignore: -------------------------------------------------------------------------------- 1 | # Ignore files not needed when building a Docker image of this project 2 | 3 | # Ignore the temporary files: 4 | /tmp/* 5 | /log/*.log 6 | 7 | # Ignore the gems installed by bundler, as they should be installed from zero 8 | # by the Docker image building process: 9 | /vendor/bundle 10 | 11 | # Ignore shell & console artifacts, such as bash, byebug and pry history logs: 12 | .bash_history 13 | .byebug_hist 14 | .pry_history 15 | 16 | # Ignore the docker-compose project files: 17 | docker-compose.yml 18 | first_time_setup.sh 19 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | *.rbc 2 | capybara-*.html 3 | .rspec 4 | /db/*.sqlite3 5 | /db/*.sqlite3-journal 6 | /public/system 7 | /coverage/ 8 | /spec/tmp 9 | **.orig 10 | rerun.txt 11 | pickle-email-*.html 12 | 13 | # Ignore all logfiles and tempfiles. 14 | /log/* 15 | !/log/.keep 16 | /tmp 17 | 18 | # Ignore the vendor/bundle directory, which contains the gems installed by 19 | # bundler: 20 | /vendor/bundle 21 | 22 | # TODO Comment out these rules if you are OK with secrets being uploaded to the repo 23 | config/initializers/secret_token.rb 24 | config/secrets.yml 25 | 26 | ## Environment normalisation: 27 | /.bundle 28 | /vendor/bundle 29 | 30 | # these should all be checked in to normalise the environment: 31 | # Gemfile.lock, .ruby-version, .ruby-gemset 32 | 33 | # unless supporting rvm < 1.11.0 or doing something fancy, ignore this: 34 | .rvmrc 35 | 36 | # if using bower-rails ignore default bower_components path bower.json files 37 | /vendor/assets/bower_components 38 | *.bowerrc 39 | bower.json 40 | 41 | # Ignore pow environment settings 42 | .powenv 43 | 44 | # Ignore bash / IRB / Byebug history files 45 | /.bash_history 46 | /.byebug_hist 47 | /.pry_history 48 | /.guard_history 49 | 50 | # TODO: Remove whatever makes the .gem file to be created: 51 | /.gem 52 | 53 | # Ignore environment file: 54 | /.env 55 | 56 | # Ignore project's database dumps: 57 | /db/dumps/* 58 | !/db/dumps/README.md 59 | -------------------------------------------------------------------------------- /Dockerfile: -------------------------------------------------------------------------------- 1 | # This Dockerfile is intended to build a production-ready app image. 2 | # 1: Use ruby 2.2.6 as base: 3 | FROM ruby:2.2.6-alpine 4 | 5 | # 2: We'll set the application path as the working directory 6 | WORKDIR /usr/src/app 7 | 8 | # 3: We'll add the app's binaries path to $PATH, and set the environment name to 'production': 9 | ENV PATH=/usr/src/app/bin:$PATH RAILS_ENV=production RACK_ENV=production 10 | 11 | # 4: Set the default command: 12 | CMD [ "bundle", "exec", "puma", "--bind", "tcp://0.0.0.0:3000" ] 13 | 14 | # 5: Expose the web port: 15 | EXPOSE 3000 16 | 17 | # ================================================================================================== 18 | # 6: Install dependencies: 19 | 20 | # 6.1: Install the common runtime dependencies: 21 | RUN set -ex && apk add --no-cache libpq ca-certificates openssl 22 | 23 | # 6.2: Copy just the Gemfile & Gemfile.lock, to avoid the build cache failing whenever any other 24 | # file changed and installing dependencies all over again - a must if your'e developing this 25 | # Dockerfile... 26 | ADD ./Gemfile* /usr/src/app/ 27 | 28 | # 6.3: Install build dependencies AND install/build the app gems: 29 | RUN set -ex \ 30 | && apk add --no-cache --virtual .app-builddeps build-base postgresql-dev \ 31 | && bundle install --without development test \ 32 | && apk del .app-builddeps 33 | 34 | # ================================================================================================== 35 | # 7: Copy the rest of the application code, install nodejs as a build dependency, then compile the 36 | # app assets, and finally change the owner of the code to 'nobody': 37 | ADD . /usr/src/app 38 | RUN set -ex \ 39 | && apk add --no-cache --virtual .app-builddeps nodejs=6.2.0-r0 \ 40 | && mkdir -p /usr/src/app/tmp/cache \ 41 | && mkdir -p /usr/src/app/tmp/pids \ 42 | && mkdir -p /usr/src/app/tmp/sockets \ 43 | && DATABASE_URL=postgres://postgres@example.com:5432/fakedb \ 44 | AMQP_URL=amqp://guest:guest@amqp:5672 TWITTER_API_KEY=SOME_KEY TWITTER_API_SECRET=SOME_SECRET \ 45 | SECRET_KEY_BASE=10167c7f7654ed02b3557b05b88ece \ 46 | rails assets:precompile \ 47 | && echo "apk del .app-builddeps" \ 48 | && chown -R nobody /usr/src/app 49 | 50 | # ================================================================================================== 51 | # 8: Set the container user to 'nobody': 52 | USER nobody 53 | -------------------------------------------------------------------------------- /Gemfile: -------------------------------------------------------------------------------- 1 | source 'https://rubygems.org' 2 | 3 | ruby "2.2.6" 4 | 5 | # Bundle edge Rails instead: gem 'rails', github: 'rails/rails' 6 | gem 'rails', '4.2.1' 7 | # Use postgresql as the database for Active Record 8 | gem 'pg' 9 | # Use SCSS for stylesheets 10 | gem 'sass-rails', '~> 5.0' 11 | # Use Uglifier as compressor for JavaScript assets 12 | gem 'uglifier', '>= 1.3.0' 13 | # Use CoffeeScript for .coffee assets and views 14 | gem 'coffee-rails', '~> 4.1.0' 15 | # See https://github.com/rails/execjs#readme for more supported runtimes 16 | # gem 'therubyracer', platforms: :ruby 17 | 18 | # Use jquery as the JavaScript library 19 | gem 'jquery-rails' 20 | # Turbolinks makes following links in your web application faster. Read more: https://github.com/rails/turbolinks 21 | gem 'turbolinks' 22 | # Build JSON APIs with ease. Read more: https://github.com/rails/jbuilder 23 | gem 'jbuilder', '~> 2.0' 24 | # bundle exec rake doc:rails generates the API under doc/api. 25 | gem 'sdoc', '~> 0.4.0', group: :doc 26 | 27 | # Use sidekiq as job processor: 28 | gem 'sidekiq', '~> 3.3.4' 29 | 30 | # Use ActiveModel has_secure_password 31 | # gem 'bcrypt', '~> 3.1.7' 32 | 33 | # Use Unicorn as the app server 34 | # gem 'unicorn' 35 | 36 | # Use Capistrano for deployment 37 | # gem 'capistrano-rails', group: :development 38 | 39 | group :development, :test do 40 | 41 | # Automatically & intelligently launch tests with the minitest framework when 42 | # files are modified: 43 | gem 'guard-minitest' 44 | 45 | # guard-minitest requirement: 46 | gem 'guard' 47 | 48 | 49 | # Call 'byebug' anywhere in the code to stop execution and get a debugger console 50 | gem 'byebug' 51 | 52 | # Access an IRB console on exception pages or by using <%= console %> in views 53 | gem 'web-console', '~> 2.0' 54 | 55 | # Spring speeds up development by keeping your application running in the background. Read more: https://github.com/rails/spring 56 | gem 'spring' 57 | end 58 | -------------------------------------------------------------------------------- /Gemfile.lock: -------------------------------------------------------------------------------- 1 | GEM 2 | remote: https://rubygems.org/ 3 | specs: 4 | actionmailer (4.2.1) 5 | actionpack (= 4.2.1) 6 | actionview (= 4.2.1) 7 | activejob (= 4.2.1) 8 | mail (~> 2.5, >= 2.5.4) 9 | rails-dom-testing (~> 1.0, >= 1.0.5) 10 | actionpack (4.2.1) 11 | actionview (= 4.2.1) 12 | activesupport (= 4.2.1) 13 | rack (~> 1.6) 14 | rack-test (~> 0.6.2) 15 | rails-dom-testing (~> 1.0, >= 1.0.5) 16 | rails-html-sanitizer (~> 1.0, >= 1.0.1) 17 | actionview (4.2.1) 18 | activesupport (= 4.2.1) 19 | builder (~> 3.1) 20 | erubis (~> 2.7.0) 21 | rails-dom-testing (~> 1.0, >= 1.0.5) 22 | rails-html-sanitizer (~> 1.0, >= 1.0.1) 23 | activejob (4.2.1) 24 | activesupport (= 4.2.1) 25 | globalid (>= 0.3.0) 26 | activemodel (4.2.1) 27 | activesupport (= 4.2.1) 28 | builder (~> 3.1) 29 | activerecord (4.2.1) 30 | activemodel (= 4.2.1) 31 | activesupport (= 4.2.1) 32 | arel (~> 6.0) 33 | activesupport (4.2.1) 34 | i18n (~> 0.7) 35 | json (~> 1.7, >= 1.7.7) 36 | minitest (~> 5.1) 37 | thread_safe (~> 0.3, >= 0.3.4) 38 | tzinfo (~> 1.1) 39 | arel (6.0.0) 40 | binding_of_caller (0.7.2) 41 | debug_inspector (>= 0.0.1) 42 | builder (3.2.2) 43 | byebug (4.0.5) 44 | columnize (= 0.9.0) 45 | celluloid (0.16.0) 46 | timers (~> 4.0.0) 47 | coderay (1.1.0) 48 | coffee-rails (4.1.0) 49 | coffee-script (>= 2.2.0) 50 | railties (>= 4.0.0, < 5.0) 51 | coffee-script (2.4.1) 52 | coffee-script-source 53 | execjs 54 | coffee-script-source (1.9.1.1) 55 | columnize (0.9.0) 56 | connection_pool (2.2.0) 57 | debug_inspector (0.0.2) 58 | erubis (2.7.0) 59 | execjs (2.5.2) 60 | ffi (1.9.8) 61 | formatador (0.2.5) 62 | globalid (0.3.5) 63 | activesupport (>= 4.1.0) 64 | guard (2.12.5) 65 | formatador (>= 0.2.4) 66 | listen (~> 2.7) 67 | lumberjack (~> 1.0) 68 | nenv (~> 0.1) 69 | notiffany (~> 0.0) 70 | pry (>= 0.9.12) 71 | shellany (~> 0.0) 72 | thor (>= 0.18.1) 73 | guard-compat (1.2.1) 74 | guard-minitest (2.4.4) 75 | guard-compat (~> 1.2) 76 | minitest (>= 3.0) 77 | hitimes (1.2.2) 78 | i18n (0.7.0) 79 | jbuilder (2.2.13) 80 | activesupport (>= 3.0.0, < 5) 81 | multi_json (~> 1.2) 82 | jquery-rails (4.0.3) 83 | rails-dom-testing (~> 1.0) 84 | railties (>= 4.2.0) 85 | thor (>= 0.14, < 2.0) 86 | json (1.8.2) 87 | listen (2.10.0) 88 | celluloid (~> 0.16.0) 89 | rb-fsevent (>= 0.9.3) 90 | rb-inotify (>= 0.9) 91 | loofah (2.0.2) 92 | nokogiri (>= 1.5.9) 93 | lumberjack (1.0.9) 94 | mail (2.6.3) 95 | mime-types (>= 1.16, < 3) 96 | method_source (0.8.2) 97 | mime-types (2.5) 98 | mini_portile (0.6.2) 99 | minitest (5.6.1) 100 | multi_json (1.11.0) 101 | nenv (0.2.0) 102 | nokogiri (1.6.6.2) 103 | mini_portile (~> 0.6.0) 104 | notiffany (0.0.6) 105 | nenv (~> 0.1) 106 | shellany (~> 0.0) 107 | pg (0.18.1) 108 | pry (0.10.1) 109 | coderay (~> 1.1.0) 110 | method_source (~> 0.8.1) 111 | slop (~> 3.4) 112 | rack (1.6.1) 113 | rack-test (0.6.3) 114 | rack (>= 1.0) 115 | rails (4.2.1) 116 | actionmailer (= 4.2.1) 117 | actionpack (= 4.2.1) 118 | actionview (= 4.2.1) 119 | activejob (= 4.2.1) 120 | activemodel (= 4.2.1) 121 | activerecord (= 4.2.1) 122 | activesupport (= 4.2.1) 123 | bundler (>= 1.3.0, < 2.0) 124 | railties (= 4.2.1) 125 | sprockets-rails 126 | rails-deprecated_sanitizer (1.0.3) 127 | activesupport (>= 4.2.0.alpha) 128 | rails-dom-testing (1.0.6) 129 | activesupport (>= 4.2.0.beta, < 5.0) 130 | nokogiri (~> 1.6.0) 131 | rails-deprecated_sanitizer (>= 1.0.1) 132 | rails-html-sanitizer (1.0.2) 133 | loofah (~> 2.0) 134 | railties (4.2.1) 135 | actionpack (= 4.2.1) 136 | activesupport (= 4.2.1) 137 | rake (>= 0.8.7) 138 | thor (>= 0.18.1, < 2.0) 139 | rake (10.4.2) 140 | rb-fsevent (0.9.4) 141 | rb-inotify (0.9.5) 142 | ffi (>= 0.5.0) 143 | rdoc (4.2.0) 144 | redis (3.2.1) 145 | redis-namespace (1.5.2) 146 | redis (~> 3.0, >= 3.0.4) 147 | sass (3.4.13) 148 | sass-rails (5.0.3) 149 | railties (>= 4.0.0, < 5.0) 150 | sass (~> 3.1) 151 | sprockets (>= 2.8, < 4.0) 152 | sprockets-rails (>= 2.0, < 4.0) 153 | tilt (~> 1.1) 154 | sdoc (0.4.1) 155 | json (~> 1.7, >= 1.7.7) 156 | rdoc (~> 4.0) 157 | shellany (0.0.1) 158 | sidekiq (3.3.4) 159 | celluloid (>= 0.16.0) 160 | connection_pool (>= 2.1.1) 161 | json 162 | redis (>= 3.0.6) 163 | redis-namespace (>= 1.3.1) 164 | slop (3.6.0) 165 | spring (1.3.6) 166 | sprockets (3.0.3) 167 | rack (~> 1.0) 168 | sprockets-rails (2.3.0) 169 | actionpack (>= 3.0) 170 | activesupport (>= 3.0) 171 | sprockets (>= 2.8, < 4.0) 172 | thor (0.19.1) 173 | thread_safe (0.3.5) 174 | tilt (1.4.1) 175 | timers (4.0.1) 176 | hitimes 177 | turbolinks (2.5.3) 178 | coffee-rails 179 | tzinfo (1.2.2) 180 | thread_safe (~> 0.1) 181 | uglifier (2.7.1) 182 | execjs (>= 0.3.0) 183 | json (>= 1.8.0) 184 | web-console (2.1.2) 185 | activemodel (>= 4.0) 186 | binding_of_caller (>= 0.7.2) 187 | railties (>= 4.0) 188 | sprockets-rails (>= 2.0, < 4.0) 189 | 190 | PLATFORMS 191 | ruby 192 | 193 | DEPENDENCIES 194 | byebug 195 | coffee-rails (~> 4.1.0) 196 | guard 197 | guard-minitest 198 | jbuilder (~> 2.0) 199 | jquery-rails 200 | pg 201 | rails (= 4.2.1) 202 | sass-rails (~> 5.0) 203 | sdoc (~> 0.4.0) 204 | sidekiq (~> 3.3.4) 205 | spring 206 | turbolinks 207 | uglifier (>= 1.3.0) 208 | web-console (~> 2.0) 209 | -------------------------------------------------------------------------------- /Guardfile: -------------------------------------------------------------------------------- 1 | # A sample Guardfile 2 | # More info at https://github.com/guard/guard#readme 3 | 4 | ## Uncomment and set this to only include directories you want to watch 5 | # directories %w(app lib config test spec features) 6 | 7 | ## Uncomment to clear the screen before every task 8 | # clearing :on 9 | 10 | ## Guard internally checks for changes in the Guardfile and exits. 11 | ## If you want Guard to automatically start up again, run guard in a 12 | ## shell loop, e.g.: 13 | ## 14 | ## $ while bundle exec guard; do echo "Restarting Guard..."; done 15 | ## 16 | ## Note: if you are using the `directories` clause above and you are not 17 | ## watching the project directory ('.'), then you will want to move 18 | ## the Guardfile to a watched dir and symlink it back, e.g. 19 | # 20 | # $ mkdir config 21 | # $ mv Guardfile config/ 22 | # $ ln -s config/Guardfile . 23 | # 24 | # and, you'll have to watch "config/Guardfile" instead of "Guardfile" 25 | 26 | guard :minitest do 27 | # with Minitest::Unit 28 | watch(%r{^test/(.*)\/?test_(.*)\.rb$}) 29 | watch(%r{^lib/(.*/)?([^/]+)\.rb$}) { |m| "test/#{m[1]}test_#{m[2]}.rb" } 30 | watch(%r{^test/test_helper\.rb$}) { 'test' } 31 | 32 | # with Minitest::Spec 33 | # watch(%r{^spec/(.*)_spec\.rb$}) 34 | # watch(%r{^lib/(.+)\.rb$}) { |m| "spec/#{m[1]}_spec.rb" } 35 | # watch(%r{^spec/spec_helper\.rb$}) { 'spec' } 36 | 37 | # Rails 4 38 | # watch(%r{^app/(.+)\.rb$}) { |m| "test/#{m[1]}_test.rb" } 39 | # watch(%r{^app/controllers/application_controller\.rb$}) { 'test/controllers' } 40 | # watch(%r{^app/controllers/(.+)_controller\.rb$}) { |m| "test/integration/#{m[1]}_test.rb" } 41 | # watch(%r{^app/views/(.+)_mailer/.+}) { |m| "test/mailers/#{m[1]}_mailer_test.rb" } 42 | # watch(%r{^lib/(.+)\.rb$}) { |m| "test/lib/#{m[1]}_test.rb" } 43 | # watch(%r{^test/.+_test\.rb$}) 44 | # watch(%r{^test/test_helper\.rb$}) { 'test' } 45 | 46 | # Rails < 4 47 | # watch(%r{^app/controllers/(.*)\.rb$}) { |m| "test/functional/#{m[1]}_test.rb" } 48 | # watch(%r{^app/helpers/(.*)\.rb$}) { |m| "test/helpers/#{m[1]}_test.rb" } 49 | # watch(%r{^app/models/(.*)\.rb$}) { |m| "test/unit/#{m[1]}_test.rb" } 50 | end 51 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2015 Roberto Quintanilla 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | 23 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Example of a Rails App with Docker Compose for development 2 | 3 | This is an example of how I use [Docker](https://docs.docker.com/) and 4 | [Docker Compose](https://docs.docker.com/compose/) to develop my rails apps. 5 | 6 | It is an ideal project setup for new and experienced developers alike, and allows 7 | to a nearly trouble-free environment setup in their development machines. 8 | 9 | In this example we'll fire up a full app environment consisting of the following: 10 | 11 | - A [postgres container](https://github.com/vovimayhem/docker-compose-rails-dev-example/blob/master/docker-compose.yml#L17) 12 | which hosts the app's database. 13 | - A [redis container](https://github.com/vovimayhem/docker-compose-rails-dev-example/blob/master/docker-compose.yml#L38) 14 | which hosts the app's job queue. 15 | - An example Rails app running 3 processes on separate containers: 16 | - A [`jobs` container](https://github.com/vovimayhem/docker-compose-rails-dev-example/blob/master/docker-compose.yml#L51) 17 | running the app's job processor ([Sidekiq](http://sidekiq.org/)). 18 | - A [`worker` container](https://github.com/vovimayhem/docker-compose-rails-dev-example/blob/master/docker-compose.yml#L105) 19 | running the Rails web server. 20 | - A [`test` container](https://github.com/vovimayhem/docker-compose-rails-dev-example/blob/master/docker-compose.yml#L113) 21 | running [guard](http://guardgem.org/), which fires tests automatically whenever a change in the 22 | app code is detected. 23 | 24 | You'll need to follow some instructions to get this example running: 25 | 26 | ## 1: Requirements 27 | 28 | You must have [Docker](https://docs.docker.com/) and 29 | [Docker Compose](https://docs.docker.com/compose/) on your machine. 30 | 31 | You can install these with: 32 | * [Docker for Mac](https://docs.docker.com/docker-for-mac/) on macOS 33 | * [Docker for Windows](https://docs.docker.com/docker-for-windows) on Windows 34 | 35 | ## 2: 'Clone & Run' the project 36 | 37 | You should clone the project into a conveniently-named directory, as this repo's name is big enough 38 | to make typing docker/compose commands tiresome, should the need arise: 39 | 40 | ``` 41 | git clone https://github.com/vovimayhem/docker-compose-rails-dev-example.git example \ 42 | && cd example \ 43 | && docker-compose up -d web jobs \ 44 | && docker-compose logs -f 45 | ``` 46 | 47 | Watch it as it starts all the containers, and how the app database is initialized upon the first run 48 | before starting the rails web server. 49 | 50 | ## 3: NOT ANYMORE: Initialize the app environment in an initial run: 51 | 52 | Originally there was some setup to be made prior to running the app. Fortunately a lot of changes 53 | happened since then, and although the dotenv file is recommended, it is not required for the project 54 | to run immediately after cloning. 55 | 56 | If you need to, however, you can copy the contents of the example dotenv file into a file 57 | called `.env`: 58 | 59 | ``` 60 | cp example.env .env 61 | ``` 62 | 63 | Docker Compose now reads the `/.env` file by default, if it exists. You can still add other dotenv 64 | files and reference them in the `docker-compose.yml` file, but that would require an additional step 65 | than the coveted 'clone and run' project setup. 66 | 67 | ## 4: Bring online the project's containers 68 | 69 | ``` 70 | docker-compose up -d 71 | ``` 72 | 73 | That's it! Check the running app web interface: [http://localhost:3000](http://localhost:3000) 74 | 75 | ## 5: Next steps 76 | 77 | I usually do some tricks to aid in my day to day activities: 78 | 79 | ### Modifying the `/etc/hosts` file for rails apps that depend on subdomains 80 | Pretty self-explanatory. 81 | 82 | ### Generate aliases to the docker-compose command... or use Plis 83 | 84 | The `docker-compose` commands are a bit lengthy for my taste, so I started generating some bash 85 | aliases... eventually I created a small Go app called [Plis](https://github.com/IcaliaLabs/plis) 86 | which besides having a smalled character count, it allows me to attach to any container using the 87 | service name, which is a must to debug the app using `byebug`: 88 | 89 | ``` 90 | plis start web && plis attach web 91 | # => Converts the commands to `docker-compose up -d web && docker attach example_web_1` 92 | ``` 93 | 94 | ### Create a new rails project with Docker 95 | [Create a new rails app using docker](doc/CREATE_A_NEW_RAILS_PROJECT.md), if you find yourself in 96 | the need of creating a new app, and you are already running this example project. 97 | 98 | ## 6: Example app ruby version 99 | 100 | It uses MRI ruby 2.2.6. I'll make some branches using different engines (i.e. Rubinius, JRuby) 101 | 102 | ## 7: More Information 103 | 104 | * [Everything Docker](https://docs.docker.com) 105 | * GIANT ROBOTS SMASHING INTO OTHER GIANT ROBOTS (Seriously, [thoughtbot](https://github.com/thoughtbot)?) 106 | * [Introducing 'heroku docker:release': Build & Deploy Heroku Apps with Docker](https://blog.heroku.com/archives/2015/5/5/introducing_heroku_docker_release_build_deploy_heroku_apps_with_docker) 107 | geez! These guys are on EVERYTHING! 108 | 109 | ## 8: Contributing 110 | 111 | I'd love to receive feedback & suggestions from everyone. If you see something off, 112 | or think there's a better way to do something this thing does, please do: 113 | 114 | * Fork the original repository. 115 | * Make your changes in a topic branch. 116 | * Send a pull request. 117 | 118 | # License 119 | 120 | This is free software, and may be redistributed under the terms specified in the [LICENSE](LICENSE) file. 121 | -------------------------------------------------------------------------------- /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 File.expand_path('../config/application', __FILE__) 5 | 6 | Rails.application.load_tasks 7 | -------------------------------------------------------------------------------- /app/assets/images/.keep: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vovimayhem/docker-compose-rails-dev-example/6653b1c87db63debce5ceb399467e916af58ee26/app/assets/images/.keep -------------------------------------------------------------------------------- /app/assets/javascripts/application.js: -------------------------------------------------------------------------------- 1 | // This is a manifest file that'll be compiled into application.js, which will include all the files 2 | // listed below. 3 | // 4 | // Any JavaScript/Coffee file within this directory, lib/assets/javascripts, vendor/assets/javascripts, 5 | // or any plugin's vendor/assets/javascripts directory can be referenced here using a relative path. 6 | // 7 | // It's not advisable to add code directly here, but if you do, it'll appear at the bottom of the 8 | // compiled file. 9 | // 10 | // Read Sprockets README (https://github.com/rails/sprockets#sprockets-directives) for details 11 | // about supported directives. 12 | // 13 | //= require jquery 14 | //= require jquery_ujs 15 | //= require turbolinks 16 | //= require_tree . 17 | -------------------------------------------------------------------------------- /app/assets/javascripts/posts.coffee: -------------------------------------------------------------------------------- 1 | # Place all the behaviors and hooks related to the matching controller here. 2 | # All this logic will automatically be available in application.js. 3 | # You can use CoffeeScript in this file: http://coffeescript.org/ 4 | -------------------------------------------------------------------------------- /app/assets/stylesheets/application.css: -------------------------------------------------------------------------------- 1 | /* 2 | * This is a manifest file that'll be compiled into application.css, which will include all the files 3 | * listed below. 4 | * 5 | * Any CSS and SCSS file within this directory, lib/assets/stylesheets, vendor/assets/stylesheets, 6 | * or any plugin's vendor/assets/stylesheets directory can be referenced here using a relative path. 7 | * 8 | * You're free to add application-wide styles to this file and they'll appear at the bottom of the 9 | * compiled file so the styles you add here take precedence over styles defined in any styles 10 | * defined in the other CSS/SCSS files in this directory. It is generally better to create a new 11 | * file per style scope. 12 | * 13 | *= require_tree . 14 | *= require_self 15 | */ 16 | -------------------------------------------------------------------------------- /app/assets/stylesheets/posts.scss: -------------------------------------------------------------------------------- 1 | // Place all the styles related to the posts controller here. 2 | // They will automatically be included in application.css. 3 | // You can use Sass (SCSS) here: http://sass-lang.com/ 4 | -------------------------------------------------------------------------------- /app/assets/stylesheets/scaffolds.scss: -------------------------------------------------------------------------------- 1 | body { 2 | background-color: #fff; 3 | color: #333; 4 | font-family: verdana, arial, helvetica, sans-serif; 5 | font-size: 13px; 6 | line-height: 18px; 7 | } 8 | 9 | p, ol, ul, td { 10 | font-family: verdana, arial, helvetica, sans-serif; 11 | font-size: 13px; 12 | line-height: 18px; 13 | } 14 | 15 | pre { 16 | background-color: #eee; 17 | padding: 10px; 18 | font-size: 11px; 19 | } 20 | 21 | a { 22 | color: #000; 23 | &:visited { 24 | color: #666; 25 | } 26 | &:hover { 27 | color: #fff; 28 | background-color: #000; 29 | } 30 | } 31 | 32 | div { 33 | &.field, &.actions { 34 | margin-bottom: 10px; 35 | } 36 | } 37 | 38 | #notice { 39 | color: green; 40 | } 41 | 42 | .field_with_errors { 43 | padding: 2px; 44 | background-color: red; 45 | display: table; 46 | } 47 | 48 | #error_explanation { 49 | width: 450px; 50 | border: 2px solid red; 51 | padding: 7px; 52 | padding-bottom: 0; 53 | margin-bottom: 20px; 54 | background-color: #f0f0f0; 55 | h2 { 56 | text-align: left; 57 | font-weight: bold; 58 | padding: 5px 5px 5px 15px; 59 | font-size: 12px; 60 | margin: -7px; 61 | margin-bottom: 0px; 62 | background-color: #c00; 63 | color: #fff; 64 | } 65 | ul li { 66 | font-size: 12px; 67 | list-style: square; 68 | } 69 | } 70 | -------------------------------------------------------------------------------- /app/controllers/application_controller.rb: -------------------------------------------------------------------------------- 1 | class ApplicationController < ActionController::Base 2 | # Prevent CSRF attacks by raising an exception. 3 | # For APIs, you may want to use :null_session instead. 4 | protect_from_forgery with: :exception 5 | end 6 | -------------------------------------------------------------------------------- /app/controllers/concerns/.keep: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vovimayhem/docker-compose-rails-dev-example/6653b1c87db63debce5ceb399467e916af58ee26/app/controllers/concerns/.keep -------------------------------------------------------------------------------- /app/controllers/posts_controller.rb: -------------------------------------------------------------------------------- 1 | class PostsController < ApplicationController 2 | before_action :set_post, only: [:show, :edit, :update, :destroy] 3 | 4 | # GET /posts 5 | # GET /posts.json 6 | def index 7 | @posts = Post.all 8 | end 9 | 10 | # GET /posts/1 11 | # GET /posts/1.json 12 | def show 13 | end 14 | 15 | # GET /posts/new 16 | def new 17 | @post = Post.new 18 | end 19 | 20 | # GET /posts/1/edit 21 | def edit 22 | end 23 | 24 | # POST /posts 25 | # POST /posts.json 26 | def create 27 | @post = Post.new(post_params) 28 | 29 | respond_to do |format| 30 | if @post.save 31 | format.html { redirect_to @post, notice: 'Post was successfully created.' } 32 | format.json { render :show, status: :created, location: @post } 33 | else 34 | format.html { render :new } 35 | format.json { render json: @post.errors, status: :unprocessable_entity } 36 | end 37 | end 38 | end 39 | 40 | # PATCH/PUT /posts/1 41 | # PATCH/PUT /posts/1.json 42 | def update 43 | respond_to do |format| 44 | if @post.update(post_params) 45 | format.html { redirect_to @post, notice: 'Post was successfully updated.' } 46 | format.json { render :show, status: :ok, location: @post } 47 | else 48 | format.html { render :edit } 49 | format.json { render json: @post.errors, status: :unprocessable_entity } 50 | end 51 | end 52 | end 53 | 54 | # DELETE /posts/1 55 | # DELETE /posts/1.json 56 | def destroy 57 | @post.destroy 58 | respond_to do |format| 59 | format.html { redirect_to posts_url, notice: 'Post was successfully destroyed.' } 60 | format.json { head :no_content } 61 | end 62 | end 63 | 64 | private 65 | # Use callbacks to share common setup or constraints between actions. 66 | def set_post 67 | @post = Post.find(params[:id]) 68 | end 69 | 70 | # Never trust parameters from the scary internet, only allow the white list through. 71 | def post_params 72 | params.require(:post).permit(:title, :body) 73 | end 74 | end 75 | -------------------------------------------------------------------------------- /app/helpers/application_helper.rb: -------------------------------------------------------------------------------- 1 | module ApplicationHelper 2 | end 3 | -------------------------------------------------------------------------------- /app/helpers/posts_helper.rb: -------------------------------------------------------------------------------- 1 | module PostsHelper 2 | end 3 | -------------------------------------------------------------------------------- /app/mailers/.keep: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vovimayhem/docker-compose-rails-dev-example/6653b1c87db63debce5ceb399467e916af58ee26/app/mailers/.keep -------------------------------------------------------------------------------- /app/models/.keep: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vovimayhem/docker-compose-rails-dev-example/6653b1c87db63debce5ceb399467e916af58ee26/app/models/.keep -------------------------------------------------------------------------------- /app/models/concerns/.keep: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vovimayhem/docker-compose-rails-dev-example/6653b1c87db63debce5ceb399467e916af58ee26/app/models/concerns/.keep -------------------------------------------------------------------------------- /app/models/post.rb: -------------------------------------------------------------------------------- 1 | class Post < ActiveRecord::Base 2 | end 3 | -------------------------------------------------------------------------------- /app/views/layouts/application.html.erb: -------------------------------------------------------------------------------- 1 | 2 | 3 |
4 |<%= notice %>
2 | 3 |Title | 9 |Body | 10 |11 | | ||
---|---|---|---|---|
<%= post.title %> | 18 |<%= post.body %> | 19 |<%= link_to 'Show', post %> | 20 |<%= link_to 'Edit', edit_post_path(post) %> | 21 |<%= link_to 'Destroy', post, method: :delete, data: { confirm: 'Are you sure?' } %> | 22 |
<%= notice %>
2 | 3 |4 | Title: 5 | <%= @post.title %> 6 |
7 | 8 |9 | Body: 10 | <%= @post.body %> 11 |
12 | 13 | <%= link_to 'Edit', edit_post_path(@post) %> | 14 | <%= link_to 'Back', posts_path %> 15 | -------------------------------------------------------------------------------- /app/views/posts/show.json.jbuilder: -------------------------------------------------------------------------------- 1 | json.extract! @post, :id, :title, :body, :created_at, :updated_at 2 | -------------------------------------------------------------------------------- /bin/bundle: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env ruby 2 | ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../../Gemfile', __FILE__) 3 | load Gem.bin_path('bundler', 'bundle') 4 | -------------------------------------------------------------------------------- /bin/check_or_setup_db: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env ruby 2 | 3 | # This script is used in the development environment with Docker to check if the 4 | # app database exists, and runs the database setup if it doesn't, as it is the 5 | # case when the project runs for the first time on the development machine. 6 | # 7 | # We are using this custom script instead of running the 8 | # `rake db:version || rake db:setup` commands, as that currently leaves a 9 | # couple of small ruby zombie processes running in the app container: 10 | require "rubygems" 11 | require "rake" 12 | require "bundler" 13 | 14 | Bundler.setup(:default) 15 | 16 | require "active_record" 17 | 18 | exit begin 19 | connection_tries ||= 3 20 | ActiveRecord::Base.establish_connection && ActiveRecord::Migrator.current_version 21 | 0 22 | rescue PG::ConnectionBad 23 | unless (connection_tries -= 1).zero? 24 | puts "Retrying DB connection #{connection_tries} more times..." 25 | sleep ENV.fetch("APP_SETUP_WAIT", "5").to_i 26 | retry 27 | end 28 | 1 29 | rescue ActiveRecord::NoDatabaseError 30 | 31 | include ActiveRecord::Tasks 32 | 33 | DatabaseTasks.root = File.expand_path "../..", __FILE__ 34 | DatabaseTasks.db_dir = File.join DatabaseTasks.root, "db" 35 | DatabaseTasks.env = ENV.fetch "ENV", ENV.fetch("RAILS_ENV", "development") 36 | 37 | # The App database seeder: 38 | DatabaseTasks.seed_loader = (Class.new do 39 | def load_seed 40 | seed_file_path = File.join DatabaseTasks.db_dir, "seeds.rb" 41 | raise "Seed file '#{seed_file_path}' does not exist" unless File.file?(seed_file_path) 42 | load seed_file_path 43 | end 44 | end).new 45 | 46 | # Add model dirs to the autoload_paths for the seeder to run smoothly: 47 | ActiveSupport::Dependencies.autoload_paths << File.join(DatabaseTasks.root, "app", "models", "concerns") 48 | ActiveSupport::Dependencies.autoload_paths << File.join(DatabaseTasks.root, "app", "models") 49 | 50 | return 2 unless DatabaseTasks.create_current 51 | 52 | if File.exist?(File.join(DatabaseTasks.root, "db", "structure.sql")) 53 | return 3 unless DatabaseTasks.load_schema_current :sql 54 | else 55 | return 3 unless DatabaseTasks.load_schema_current :ruby 56 | end 57 | 58 | return 4 unless DatabaseTasks.load_seed 59 | 0 60 | ensure 61 | ActiveRecord::Base.clear_all_connections! 62 | end 63 | -------------------------------------------------------------------------------- /bin/dumpdb: -------------------------------------------------------------------------------- 1 | #! /bin/bash 2 | 3 | # For use on the postgres container only. 4 | set -e 5 | 6 | : ${DB_NAME:=$1} 7 | : ${DB_DUMP_PATH:=$2} 8 | 9 | pg_dump -U postgres --compress=9 --no-privileges --no-owner --format=custom \ 10 | --file=$DB_DUMP_PATH $DB_NAME 11 | -------------------------------------------------------------------------------- /bin/rails: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env ruby 2 | APP_PATH = File.expand_path('../../config/application', __FILE__) 3 | require_relative '../config/boot' 4 | require 'rails/commands' 5 | -------------------------------------------------------------------------------- /bin/rake: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env ruby 2 | require_relative '../config/boot' 3 | require 'rake' 4 | Rake.application.run 5 | -------------------------------------------------------------------------------- /bin/restoredb: -------------------------------------------------------------------------------- 1 | #! /bin/bash 2 | 3 | # For use on the postgres container only. 4 | set -e 5 | 6 | : ${DB_NAME:=$1} 7 | : ${DB_DUMP_PATH:=$2} 8 | 9 | dropdb -U postgres -e --if-exists $1 && \ 10 | createdb -U postgres $1 && \ 11 | pg_restore -U postgres --dbname=$1 \ 12 | --clean --no-owner --no-privileges --verbose --jobs=2 \ 13 | $2 14 | -------------------------------------------------------------------------------- /bin/setup: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env ruby 2 | require 'pathname' 3 | 4 | # path to your application root. 5 | APP_ROOT = Pathname.new File.expand_path('../../', __FILE__) 6 | 7 | Dir.chdir APP_ROOT do 8 | # This script is a starting point to setup your application. 9 | # Add necessary setup steps to this file: 10 | 11 | puts "== Installing dependencies ==" 12 | system "gem install bundler --conservative" 13 | system "bundle check || bundle install" 14 | 15 | # puts "\n== Copying sample files ==" 16 | # unless File.exist?("config/database.yml") 17 | # system "cp config/database.yml.sample config/database.yml" 18 | # end 19 | 20 | puts "\n== Preparing database ==" 21 | system "bin/rake db:setup" 22 | 23 | puts "\n== Removing old logs and tempfiles ==" 24 | system "rm -f log/*" 25 | system "rm -rf tmp/cache" 26 | 27 | puts "\n== Restarting application server ==" 28 | system "touch tmp/restart.txt" 29 | end 30 | -------------------------------------------------------------------------------- /config.ru: -------------------------------------------------------------------------------- 1 | # This file is used by Rack-based servers to start the application. 2 | 3 | require ::File.expand_path('../config/environment', __FILE__) 4 | run Rails.application 5 | -------------------------------------------------------------------------------- /config/application.rb: -------------------------------------------------------------------------------- 1 | require File.expand_path('../boot', __FILE__) 2 | 3 | require 'rails/all' 4 | 5 | # Require the gems listed in Gemfile, including any gems 6 | # you've limited to :test, :development, or :production. 7 | Bundler.require(*Rails.groups) 8 | 9 | module MyApp 10 | class Application < Rails::Application 11 | # Settings in config/environments/* take precedence over those specified here. 12 | # Application configuration should go into files in config/initializers 13 | # -- all .rb files in that directory are automatically loaded. 14 | 15 | # Set Time.zone default to the specified zone and make Active Record auto-convert to this zone. 16 | # Run "rake -D time" for a list of tasks for finding time zone names. Default is UTC. 17 | # config.time_zone = 'Central Time (US & Canada)' 18 | 19 | # The default locale is :en and all translations from config/locales/*.rb,yml are auto loaded. 20 | # config.i18n.load_path += Dir[Rails.root.join('my', 'locales', '*.{rb,yml}').to_s] 21 | # config.i18n.default_locale = :de 22 | 23 | # Do not swallow errors in after_commit/after_rollback callbacks. 24 | config.active_record.raise_in_transactional_callbacks = true 25 | end 26 | end 27 | -------------------------------------------------------------------------------- /config/boot.rb: -------------------------------------------------------------------------------- 1 | ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../../Gemfile', __FILE__) 2 | 3 | require 'bundler/setup' # Set up gems listed in the Gemfile. 4 | -------------------------------------------------------------------------------- /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 | encoding: unicode 19 | # Schema search path. The server defaults to $user,public 20 | schema_search_path: partitioning,public 21 | # For details on connection pooling, see rails configuration guide 22 | # http://guides.rubyonrails.org/configuring.html#database-pooling 23 | pool: <%= ENV.fetch("RAILS_MAX_THREADS") { 5 } %> 24 | # Minimum log levels, in increasing order: 25 | # debug5, debug4, debug3, debug2, debug1, 26 | # log, notice, warning, error, fatal, and panic 27 | # Defaults to warning. 28 | min_messages: log 29 | 30 | development: 31 | <<: *default 32 | 33 | # Warning: The database defined as "test" will be erased and 34 | # re-generated from your development database when you run "rake". 35 | # Do not set this db to the same as development or production. 36 | test: 37 | <<: *default 38 | 39 | # Production database configuration - bigger pool size, lower log level: 40 | production: 41 | <<: *default 42 | min_messages: notice 43 | -------------------------------------------------------------------------------- /config/environment.rb: -------------------------------------------------------------------------------- 1 | # Load the Rails application. 2 | require File.expand_path('../application', __FILE__) 3 | 4 | # Initialize the Rails application. 5 | Rails.application.initialize! 6 | -------------------------------------------------------------------------------- /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 and disable caching. 13 | config.consider_all_requests_local = true 14 | config.action_controller.perform_caching = false 15 | 16 | # Don't care if the mailer can't send. 17 | config.action_mailer.raise_delivery_errors = false 18 | 19 | # Print deprecation notices to the Rails logger. 20 | config.active_support.deprecation = :log 21 | 22 | # Raise an error on page load if there are pending migrations. 23 | config.active_record.migration_error = :page_load 24 | 25 | # Debug mode disables concatenation and preprocessing of assets. 26 | # This option may cause significant delays in view rendering with a large 27 | # number of complex assets. 28 | config.assets.debug = true 29 | 30 | # Asset digests allow you to set far-future HTTP expiration dates on all assets, 31 | # yet still be able to expire them through the digest params. 32 | config.assets.digest = true 33 | 34 | # Adds additional error checking when serving assets at runtime. 35 | # Checks for improperly declared sprockets dependencies. 36 | # Raises helpful error messages. 37 | config.assets.raise_runtime_errors = true 38 | 39 | # Raises error for missing translations 40 | # config.action_view.raise_on_missing_translations = true 41 | end 42 | -------------------------------------------------------------------------------- /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 | # Enable Rack::Cache to put a simple HTTP cache in front of your application 18 | # Add `rack-cache` to your Gemfile before enabling this. 19 | # For large-scale production use, consider using a caching reverse proxy like 20 | # NGINX, varnish or squid. 21 | # config.action_dispatch.rack_cache = true 22 | 23 | # Disable serving static files from the `/public` folder by default since 24 | # Apache or NGINX already handles this. 25 | config.serve_static_files = ENV['RAILS_SERVE_STATIC_FILES'].present? 26 | 27 | # Compress JavaScripts and CSS. 28 | config.assets.js_compressor = :uglifier 29 | # config.assets.css_compressor = :sass 30 | 31 | # Do not fallback to assets pipeline if a precompiled asset is missed. 32 | config.assets.compile = false 33 | 34 | # Asset digests allow you to set far-future HTTP expiration dates on all assets, 35 | # yet still be able to expire them through the digest params. 36 | config.assets.digest = true 37 | 38 | # `config.assets.precompile` and `config.assets.version` have moved to config/initializers/assets.rb 39 | 40 | # Specifies the header that your server uses for sending files. 41 | # config.action_dispatch.x_sendfile_header = 'X-Sendfile' # for Apache 42 | # config.action_dispatch.x_sendfile_header = 'X-Accel-Redirect' # for NGINX 43 | 44 | # Force all access to the app over SSL, use Strict-Transport-Security, and use secure cookies. 45 | # config.force_ssl = true 46 | 47 | # Use the lowest log level to ensure availability of diagnostic information 48 | # when problems arise. 49 | config.log_level = :debug 50 | 51 | # Prepend all log lines with the following tags. 52 | # config.log_tags = [ :subdomain, :uuid ] 53 | 54 | # Use a different logger for distributed setups. 55 | # config.logger = ActiveSupport::TaggedLogging.new(SyslogLogger.new) 56 | 57 | # Use a different cache store in production. 58 | # config.cache_store = :mem_cache_store 59 | 60 | # Enable serving of images, stylesheets, and JavaScripts from an asset server. 61 | # config.action_controller.asset_host = 'http://assets.example.com' 62 | 63 | # Ignore bad email addresses and do not raise email delivery errors. 64 | # Set this to true and configure the email server for immediate delivery to raise delivery errors. 65 | # config.action_mailer.raise_delivery_errors = false 66 | 67 | # Enable locale fallbacks for I18n (makes lookups for any locale fall back to 68 | # the I18n.default_locale when a translation cannot be found). 69 | config.i18n.fallbacks = true 70 | 71 | # Send deprecation notices to registered listeners. 72 | config.active_support.deprecation = :notify 73 | 74 | # Use default logging formatter so that PID and timestamp are not suppressed. 75 | config.log_formatter = ::Logger::Formatter.new 76 | 77 | # Do not dump schema after migrations. 78 | config.active_record.dump_schema_after_migration = false 79 | end 80 | -------------------------------------------------------------------------------- /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 static file server for tests with Cache-Control for performance. 16 | config.serve_static_files = true 17 | config.static_cache_control = 'public, max-age=3600' 18 | 19 | # Show full error reports and disable caching. 20 | config.consider_all_requests_local = true 21 | config.action_controller.perform_caching = false 22 | 23 | # Raise exceptions instead of rendering exception templates. 24 | config.action_dispatch.show_exceptions = false 25 | 26 | # Disable request forgery protection in test environment. 27 | config.action_controller.allow_forgery_protection = false 28 | 29 | # Tell Action Mailer not to deliver emails to the real world. 30 | # The :test delivery method accumulates sent emails in the 31 | # ActionMailer::Base.deliveries array. 32 | config.action_mailer.delivery_method = :test 33 | 34 | # Randomize the order test cases are executed. 35 | config.active_support.test_order = :random 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 | -------------------------------------------------------------------------------- /config/initializers/assets.rb: -------------------------------------------------------------------------------- 1 | # Be sure to restart your server when you modify this file. 2 | 3 | # Version of your assets, change this if you want to expire all your assets. 4 | Rails.application.config.assets.version = '1.0' 5 | 6 | # Add additional assets to the asset load path 7 | # Rails.application.config.assets.paths << Emoji.images_path 8 | 9 | # Precompile additional assets. 10 | # application.js, application.css, and all non-JS/CSS in app/assets folder are already added. 11 | # Rails.application.config.assets.precompile += %w( search.js ) 12 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /config/initializers/cookies_serializer.rb: -------------------------------------------------------------------------------- 1 | # Be sure to restart your server when you modify this file. 2 | 3 | Rails.application.config.action_dispatch.cookies_serializer = :json 4 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /config/initializers/session_store.rb: -------------------------------------------------------------------------------- 1 | # Be sure to restart your server when you modify this file. 2 | 3 | Rails.application.config.session_store :cookie_store, key: '_my_app_session' 4 | -------------------------------------------------------------------------------- /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] if respond_to?(:wrap_parameters) 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 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /config/routes.rb: -------------------------------------------------------------------------------- 1 | Rails.application.routes.draw do 2 | resources :posts 3 | # The priority is based upon order of creation: first created -> highest priority. 4 | # See how all your routes lay out with "rake routes". 5 | 6 | # You can have the root of your site routed with "root" 7 | # root 'welcome#index' 8 | 9 | # Example of regular route: 10 | # get 'products/:id' => 'catalog#view' 11 | 12 | # Example of named route that can be invoked with purchase_url(id: product.id) 13 | # get 'products/:id/purchase' => 'catalog#purchase', as: :purchase 14 | 15 | # Example resource route (maps HTTP verbs to controller actions automatically): 16 | # resources :products 17 | 18 | # Example resource route with options: 19 | # resources :products do 20 | # member do 21 | # get 'short' 22 | # post 'toggle' 23 | # end 24 | # 25 | # collection do 26 | # get 'sold' 27 | # end 28 | # end 29 | 30 | # Example resource route with sub-resources: 31 | # resources :products do 32 | # resources :comments, :sales 33 | # resource :seller 34 | # end 35 | 36 | # Example resource route with more complex sub-resources: 37 | # resources :products do 38 | # resources :comments 39 | # resources :sales do 40 | # get 'recent', on: :collection 41 | # end 42 | # end 43 | 44 | # Example resource route with concerns: 45 | # concern :toggleable do 46 | # post 'toggle' 47 | # end 48 | # resources :posts, concerns: :toggleable 49 | # resources :photos, concerns: :toggleable 50 | 51 | # Example resource route within a namespace: 52 | # namespace :admin do 53 | # # Directs /admin/products/* to Admin::ProductsController 54 | # # (app/controllers/admin/products_controller.rb) 55 | # resources :products 56 | # end 57 | end 58 | -------------------------------------------------------------------------------- /db/dumps/README.md: -------------------------------------------------------------------------------- 1 | # Database Dumps Folder 2 | 3 | Use this folder to store dumps from databases. 4 | 5 | If your'e spinning up this project with the provided docker-compose file, 6 | this folder is already mounted in the database container. 7 | -------------------------------------------------------------------------------- /db/migrate/20150508192001_create_posts.rb: -------------------------------------------------------------------------------- 1 | class CreatePosts < ActiveRecord::Migration 2 | def change 3 | create_table :posts do |t| 4 | t.string :title 5 | t.text :body 6 | 7 | t.timestamps null: false 8 | end 9 | end 10 | end 11 | -------------------------------------------------------------------------------- /db/postgres-setup.sql: -------------------------------------------------------------------------------- 1 | -- This file is a reference to replicate a freshly-provisioned database like most 2 | -- database service providers - such as Heroku Postgres, for example. 3 | 4 | -- I think including these instructions as rails migrations is not a good fit, 5 | -- since you already get this taken care of by the database provider anyways. 6 | -- I'm open to discussion, however :) 7 | 8 | -- Enable HStore: 9 | CREATE EXTENSION hstore; 10 | 11 | -- Enable DBLink: 12 | CREATE EXTENSION dblink; 13 | 14 | -- Create the project databases: 15 | CREATE DATABASE xmple_development; 16 | CREATE DATABASE xmple_test; 17 | -------------------------------------------------------------------------------- /db/schema.rb: -------------------------------------------------------------------------------- 1 | # encoding: UTF-8 2 | # This file is auto-generated from the current state of the database. Instead 3 | # of editing this file, please use the migrations feature of Active Record to 4 | # incrementally modify your database, and then regenerate this schema definition. 5 | # 6 | # Note that this schema.rb definition is the authoritative source for your 7 | # database schema. If you need to create the application database on another 8 | # system, you should be using db:schema:load, not running all the migrations 9 | # from scratch. The latter is a flawed and unsustainable approach (the more migrations 10 | # you'll amass, the slower it'll run and the greater likelihood for issues). 11 | # 12 | # It's strongly recommended that you check this file into your version control system. 13 | 14 | ActiveRecord::Schema.define(version: 20150508192001) do 15 | 16 | # These are extensions that must be enabled in order to support this database 17 | enable_extension "plpgsql" 18 | enable_extension "hstore" 19 | enable_extension "dblink" 20 | 21 | create_table "posts", force: :cascade do |t| 22 | t.string "title" 23 | t.text "body" 24 | t.datetime "created_at", null: false 25 | t.datetime "updated_at", null: false 26 | end 27 | 28 | end 29 | -------------------------------------------------------------------------------- /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 rake db:seed (or created alongside the db with db:setup). 3 | # 4 | # Examples: 5 | # 6 | # cities = City.create([{ name: 'Chicago' }, { name: 'Copenhagen' }]) 7 | # Mayor.create(name: 'Emanuel', city: cities.first) 8 | -------------------------------------------------------------------------------- /dev.Dockerfile: -------------------------------------------------------------------------------- 1 | # 1: Use ruby 2.2.6 as base: 2 | FROM ruby:2.2.6 3 | 4 | # 2: We'll set the application path as the working directory 5 | WORKDIR /usr/src/app 6 | 7 | # 3: We'll set the working dir as HOME and add the app's binaries path to $PATH: 8 | ENV HOME=/usr/src/app PATH=/usr/src/app/bin:$PATH 9 | 10 | # 4: Expose the app web port: 11 | EXPOSE 3000 12 | 13 | # 5: Set the default command: 14 | CMD ["rails", "server", "-b", "0.0.0.0", "-p", "3000"] 15 | 16 | # 6: Install node as a javascript runtime for asset compilation: 17 | # gpg keys listed at https://github.com/nodejs/node 18 | RUN set -ex \ 19 | && for key in \ 20 | 9554F04D7259F04124DE6B476D5A82AC7E37093B \ 21 | 94AE36675C464D64BAFA68DD7434390BDBE9B9C5 \ 22 | 0034A06D9D9B0064CE8ADF6BF1747F4AD2306D93 \ 23 | FD3A5288F042B6850C66B31F09FE44734EB7990E \ 24 | 71DCFD284A79C3B38668286BC97EC7A07EDE3FC1 \ 25 | DD8F2338BAE7501E3DD5AC78C273792F7D83545D \ 26 | B9AE9905FFD7803F25714661B63B535A4C206CA9 \ 27 | C4F0DFFF4E8C1A8236409D08E73BC641CC11F4C8 \ 28 | ; do \ 29 | gpg --keyserver ha.pool.sks-keyservers.net --recv-keys "$key"; \ 30 | done \ 31 | && export NPM_CONFIG_LOGLEVEL=info \ 32 | && export NODE_VERSION=6.3.1 \ 33 | && curl -SLO "https://nodejs.org/dist/v$NODE_VERSION/node-v$NODE_VERSION-linux-x64.tar.xz" \ 34 | && curl -SLO "https://nodejs.org/dist/v$NODE_VERSION/SHASUMS256.txt.asc" \ 35 | && gpg --batch --decrypt --output SHASUMS256.txt SHASUMS256.txt.asc \ 36 | && grep " node-v$NODE_VERSION-linux-x64.tar.xz\$" SHASUMS256.txt | sha256sum -c - \ 37 | && tar -xJf "node-v$NODE_VERSION-linux-x64.tar.xz" -C /usr/local --strip-components=1 \ 38 | && rm "node-v$NODE_VERSION-linux-x64.tar.xz" SHASUMS256.txt.asc SHASUMS256.txt 39 | 40 | # 7: Install the current project gems - they can be safely changed later during 41 | # development via `bundle install` or `bundle update`: 42 | ADD Gemfile* /usr/src/app/ 43 | RUN set -ex && bundle --retry 3 44 | -------------------------------------------------------------------------------- /development-entrypoint: -------------------------------------------------------------------------------- 1 | #! /bin/bash 2 | 3 | # The Docker App Container's development entrypoint. 4 | # This is a script used by the project's Docker development environment to 5 | # setup the app containers and databases upon runnning. 6 | set -e 7 | 8 | : ${APP_PATH:="/app/user"} 9 | : ${APP_TEMP_PATH:="$APP_PATH/tmp"} 10 | : ${APP_SETUP_LOCK:="$APP_TEMP_PATH/setup.lock"} 11 | : ${APP_SETUP_WAIT:="5"} 12 | 13 | # 1: Define the functions lock and unlock our app containers setup processes: 14 | function lock_setup { mkdir -p $APP_TEMP_PATH && touch $APP_SETUP_LOCK; } 15 | function unlock_setup { rm -rf $APP_SETUP_LOCK; } 16 | function wait_setup { echo "Waiting for app setup to finish..."; sleep $APP_SETUP_WAIT; } 17 | 18 | # 2: 'Unlock' the setup process if the script exits prematurely: 19 | trap unlock_setup HUP INT QUIT KILL TERM EXIT 20 | 21 | # 3: Specify a default command, in case it wasn't issued: 22 | if [ -z "$1" ]; then set -- rails server -p 3000 -b 0.0.0.0 "$@"; fi 23 | 24 | # 4: Run the app setup only if the requested command requires it: 25 | if [[ "$1" = "rails" || "$1" = "sidekiq" ]] 26 | then 27 | # 5: Wait until the setup 'lock' file no longer exists: 28 | while [ -f $APP_SETUP_LOCK ]; do wait_setup; done 29 | 30 | # 6: 'Lock' the setup process, to prevent a race condition when the project's 31 | # app containers will try to install gems and setup the database concurrently: 32 | lock_setup 33 | 34 | # 7: Check if the database exists, or setup the database if it doesn't, as it is 35 | # the case when the project runs for the first time. 36 | # 37 | # We'll use a custom script `check_or_setup_db` (inside our app's `bin` folder), 38 | # instead of running `rake db:version || rake db:setup`, as running that command 39 | # (at least on rails 4.2.4) will leave a couple of small ruby zombie processes 40 | # running in the container: 41 | bundle exec check_or_setup_db 42 | 43 | # 8: 'Unlock' the setup process: 44 | unlock_setup 45 | 46 | # 9: If the command to execute is 'rails server', then force it to write the pid 47 | # file into an private directory - suddenly killing and removing app containers 48 | # without this would leave a pidfile in the project's tmp dir, preventing containers 49 | # from starting up on further attempts: 50 | if [[ ("$1" = "rails" || ("$1" = "bundle" && "$2" = "exec" && "$3" = "rails")) && (("$2" = "s" || "$2" = "server") || ("$4" = "s" || "$4" = "server")) ]]; then 51 | rm -rf "${APP_TEMP_PATH}/pids/server.pid"; 52 | fi 53 | fi 54 | 55 | # 10: Execute the given or default command: 56 | exec "$@" 57 | -------------------------------------------------------------------------------- /doc/CREATE_A_NEW_RAILS_PROJECT.md: -------------------------------------------------------------------------------- 1 | # Create a new Rails project using Docker 2 | 3 | While this docker-compose project is really good for firing up an already-existing Rails app, 4 | creating a new Rails app with it is a lot easier using plain docker. 5 | 6 | There should be a lot of rails project templates out there, but here we'll go *"back to basics"*. 7 | We'll install rails temporarily on a one-off container (using the `docker` command directly, instead 8 | of `docker-compose`), from which we'll call the rails project generator: 9 | 10 | ```bash 11 | # Start a new, one-off ruby container running a bash shell. It should have the 12 | # current directory mounted at '/usr/src': 13 | docker run --rm -ti -v $(pwd):/usr/src -w /usr/src ruby:2.2.6 bash 14 | 15 | # Now that your'e running bash inside our one-off container, install rails and generate the app. 16 | gem install rails --no-rdoc --no-ri && rails new my-app --database=postgresql 17 | 18 | # Exit the one-off container. The container should be removed automatically. 19 | exit 20 | ``` 21 | 22 | Now you have your new rails project code created and available in your host. 23 | -------------------------------------------------------------------------------- /doc/DOCKER_SETUP_ON_LINUX.md: -------------------------------------------------------------------------------- 1 | # Recommended Docker setup on Linux 2 | 3 | FYI: I always use Linux Mint and everything works out hassle-free. Here's how to 4 | do it for Ubuntu-like distros: 5 | 6 | ## 1. Install Docker 7 | 8 | *Please refer to the [Official Docker installation guides](http://docs.docker.com/installation/#installation) 9 | for updated instructions for your linux distribution.* 10 | 11 | ```bash 12 | # Log into your Ubuntu installation as a user with sudo privileges. 13 | 14 | # Verify that you have wget installed. 15 | which wget 16 | 17 | # If wget isn't installed, install it after updating your manager: 18 | 19 | sudo apt-get update $ sudo apt-get install wget 20 | 21 | # Get the latest Docker package. 22 | 23 | wget -qO- https://get.docker.com/ | sh 24 | 25 | # Verify docker is installed correctly. 26 | 27 | sudo docker run hello-world 28 | ``` 29 | 30 | ## 2. Adding your user to the docker group 31 | 32 | Using sudo everytime is kind of tiresome. Do yourself a favor and add your user 33 | to the `docker` group: 34 | 35 | ```bash 36 | # Please replace 'your_user' with your actual user name: 37 | sudo usermod -a -G docker your_user 38 | 39 | # Check that you belong to the docker group: 40 | id 41 | # You should be able to see the docker group entry. If not... 42 | ``` 43 | 44 | *CAVEAT* I've seen some Ubuntu systems that require you to logout and then log 45 | back in in order for you to appear belonging in the `docker` group. 46 | 47 | ## 3. Install Docker Compose 48 | 49 | *Please refer to the [Official Docker Compose installation guide](https://docs.docker.com/compose/install/#install-compose) 50 | for updated instructions.* 51 | 52 | To install Docker Compose, run the following command: 53 | 54 | ```bash 55 | curl -L https://github.com/docker/compose/releases/download/1.2.0/docker-compose-`uname -s`-`uname -m` > /usr/local/bin/docker-compose 56 | chmod +x /usr/local/bin/docker-compose 57 | ``` 58 | -------------------------------------------------------------------------------- /doc/DOCKER_SETUP_ON_MAC.md: -------------------------------------------------------------------------------- 1 | # Recommended Docker setup on Mac OSX 2 | 3 | Since Linux containers can't run directly on Mac yet, you'll need to use 4 | virtualization software in order to fire up a virtual server running a lightweight 5 | OS special for running Docker - That's taken care of with [Docker Machine](https://docs.docker.com/machine/) 6 | 7 | *Be advised* that the official Docker docs still instructs to fire up a virtual 8 | machine running boot2docker manually, and makes you set up a bunch of environment 9 | variables by yourself. *Disregard that information*, since 10 | [Docker Machine](https://docs.docker.com/machine/) already takes care of this! 11 | 12 | ## 1. Install virtualization software 13 | 14 | Although [Docker Machine](https://docs.docker.com/machine/) supports 15 | [Virtualbox](https://www.virtualbox.org/) for creating and managing Docker hosts, 16 | *I strongly advise against using it*, since it doesn't work well quite often, and 17 | when it does, offers inferior performance than [VMWare Fusion 7+](http://www.vmware.com/products/fusion), 18 | which I do recommend. 19 | 20 | ## 2. Install Docker Machine 21 | 22 | *Please refer to the [Official Docker Machine installation guide](https://docs.docker.com/machine/#osx-and-linux) 23 | for updated instructions.* 24 | 25 | ```bash 26 | # Install Docker Machine: 27 | curl -L https://github.com/docker/machine/releases/download/v0.2.0/docker-machine_darwin-amd64 > /usr/local/bin/docker-machine 28 | chmod +x /usr/local/bin/docker-machine 29 | 30 | # Install the Docker client, which issues the docker commands to your virtualized docker host: 31 | curl https://get.docker.com/builds/Darwin/x86_64/docker-latest > /usr/local/bin/docker 32 | ``` 33 | 34 | ## 3. Create a virtualized Docker host with Docker Machine 35 | 36 | ```bash 37 | # Create a virtualized Docker host called 'dev' with VMWare Fusion: 38 | docker-machine --debug create --driver vmwarefusion dev 39 | 40 | # If you encounter problems with Docker server/client version mismatch 41 | # (that's the case with the current version - remember it's still in Beta), 42 | # try specifying the boot2docker image url: 43 | docker-machine create --driver vmwarefusion \ 44 | --vmwarefusion-boot2docker-url https://github.com/cloudnativeapps/boot2docker/releases/download/v1.6.0-vmw/boot2docker-1.6.0-vmw.iso \ 45 | dev 46 | 47 | # Add the required environment variables to your terminal environment: 48 | eval $(docker-machine env dev) 49 | ``` 50 | 51 | ## 4. Install Docker Compose 52 | 53 | *Please refer to the [Official Docker Compose installation guide](https://docs.docker.com/compose/install/#install-compose) 54 | for updated instructions.* 55 | 56 | Try installing via curl first - You'll need an updated Python install for this: 57 | 58 | ```bash 59 | curl -L https://github.com/docker/compose/releases/download/1.2.0/docker-compose-`uname -s`-`uname -m` > /usr/local/bin/docker-compose 60 | chmod +x /usr/local/bin/docker-compose 61 | 62 | # Check your installation: 63 | docker-compose --version 64 | ``` 65 | 66 | If for any reason this does not work, try installing via PIP: 67 | ```bash 68 | sudo pip install -U docker-compose 69 | ``` 70 | -------------------------------------------------------------------------------- /doc/DOCKER_SETUP_ON_WINDOWS.md: -------------------------------------------------------------------------------- 1 | # Recommended Docker setup on Windows 2 | 3 | You are very brave trying this on a Windows machine! 4 | -------------------------------------------------------------------------------- /docker-compose.yml: -------------------------------------------------------------------------------- 1 | version: '2.1' 2 | 3 | volumes: 4 | # We'll define a volume that will store the data from the postgres databases: 5 | postgres-data: 6 | driver: local 7 | # The rabbitmq data store volume 8 | redis-data: 9 | driver: local 10 | # We'll also define a volume that will store gems installed manually after the initial app 11 | # development image build process: 12 | app-gems: 13 | driver: local 14 | 15 | services: 16 | # Our PostgreSQL service: 17 | postgres: 18 | image: postgres:9.6.1 19 | ports: 20 | # We'll bind our host's port 5432 to postgres's port 5432, so we can use 21 | # our database IDEs with it: 22 | - 5432:5432 23 | volumes: 24 | # Mount the DB dumps folder into the container, to be able to create & access database dumps: 25 | - ./db/dumps:/db/dumps 26 | # Mount out tmp folder, we might want to have access to something there during development: 27 | - ./tmp:/tmp 28 | # Mount our 'restoredb' script: 29 | - ./bin/restoredb:/bin/restoredb:ro 30 | # Mount our 'dumpdb' script: 31 | - ./bin/dumpdb:/bin/dumpdb:ro 32 | # We'll mount the 'postgres-data' volume into the location Postgres stores it's data: 33 | - postgres-data:/var/lib/postgresql/data 34 | environment: 35 | POSTGRES_PASSWORD: 3x4mpl3 36 | 37 | # Our Redis service: 38 | redis: 39 | image: redis:3.2.4-alpine 40 | ports: 41 | # We'll bind our host's port 6379 to redis's port 6379, so we can use 42 | # Redis Desktop Manager (or other tools) with it: 43 | - 6379:6379 44 | volumes: 45 | # We'll mount the 'redis-data' volume into the location redis stores it's data: 46 | - redis-data:/var/lib/redis 47 | command: redis-server --appendonly yes 48 | 49 | # Application: ----------------------------------------------------------------- 50 | # We'll also use this configuration (&app_base) for the web and test containers: 51 | jobs: &app_base 52 | build: 53 | context: . 54 | dockerfile: dev.Dockerfile 55 | image: vovimayhem/docker-compose-rails-dev-example:development 56 | entrypoint: /usr/src/app/development-entrypoint 57 | 58 | # The command this container will run - in this case, this container will run our sidekiq 59 | # process: 60 | command: sidekiq -c 25 -q default 61 | 62 | volumes: 63 | # Mount our app code directory (".") into our app containers at the 64 | # "/usr/src/app" folder: 65 | - .:/usr/src/app 66 | 67 | # Mount the 'gems' volume on the folder that stores bundled gems: 68 | - app-gems:/usr/local/bundle 69 | 70 | # Keep the stdin open, so we can attach to our app container's process and do things such as 71 | # byebug, etc: 72 | stdin_open: true 73 | 74 | # Enable sending signals (CTRL+C, CTRL+P + CTRL+Q) into the container: 75 | tty: true 76 | 77 | # Link to our postgres and redis containers, so they can be visible from our 78 | # app containers: 79 | links: 80 | # We'll include a link to the 'db' (postgres) container, making it visible from the container 81 | # using the 'postgres.local' hostname (which is not necessary, but I'm doing it here to 82 | # illustrate that you can play with this): 83 | - postgres:db.local 84 | 85 | # We'll include a link to the 'keyval' (redis) container, making it 86 | # visible from the container using the 'keyval.local' hostname: 87 | - redis:keyval.local 88 | 89 | environment: &app_environment 90 | # The postgres database URL: 91 | DATABASE_URL: postgres://postgres:3x4mpl3@db.local:5432/example_development 92 | 93 | # The redis URL: 94 | REDIS_URL: redis://keyval.local:6379 95 | 96 | # Sidekiq configuration: 97 | SIDEKIQ_CONCURRENCY: 5 98 | SIDEKIQ_TIMEOUT: 10 99 | 100 | # Run the app in the 'development' environment: 101 | RACK_ENV: development 102 | RAILS_ENV: development 103 | 104 | # This container will run the rails web server: 105 | web: 106 | # We'll copy from &app_base, and override: 107 | <<: *app_base 108 | command: rails server -p 3000 -b 0.0.0.0 109 | ports: 110 | - "3000:3000" # Bind our host's port 3000 to the app port 3000: 111 | 112 | # App Guard: Keeps running tests on a separate process: 113 | test: 114 | # We'll copy from &app_base, and override: 115 | <<: *app_base 116 | command: guard start --no-bundler-warning --no-interactions 117 | environment: 118 | <<: *app_environment 119 | # PostgreSQL Test Database: 120 | DATABASE_URL: postgres://postgres:3x4mpl3@db.local:5432/example_test 121 | # Run the app in the 'test' environment, instead of the default 'developent' 122 | RACK_ENV: test 123 | RAILS_ENV: test 124 | -------------------------------------------------------------------------------- /lib/assets/.keep: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vovimayhem/docker-compose-rails-dev-example/6653b1c87db63debce5ceb399467e916af58ee26/lib/assets/.keep -------------------------------------------------------------------------------- /lib/tasks/.keep: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vovimayhem/docker-compose-rails-dev-example/6653b1c87db63debce5ceb399467e916af58ee26/lib/tasks/.keep -------------------------------------------------------------------------------- /lib/templates/dotenv.env: -------------------------------------------------------------------------------- 1 | ################################################################################ 2 | # .env File Template 3 | # 4 | # This file is a template with several environment variables that could 5 | # contain sensitive data, such as passwords, API secrets, etc. 6 | # 7 | # This file SHOULD NOT be edited directly (this is just a template!), as it is 8 | # meant to be checked-in in version control. The file that should be edited is 9 | # located at '/.env'. 10 | ################################################################################ 11 | 12 | SOME_SERVICE_API_KEY=SOME_API_KEY 13 | SOME_SERVICE_API_SECRET=SOME_API_SECRET 14 | 15 | # Let's set a default rails app secret here... please update with a secret 16 | # generated with 'rake secret'! 17 | SECRET_KEY_BASE=5d20b3c9e6e99509bc687263b7506b0480b625876af957a698fe71d22aee8dd1d1540b51b795b0cacf8a38ee22e9cfe6bb2a6eb6cadebfe480c90c982fc352de 18 | -------------------------------------------------------------------------------- /lib/templates/secrets.yml.erb: -------------------------------------------------------------------------------- 1 | <% 2 | raise "No RACK_ENV or RAILS_ENV found" unless ENV["RAILS_ENV"] || ENV["RACK_ENV"] 3 | raise "No SECRET_KEY_BASE found" unless ENV['SECRET_KEY_BASE'] 4 | %>--- 5 | <%= ENV["RAILS_ENV"] || ENV["RACK_ENV"] %>: 6 | secret_key_base: "<%= ENV['SECRET_KEY_BASE'] %>" 7 | -------------------------------------------------------------------------------- /log/.keep: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vovimayhem/docker-compose-rails-dev-example/6653b1c87db63debce5ceb399467e916af58ee26/log/.keep -------------------------------------------------------------------------------- /public/404.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 |You may have mistyped the address or the page may have moved.
63 |If you are the application owner check the logs for more information.
65 |Maybe you tried to change something you didn't have access to.
63 |If you are the application owner check the logs for more information.
65 |If you are the application owner check the logs for more information.
64 |