├── .gitignore ├── CONTRIBUTING.md ├── README.md ├── backend ├── .dockerignore ├── .gitignore ├── .rspec ├── Dockerfile ├── Gemfile ├── Gemfile.lock ├── Rakefile ├── app │ ├── channels │ │ └── application_cable │ │ │ ├── channel.rb │ │ │ └── connection.rb │ ├── controllers │ │ ├── api │ │ │ └── status_controller.rb │ │ └── application_controller.rb │ ├── jobs │ │ ├── application_job.rb │ │ └── test_job.rb │ ├── mailers │ │ └── application_mailer.rb │ ├── models │ │ ├── application_record.rb │ │ └── user.rb │ └── views │ │ └── layouts │ │ ├── mailer.html.erb │ │ └── mailer.text.erb ├── bin │ ├── bundle │ ├── rails │ ├── rake │ ├── setup │ ├── spring │ └── 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 │ │ ├── devise_token_auth.rb │ │ ├── filter_parameter_logging.rb │ │ ├── inflections.rb │ │ ├── mime_types.rb │ │ └── wrap_parameters.rb │ ├── locales │ │ └── en.yml │ ├── puma.rb │ ├── routes.rb │ ├── secrets.yml │ └── spring.rb ├── db │ ├── migrate │ │ └── 20180306161431_devise_token_auth_create_users.rb │ ├── schema.rb │ └── seeds.rb ├── docker-entrypoint.sh ├── public │ └── robots.txt └── spec │ └── spec_helper.rb ├── config └── nginx │ └── nginx.conf ├── docker-compose.yml └── frontend ├── .babelrc ├── .dockerignore ├── .gitignore ├── Dockerfile ├── README.md ├── config ├── env.js ├── jest │ ├── cssTransform.js │ └── fileTransform.js ├── paths.js ├── polyfills.js ├── webpack.config.dev.js ├── webpack.config.prod.js └── webpackDevServer.config.js ├── package.json ├── public ├── favicon.ico ├── index.html └── manifest.json ├── scripts ├── build.js ├── start.js └── test.js ├── src ├── actions │ └── app.js ├── components │ └── sample.js ├── constants │ ├── action-types.js │ └── config.js ├── containers │ ├── app.css │ └── app.js ├── index.js ├── reducers │ └── app.js ├── registerServiceWorker.js ├── routes │ └── index.js ├── selectors │ └── app.js ├── shared │ ├── action-types.js │ └── api-client.js └── store │ └── index.js └── yarn.lock /.gitignore: -------------------------------------------------------------------------------- 1 | terraform.tfvars 2 | .terraform 3 | *.tfstate* 4 | .DS_Store 5 | -------------------------------------------------------------------------------- /CONTRIBUTING.md: -------------------------------------------------------------------------------- 1 | # Contributing to the boilerplate 2 | 3 | Please clone this repo, and follow the setup steps to get the project up and running. 4 | 5 | If you would like to add a feature, then generally I'll be all for it. But ensure that your feature is as general purpose and universal as possible. This project is intended to be a starter kit, so I want to keep it simple. 6 | 7 | Once you think you have completed your work, please submit a pull request from your branch to this repo. 8 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Technologies 2 | - Docker compose 3 | - Postgresql 4 | - Nginx proxy 5 | - Ruby on Rails 5 (API only) 6 | - React + Redux + Redux Thunk + Reselect 7 | - Sidekiq in a Worker container. 8 | 9 | # Setup && running the application 10 | 11 | Before you run the application for the first time, you must create the database and run migrations: 12 | 13 | ``` 14 | docker-compose run backend rake db:create db:migrate 15 | ``` 16 | 17 | Or alternatively, log in via bash and run the commands there: 18 | ``` 19 | docker-compose run backend bash 20 | root@1c5e8aedd21a:/usr/src/backend-app# rake db:create 21 | Created database 'backend_development' 22 | Created database 'backend_test' 23 | root@1c5e8aedd21a:/usr/src/backend-app# rake db:migrate 24 | == 20180306161431 DeviseTokenAuthCreateUsers: migrating ======================= 25 | -- create_table(:users) 26 | -> 0.0164s 27 | -- add_index(:users, :email, {:unique=>true}) 28 | -> 0.0088s 29 | -- add_index(:users, [:uid, :provider], {:unique=>true}) 30 | -> 0.0078s 31 | -- add_index(:users, :reset_password_token, {:unique=>true}) 32 | -> 0.0092s 33 | -- add_index(:users, :confirmation_token, {:unique=>true}) 34 | -> 0.0070s 35 | == 20180306161431 DeviseTokenAuthCreateUsers: migrated (0.0497s) ============== 36 | ``` 37 | 38 | ## Docker on OS X 39 | 40 | If you are using Docker for Mac, you must setup the directory `/Users` to be able to be bind mounted into Docker containers by going to Docker for Mac preferences, and then File Sharing, and ensuring that `/Users` is listed there. 41 | 42 | ## Running 43 | 44 | Running the app (and navigate to `http://localhost:8080`): 45 | 46 | ``` 47 | docker-compose up --build 48 | ``` 49 | 50 | Accessing the bash console for the React container (for installing new Yarn / NPM packages): 51 | 52 | ``` 53 | docker-compose run frontend bash 54 | ``` 55 | 56 | Accessing the bash console for the Rails app (for `rails c`): 57 | 58 | ``` 59 | docker-compose run backend bash 60 | => rails c 61 | ``` 62 | 63 | Creating the database: 64 | 65 | ``` 66 | docker-compose run backend rake db:setup 67 | ``` 68 | 69 | Running migrations: 70 | 71 | ``` 72 | docker-compose run backend rake db:migrate 73 | ``` 74 | 75 | Killing the application (and remove data volumes): 76 | 77 | ``` 78 | docker-compose down --volumes 79 | ``` 80 | 81 | Running backend RSpec tests: 82 | 83 | ``` 84 | docker-compose run backend rspec 85 | ``` 86 | 87 | Running Jest (JS) specs: 88 | 89 | ``` 90 | docker-compose run frontend yarn test 91 | ``` 92 | 93 | # Architecture 94 | 95 | The application can be built using `docker-compose up --build`. 96 | 97 | There are several interlinking services orchestrated in individual containers: `db` (the postgresql instance), `backend` (the Rails api), `frontend` (the React application) and finally the `nginx` proxy container which pulls everything together and which is the only container which exposes any ports to the host machine. 98 | 99 | The nginx conf can be found at `/config/nginx/nginx.conf`. 100 | 101 | The Rails application is proxied from port `3000` to `http://localhost:8080/api` and the Webpack / React application is proxied from port `4000` to the root at `http://localhost:8080/`. 102 | 103 | The React application was originally created using `create-react-app` but was ejected to expose the full configuration. 104 | 105 | # Using on your own project 106 | 107 | Nuke the git directory: 108 | 109 | ``` 110 | rm -rf .git 111 | ``` 112 | 113 | Start again: 114 | 115 | ``` 116 | git init 117 | git add . 118 | git commit -m "Initial commit" 119 | ``` 120 | 121 | Do some work / profit 122 | 123 | # Recommended dep versions 124 | 125 | I develop using Ubuntu, so your mileage may vary on other operating systems like OS X and Windows. 126 | 127 | Docker Compose: 128 | 129 | ``` 130 | ➜ react-rails-docker git:(master) docker-compose -v 131 | docker-compose version 1.19.0, build 9e633ef 132 | ``` 133 | 134 | Docker: 135 | 136 | ``` 137 | ➜ react-rails-docker git:(master) ✗ docker -v 138 | Docker version 17.12.1-ce, build 7390fc6 139 | ``` 140 | 141 | Ruby version (through rbenv): 142 | 143 | ``` 144 | ➜ react-rails-docker git:(master) ✗ ruby -v 145 | ruby 2.5.0p0 (2017-12-25 revision 61468) [x86_64-linux] 146 | ``` 147 | -------------------------------------------------------------------------------- /backend/.dockerignore: -------------------------------------------------------------------------------- 1 | tmp/* 2 | log/* 3 | db/*.sqlite3 4 | .git 5 | .byebug_history 6 | 7 | # Dont copy the docker ignore to the VD. Makes no sense 8 | .dockerignore -------------------------------------------------------------------------------- /backend/.gitignore: -------------------------------------------------------------------------------- 1 | # See https://help.github.com/articles/ignoring-files for more about ignoring files. 2 | # 3 | # If you find yourself ignoring temporary files generated by your text editor 4 | # or operating system, you probably want to add a global ignore instead: 5 | # git config --global core.excludesfile '~/.gitignore_global' 6 | 7 | # Ignore bundler config. 8 | /.bundle 9 | 10 | # Ignore all logfiles and tempfiles. 11 | /log/* 12 | /tmp/* 13 | 14 | .byebug_history 15 | -------------------------------------------------------------------------------- /backend/.rspec: -------------------------------------------------------------------------------- 1 | --require spec_helper 2 | -------------------------------------------------------------------------------- /backend/Dockerfile: -------------------------------------------------------------------------------- 1 | FROM ruby:2.3.3 2 | RUN apt-get update -qq && apt-get install -y --no-install-recommends build-essential libpq-dev 3 | RUN apt-get clean 4 | RUN rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/* 5 | RUN gem install bundler 6 | 7 | RUN mkdir /usr/src/backend-app 8 | WORKDIR /usr/src/backend-app 9 | 10 | RUN echo "gem: --no-rdoc --no-ri" > /etc/gemrc 11 | ADD Gemfile /usr/src/backend-app/Gemfile 12 | ADD Gemfile.lock /usr/src/backend-app/Gemfile.lock 13 | RUN bundle install --jobs 20 --retry 5 14 | ADD . /usr/src/backend-app 15 | EXPOSE 3000 16 | 17 | COPY ./docker-entrypoint.sh / 18 | RUN chmod +x /docker-entrypoint.sh 19 | 20 | ENTRYPOINT ["/docker-entrypoint.sh"] 21 | CMD ["rails", "s", "-b", "0.0.0.0"] 22 | -------------------------------------------------------------------------------- /backend/Gemfile: -------------------------------------------------------------------------------- 1 | source 'https://rubygems.org' 2 | 3 | git_source(:github) do |repo_name| 4 | repo_name = "#{repo_name}/#{repo_name}" unless repo_name.include?("/") 5 | "https://github.com/#{repo_name}.git" 6 | end 7 | 8 | gem 'rails', '~> 5.1.5' 9 | gem 'pg', '>= 0.18', '< 2.0' 10 | gem 'puma', '~> 3.7' 11 | 12 | gem 'devise_token_auth' 13 | gem 'omniauth' 14 | gem 'redis' 15 | gem 'sidekiq' 16 | gem 'connection_pool' 17 | 18 | group :development, :test do 19 | gem 'pry' 20 | gem 'pry-rails' 21 | gem 'rspec' 22 | end 23 | 24 | group :development do 25 | gem 'listen', '>= 3.0.5', '< 3.2' 26 | # Spring speeds up development by keeping your application running in the background. Read more: https://github.com/rails/spring 27 | gem 'spring' 28 | gem 'spring-watcher-listen', '~> 2.0.0' 29 | end 30 | 31 | # Windows does not include zoneinfo files, so bundle the tzinfo-data gem 32 | gem 'tzinfo-data', platforms: [:mingw, :mswin, :x64_mingw, :jruby] 33 | -------------------------------------------------------------------------------- /backend/Gemfile.lock: -------------------------------------------------------------------------------- 1 | GEM 2 | remote: https://rubygems.org/ 3 | specs: 4 | actioncable (5.1.6) 5 | actionpack (= 5.1.6) 6 | nio4r (~> 2.0) 7 | websocket-driver (~> 0.6.1) 8 | actionmailer (5.1.6) 9 | actionpack (= 5.1.6) 10 | actionview (= 5.1.6) 11 | activejob (= 5.1.6) 12 | mail (~> 2.5, >= 2.5.4) 13 | rails-dom-testing (~> 2.0) 14 | actionpack (5.1.6) 15 | actionview (= 5.1.6) 16 | activesupport (= 5.1.6) 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.1.6) 22 | activesupport (= 5.1.6) 23 | builder (~> 3.1) 24 | erubi (~> 1.4) 25 | rails-dom-testing (~> 2.0) 26 | rails-html-sanitizer (~> 1.0, >= 1.0.3) 27 | activejob (5.1.6) 28 | activesupport (= 5.1.6) 29 | globalid (>= 0.3.6) 30 | activemodel (5.1.6) 31 | activesupport (= 5.1.6) 32 | activerecord (5.1.6) 33 | activemodel (= 5.1.6) 34 | activesupport (= 5.1.6) 35 | arel (~> 8.0) 36 | activesupport (5.1.6) 37 | concurrent-ruby (~> 1.0, >= 1.0.2) 38 | i18n (>= 0.7, < 2) 39 | minitest (~> 5.1) 40 | tzinfo (~> 1.1) 41 | arel (8.0.0) 42 | bcrypt (3.1.11) 43 | builder (3.2.3) 44 | coderay (1.1.2) 45 | concurrent-ruby (1.1.5) 46 | connection_pool (2.2.1) 47 | crass (1.0.5) 48 | devise (4.4.3) 49 | bcrypt (~> 3.0) 50 | orm_adapter (~> 0.1) 51 | railties (>= 4.1.0, < 6.0) 52 | responders 53 | warden (~> 1.2.3) 54 | devise_token_auth (0.1.43) 55 | devise (> 3.5.2, < 4.5) 56 | rails (< 6) 57 | diff-lcs (1.3) 58 | erubi (1.7.1) 59 | ffi (1.11.1) 60 | globalid (0.4.1) 61 | activesupport (>= 4.2.0) 62 | hashie (3.5.7) 63 | i18n (1.0.0) 64 | concurrent-ruby (~> 1.0) 65 | listen (3.1.5) 66 | rb-fsevent (~> 0.9, >= 0.9.4) 67 | rb-inotify (~> 0.9, >= 0.9.7) 68 | ruby_dep (~> 1.2) 69 | loofah (2.3.1) 70 | crass (~> 1.0.2) 71 | nokogiri (>= 1.5.9) 72 | mail (2.7.0) 73 | mini_mime (>= 0.1.1) 74 | method_source (0.9.0) 75 | mini_mime (1.0.0) 76 | mini_portile2 (2.4.0) 77 | minitest (5.11.3) 78 | nio4r (2.3.0) 79 | nokogiri (1.10.5) 80 | mini_portile2 (~> 2.4.0) 81 | omniauth (1.8.1) 82 | hashie (>= 3.4.6, < 3.6.0) 83 | rack (>= 1.6.2, < 3) 84 | orm_adapter (0.5.0) 85 | pg (1.0.0) 86 | pry (0.11.3) 87 | coderay (~> 1.1.0) 88 | method_source (~> 0.9.0) 89 | pry-rails (0.3.6) 90 | pry (>= 0.10.4) 91 | puma (3.11.3) 92 | rack (2.0.8) 93 | rack-protection (2.0.1) 94 | rack 95 | rack-test (1.0.0) 96 | rack (>= 1.0, < 3) 97 | rails (5.1.6) 98 | actioncable (= 5.1.6) 99 | actionmailer (= 5.1.6) 100 | actionpack (= 5.1.6) 101 | actionview (= 5.1.6) 102 | activejob (= 5.1.6) 103 | activemodel (= 5.1.6) 104 | activerecord (= 5.1.6) 105 | activesupport (= 5.1.6) 106 | bundler (>= 1.3.0) 107 | railties (= 5.1.6) 108 | sprockets-rails (>= 2.0.0) 109 | rails-dom-testing (2.0.3) 110 | activesupport (>= 4.2.0) 111 | nokogiri (>= 1.6) 112 | rails-html-sanitizer (1.0.4) 113 | loofah (~> 2.2, >= 2.2.2) 114 | railties (5.1.6) 115 | actionpack (= 5.1.6) 116 | activesupport (= 5.1.6) 117 | method_source 118 | rake (>= 0.8.7) 119 | thor (>= 0.18.1, < 2.0) 120 | rake (12.3.1) 121 | rb-fsevent (0.10.3) 122 | rb-inotify (0.9.10) 123 | ffi (>= 0.5.0, < 2) 124 | redis (4.0.1) 125 | responders (2.4.0) 126 | actionpack (>= 4.2.0, < 5.3) 127 | railties (>= 4.2.0, < 5.3) 128 | rspec (3.7.0) 129 | rspec-core (~> 3.7.0) 130 | rspec-expectations (~> 3.7.0) 131 | rspec-mocks (~> 3.7.0) 132 | rspec-core (3.7.1) 133 | rspec-support (~> 3.7.0) 134 | rspec-expectations (3.7.0) 135 | diff-lcs (>= 1.2.0, < 2.0) 136 | rspec-support (~> 3.7.0) 137 | rspec-mocks (3.7.0) 138 | diff-lcs (>= 1.2.0, < 2.0) 139 | rspec-support (~> 3.7.0) 140 | rspec-support (3.7.1) 141 | ruby_dep (1.5.0) 142 | sidekiq (5.1.2) 143 | concurrent-ruby (~> 1.0) 144 | connection_pool (~> 2.2, >= 2.2.0) 145 | rack-protection (>= 1.5.0) 146 | redis (>= 3.3.5, < 5) 147 | spring (2.0.2) 148 | activesupport (>= 4.2) 149 | spring-watcher-listen (2.0.1) 150 | listen (>= 2.7, < 4.0) 151 | spring (>= 1.2, < 3.0) 152 | sprockets (3.7.2) 153 | concurrent-ruby (~> 1.0) 154 | rack (> 1, < 3) 155 | sprockets-rails (3.2.1) 156 | actionpack (>= 4.0) 157 | activesupport (>= 4.0) 158 | sprockets (>= 3.0.0) 159 | thor (0.20.0) 160 | thread_safe (0.3.6) 161 | tzinfo (1.2.5) 162 | thread_safe (~> 0.1) 163 | warden (1.2.7) 164 | rack (>= 1.0) 165 | websocket-driver (0.6.5) 166 | websocket-extensions (>= 0.1.0) 167 | websocket-extensions (0.1.3) 168 | 169 | PLATFORMS 170 | ruby 171 | 172 | DEPENDENCIES 173 | connection_pool 174 | devise_token_auth 175 | listen (>= 3.0.5, < 3.2) 176 | omniauth 177 | pg (>= 0.18, < 2.0) 178 | pry 179 | pry-rails 180 | puma (~> 3.7) 181 | rails (~> 5.1.5) 182 | redis 183 | rspec 184 | sidekiq 185 | spring 186 | spring-watcher-listen (~> 2.0.0) 187 | tzinfo-data 188 | 189 | BUNDLED WITH 190 | 1.16.1 191 | -------------------------------------------------------------------------------- /backend/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 | -------------------------------------------------------------------------------- /backend/app/channels/application_cable/channel.rb: -------------------------------------------------------------------------------- 1 | module ApplicationCable 2 | class Channel < ActionCable::Channel::Base 3 | end 4 | end 5 | -------------------------------------------------------------------------------- /backend/app/channels/application_cable/connection.rb: -------------------------------------------------------------------------------- 1 | module ApplicationCable 2 | class Connection < ActionCable::Connection::Base 3 | end 4 | end 5 | -------------------------------------------------------------------------------- /backend/app/controllers/api/status_controller.rb: -------------------------------------------------------------------------------- 1 | class Api::StatusController < ApplicationController 2 | def index 3 | render json: { status: "OK" } 4 | end 5 | 6 | def job 7 | # Just an example of enqueuing an ActiveJob to the worker container. 8 | # perform_later will cause it to be enqueud to the worker 9 | # whilst perform will cause it to be executed in the current Rails process 10 | TestJob.perform_later 11 | end 12 | end -------------------------------------------------------------------------------- /backend/app/controllers/application_controller.rb: -------------------------------------------------------------------------------- 1 | class ApplicationController < ActionController::API 2 | include DeviseTokenAuth::Concerns::SetUserByToken 3 | end 4 | -------------------------------------------------------------------------------- /backend/app/jobs/application_job.rb: -------------------------------------------------------------------------------- 1 | class ApplicationJob < ActiveJob::Base 2 | queue_as :default 3 | end 4 | -------------------------------------------------------------------------------- /backend/app/jobs/test_job.rb: -------------------------------------------------------------------------------- 1 | class TestJob < ApplicationJob 2 | def perform 3 | # Do some work 4 | end 5 | end -------------------------------------------------------------------------------- /backend/app/mailers/application_mailer.rb: -------------------------------------------------------------------------------- 1 | class ApplicationMailer < ActionMailer::Base 2 | default from: 'from@example.com' 3 | layout 'mailer' 4 | end 5 | -------------------------------------------------------------------------------- /backend/app/models/application_record.rb: -------------------------------------------------------------------------------- 1 | class ApplicationRecord < ActiveRecord::Base 2 | self.abstract_class = true 3 | end 4 | -------------------------------------------------------------------------------- /backend/app/models/user.rb: -------------------------------------------------------------------------------- 1 | class User < ApplicationRecord 2 | # Include default devise modules. 3 | devise :database_authenticatable, :registerable, 4 | :recoverable, :rememberable, :trackable, :validatable, 5 | :confirmable, :omniauthable 6 | include DeviseTokenAuth::Concerns::User 7 | end 8 | -------------------------------------------------------------------------------- /backend/app/views/layouts/mailer.html.erb: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 8 | 9 | 10 | 11 | <%= yield %> 12 | 13 | 14 | -------------------------------------------------------------------------------- /backend/app/views/layouts/mailer.text.erb: -------------------------------------------------------------------------------- 1 | <%= yield %> 2 | -------------------------------------------------------------------------------- /backend/bin/bundle: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env ruby 2 | ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../../Gemfile', __FILE__) 3 | load Gem.bin_path('bundler', 'bundle') 4 | -------------------------------------------------------------------------------- /backend/bin/rails: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env ruby 2 | begin 3 | load File.expand_path('../spring', __FILE__) 4 | rescue LoadError => e 5 | raise unless e.message.include?('spring') 6 | end 7 | APP_PATH = File.expand_path('../config/application', __dir__) 8 | require_relative '../config/boot' 9 | require 'rails/commands' 10 | -------------------------------------------------------------------------------- /backend/bin/rake: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env ruby 2 | begin 3 | load File.expand_path('../spring', __FILE__) 4 | rescue LoadError => e 5 | raise unless e.message.include?('spring') 6 | end 7 | require_relative '../config/boot' 8 | require 'rake' 9 | Rake.application.run 10 | -------------------------------------------------------------------------------- /backend/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 | 22 | # puts "\n== Copying sample files ==" 23 | # unless File.exist?('config/database.yml') 24 | # cp 'config/database.yml.sample', 'config/database.yml' 25 | # end 26 | 27 | puts "\n== Preparing database ==" 28 | system! 'bin/rails db:setup' 29 | 30 | puts "\n== Removing old logs and tempfiles ==" 31 | system! 'bin/rails log:clear tmp:clear' 32 | 33 | puts "\n== Restarting application server ==" 34 | system! 'bin/rails restart' 35 | end 36 | -------------------------------------------------------------------------------- /backend/bin/spring: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env ruby 2 | 3 | # This file loads spring without using Bundler, in order to be fast. 4 | # It gets overwritten when you run the `spring binstub` command. 5 | 6 | unless defined?(Spring) 7 | require 'rubygems' 8 | require 'bundler' 9 | 10 | lockfile = Bundler::LockfileParser.new(Bundler.default_lockfile.read) 11 | spring = lockfile.specs.detect { |spec| spec.name == "spring" } 12 | if spring 13 | Gem.use_paths Gem.dir, Bundler.bundle_path.to_s, *Gem.path 14 | gem 'spring', spring.version 15 | require 'spring/binstub' 16 | end 17 | end 18 | -------------------------------------------------------------------------------- /backend/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 | -------------------------------------------------------------------------------- /backend/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 | -------------------------------------------------------------------------------- /backend/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 | 14 | # Require the gems listed in Gemfile, including any gems 15 | # you've limited to :test, :development, or :production. 16 | Bundler.require(*Rails.groups) 17 | 18 | module Backend 19 | class Application < Rails::Application 20 | # Initialize configuration defaults for originally generated Rails version. 21 | config.load_defaults 5.1 22 | 23 | config.active_job.queue_adapter = :sidekiq 24 | 25 | # Settings in config/environments/* take precedence over those specified here. 26 | # Application configuration should go into files in config/initializers 27 | # -- all .rb files in that directory are automatically loaded. 28 | 29 | # Only loads a smaller set of middleware suitable for API only apps. 30 | # Middleware like session, flash, cookies can be added back manually. 31 | # Skip views, helpers and assets when generating a new resource. 32 | config.api_only = true 33 | end 34 | end 35 | -------------------------------------------------------------------------------- /backend/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 | -------------------------------------------------------------------------------- /backend/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 | channel_prefix: backend_production 11 | -------------------------------------------------------------------------------- /backend/config/database.yml: -------------------------------------------------------------------------------- 1 | default: &default 2 | adapter: postgresql 3 | encoding: unicode 4 | username: postgres 5 | password: secret 6 | host: db 7 | # For details on connection pooling, see Rails configuration guide 8 | # http://guides.rubyonrails.org/configuring.html#database-pooling 9 | pool: <%= ENV.fetch("RAILS_MAX_THREADS") { 5 } %> 10 | 11 | development: 12 | <<: *default 13 | database: backend_development 14 | 15 | # The specified database role being used to connect to postgres. 16 | # To create additional roles in postgres see `$ createuser --help`. 17 | # When left blank, postgres will use the default role. This is 18 | # the same name as the operating system user that initialized the database. 19 | #username: backend 20 | 21 | # The password associated with the postgres role (username). 22 | #password: 23 | 24 | # Connect on a TCP socket. Omitted by default since the client uses a 25 | # domain socket that doesn't need configuration. Windows does not have 26 | # domain sockets, so uncomment these lines. 27 | #host: localhost 28 | 29 | # The TCP port the server listens on. Defaults to 5432. 30 | # If your server runs on a different port number, change accordingly. 31 | #port: 5432 32 | 33 | # Schema search path. The server defaults to $user,public 34 | #schema_search_path: myapp,sharedapp,public 35 | 36 | # Minimum log levels, in increasing order: 37 | # debug5, debug4, debug3, debug2, debug1, 38 | # log, notice, warning, error, fatal, and panic 39 | # Defaults to warning. 40 | #min_messages: notice 41 | 42 | # Warning: The database defined as "test" will be erased and 43 | # re-generated from your development database when you run "rake". 44 | # Do not set this db to the same as development or production. 45 | test: 46 | <<: *default 47 | database: backend_test 48 | 49 | # As with config/secrets.yml, you never want to store sensitive information, 50 | # like your database password, in your source code. If your source code is 51 | # ever seen by anyone, they now have access to your database. 52 | # 53 | # Instead, provide the password as a unix environment variable when you boot 54 | # the app. Read http://guides.rubyonrails.org/configuring.html#configuring-a-database 55 | # for a full rundown on how to provide these environment variables in a 56 | # production deployment. 57 | # 58 | # On Heroku and other platform providers, you may have a full connection URL 59 | # available as an environment variable. For example: 60 | # 61 | # DATABASE_URL="postgres://myuser:mypass@localhost/somedatabase" 62 | # 63 | # You can use this database configuration with: 64 | # 65 | # production: 66 | # url: <%= ENV['DATABASE_URL'] %> 67 | # 68 | production: 69 | <<: *default 70 | database: backend_production 71 | username: backend 72 | password: <%= ENV['BACKEND_DATABASE_PASSWORD'] %> 73 | -------------------------------------------------------------------------------- /backend/config/environment.rb: -------------------------------------------------------------------------------- 1 | # Load the Rails application. 2 | require_relative 'application' 3 | 4 | # Initialize the Rails application. 5 | Rails.application.initialize! 6 | -------------------------------------------------------------------------------- /backend/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=#{2.days.seconds.to_i}" 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 | # Raises error for missing translations 41 | # config.action_view.raise_on_missing_translations = true 42 | 43 | # Use an evented file watcher to asynchronously detect changes in source code, 44 | # routes, locales, etc. This feature depends on the listen gem. 45 | config.file_watcher = ActiveSupport::EventedFileUpdateChecker 46 | end 47 | -------------------------------------------------------------------------------- /backend/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 | # Attempt to read encrypted secrets from `config/secrets.yml.enc`. 18 | # Requires an encryption key in `ENV["RAILS_MASTER_KEY"]` or 19 | # `config/secrets.yml.key`. 20 | config.read_encrypted_secrets = true 21 | 22 | # Disable serving static files from the `/public` folder by default since 23 | # Apache or NGINX already handles this. 24 | config.public_file_server.enabled = ENV['RAILS_SERVE_STATIC_FILES'].present? 25 | 26 | 27 | # Enable serving of images, stylesheets, and JavaScripts from an asset server. 28 | # config.action_controller.asset_host = 'http://assets.example.com' 29 | 30 | # Specifies the header that your server uses for sending files. 31 | # config.action_dispatch.x_sendfile_header = 'X-Sendfile' # for Apache 32 | # config.action_dispatch.x_sendfile_header = 'X-Accel-Redirect' # for NGINX 33 | 34 | # Mount Action Cable outside main process or domain 35 | # config.action_cable.mount_path = nil 36 | # config.action_cable.url = 'wss://example.com/cable' 37 | # config.action_cable.allowed_request_origins = [ 'http://example.com', /http:\/\/example.*/ ] 38 | 39 | # Force all access to the app over SSL, use Strict-Transport-Security, and use secure cookies. 40 | # config.force_ssl = true 41 | 42 | # Use the lowest log level to ensure availability of diagnostic information 43 | # when problems arise. 44 | config.log_level = :debug 45 | 46 | # Prepend all log lines with the following tags. 47 | config.log_tags = [ :request_id ] 48 | 49 | # Use a different cache store in production. 50 | # config.cache_store = :mem_cache_store 51 | 52 | # Use a real queuing backend for Active Job (and separate queues per environment) 53 | # config.active_job.queue_adapter = :resque 54 | # config.active_job.queue_name_prefix = "backend_#{Rails.env}" 55 | config.action_mailer.perform_caching = false 56 | 57 | # Ignore bad email addresses and do not raise email delivery errors. 58 | # Set this to true and configure the email server for immediate delivery to raise delivery errors. 59 | # config.action_mailer.raise_delivery_errors = false 60 | 61 | # Enable locale fallbacks for I18n (makes lookups for any locale fall back to 62 | # the I18n.default_locale when a translation cannot be found). 63 | config.i18n.fallbacks = true 64 | 65 | # Send deprecation notices to registered listeners. 66 | config.active_support.deprecation = :notify 67 | 68 | # Use default logging formatter so that PID and timestamp are not suppressed. 69 | config.log_formatter = ::Logger::Formatter.new 70 | 71 | # Use a different logger for distributed setups. 72 | # require 'syslog/logger' 73 | # config.logger = ActiveSupport::TaggedLogging.new(Syslog::Logger.new 'app-name') 74 | 75 | if ENV["RAILS_LOG_TO_STDOUT"].present? 76 | logger = ActiveSupport::Logger.new(STDOUT) 77 | logger.formatter = config.log_formatter 78 | config.logger = ActiveSupport::TaggedLogging.new(logger) 79 | end 80 | 81 | # Do not dump schema after migrations. 82 | config.active_record.dump_schema_after_migration = false 83 | end 84 | -------------------------------------------------------------------------------- /backend/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=#{1.hour.seconds.to_i}" 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 | -------------------------------------------------------------------------------- /backend/config/initializers/application_controller_renderer.rb: -------------------------------------------------------------------------------- 1 | # Be sure to restart your server when you modify this file. 2 | 3 | # ActiveSupport::Reloader.to_prepare do 4 | # ApplicationController.renderer.defaults.merge!( 5 | # http_host: 'example.org', 6 | # https: false 7 | # ) 8 | # end 9 | -------------------------------------------------------------------------------- /backend/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 | -------------------------------------------------------------------------------- /backend/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 | -------------------------------------------------------------------------------- /backend/config/initializers/devise_token_auth.rb: -------------------------------------------------------------------------------- 1 | DeviseTokenAuth.setup do |config| 2 | # By default the authorization headers will change after each request. The 3 | # client is responsible for keeping track of the changing tokens. Change 4 | # this to false to prevent the Authorization header from changing after 5 | # each request. 6 | # config.change_headers_on_each_request = true 7 | 8 | # By default, users will need to re-authenticate after 2 weeks. This setting 9 | # determines how long tokens will remain valid after they are issued. 10 | # config.token_lifespan = 2.weeks 11 | 12 | # Sets the max number of concurrent devices per user, which is 10 by default. 13 | # After this limit is reached, the oldest tokens will be removed. 14 | # config.max_number_of_devices = 10 15 | 16 | # Sometimes it's necessary to make several requests to the API at the same 17 | # time. In this case, each request in the batch will need to share the same 18 | # auth token. This setting determines how far apart the requests can be while 19 | # still using the same auth token. 20 | # config.batch_request_buffer_throttle = 5.seconds 21 | 22 | # This route will be the prefix for all oauth2 redirect callbacks. For 23 | # example, using the default '/omniauth', the github oauth2 provider will 24 | # redirect successful authentications to '/omniauth/github/callback' 25 | config.omniauth_prefix = "/api/omniauth" 26 | 27 | # By default sending current password is not needed for the password update. 28 | # Uncomment to enforce current_password param to be checked before all 29 | # attribute updates. Set it to :password if you want it to be checked only if 30 | # password is updated. 31 | # config.check_current_password_before_update = :attributes 32 | 33 | # By default we will use callbacks for single omniauth. 34 | # It depends on fields like email, provider and uid. 35 | # config.default_callbacks = true 36 | 37 | # Makes it possible to change the headers names 38 | # config.headers_names = {:'access-token' => 'access-token', 39 | # :'client' => 'client', 40 | # :'expiry' => 'expiry', 41 | # :'uid' => 'uid', 42 | # :'token-type' => 'token-type' } 43 | 44 | # By default, only Bearer Token authentication is implemented out of the box. 45 | # If, however, you wish to integrate with legacy Devise authentication, you can 46 | # do so by enabling this flag. NOTE: This feature is highly experimental! 47 | # config.enable_standard_devise_support = false 48 | end 49 | -------------------------------------------------------------------------------- /backend/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 | -------------------------------------------------------------------------------- /backend/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 | -------------------------------------------------------------------------------- /backend/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 | -------------------------------------------------------------------------------- /backend/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 | -------------------------------------------------------------------------------- /backend/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 | # The following keys must be escaped otherwise they will not be retrieved by 20 | # the default I18n backend: 21 | # 22 | # true, false, on, off, yes, no 23 | # 24 | # Instead, surround them with single quotes. 25 | # 26 | # en: 27 | # 'true': 'foo' 28 | # 29 | # To learn more, please read the Rails Internationalization guide 30 | # available at http://guides.rubyonrails.org/i18n.html. 31 | 32 | en: 33 | hello: "Hello world" 34 | -------------------------------------------------------------------------------- /backend/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 } 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 | # If you are preloading your application and using Active Record, it's 36 | # recommended that you close any connections to the database before workers 37 | # are forked to prevent connection leakage. 38 | # 39 | # before_fork do 40 | # ActiveRecord::Base.connection_pool.disconnect! if defined?(ActiveRecord) 41 | # end 42 | 43 | # The code in the `on_worker_boot` will be called if you are using 44 | # clustered mode by specifying a number of `workers`. After each worker 45 | # process is booted, this block will be run. If you are using the `preload_app!` 46 | # option, you will want to use this block to reconnect to any threads 47 | # or connections that may have been created at application boot, as Ruby 48 | # cannot share connections between processes. 49 | # 50 | # on_worker_boot do 51 | # ActiveRecord::Base.establish_connection if defined?(ActiveRecord) 52 | # end 53 | # 54 | 55 | # Allow puma to be restarted by `rails restart` command. 56 | plugin :tmp_restart 57 | -------------------------------------------------------------------------------- /backend/config/routes.rb: -------------------------------------------------------------------------------- 1 | require 'sidekiq/web' 2 | 3 | Rails.application.routes.draw do 4 | root to: 'api/status#index' 5 | 6 | namespace :api do 7 | mount_devise_token_auth_for 'User', at: 'auth' 8 | 9 | namespace :jobs do 10 | mount Sidekiq::Web => '/ui' 11 | end 12 | 13 | get '/', to: 'status#index' 14 | end 15 | end 16 | -------------------------------------------------------------------------------- /backend/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 | # Shared secrets are available across all environments. 14 | 15 | # shared: 16 | # api_key: a1B2c3D4e5F6 17 | 18 | # Environmental secrets are only available for that specific environment. 19 | 20 | development: 21 | secret_key_base: b1c317da8ce5a4da280e2c80f39f0439ce804840332a234d47bd50edd3cc5ba9dec6a3023423d73168c2b9f5886c585e66ddda6aba73051ac1921c758533a847 22 | 23 | test: 24 | secret_key_base: e368e9a07bea06b78aadbf976746caa825688ac667da2706ed6dcd4f7638f288702beb6ee93a704c1b08b9b8921c14e570e9e52dfb886ec23c9e124b8e6cedc6 25 | 26 | # Do not keep production secrets in the unencrypted secrets file. 27 | # Instead, either read values from the environment. 28 | # Or, use `bin/rails secrets:setup` to configure encrypted secrets 29 | # and move the `production:` environment over there. 30 | 31 | production: 32 | secret_key_base: <%= ENV["SECRET_KEY_BASE"] %> 33 | -------------------------------------------------------------------------------- /backend/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 | -------------------------------------------------------------------------------- /backend/db/migrate/20180306161431_devise_token_auth_create_users.rb: -------------------------------------------------------------------------------- 1 | class DeviseTokenAuthCreateUsers < ActiveRecord::Migration[5.1] 2 | def change 3 | create_table(:users) do |t| 4 | ## Required 5 | t.string :provider, :null => false, :default => "email" 6 | t.string :uid, :null => false, :default => "" 7 | 8 | ## Database authenticatable 9 | t.string :encrypted_password, :null => false, :default => "" 10 | 11 | ## Recoverable 12 | t.string :reset_password_token 13 | t.datetime :reset_password_sent_at 14 | 15 | ## Rememberable 16 | t.datetime :remember_created_at 17 | 18 | ## Trackable 19 | t.integer :sign_in_count, :default => 0, :null => false 20 | t.datetime :current_sign_in_at 21 | t.datetime :last_sign_in_at 22 | t.string :current_sign_in_ip 23 | t.string :last_sign_in_ip 24 | 25 | ## Confirmable 26 | t.string :confirmation_token 27 | t.datetime :confirmed_at 28 | t.datetime :confirmation_sent_at 29 | t.string :unconfirmed_email # Only if using reconfirmable 30 | 31 | ## Lockable 32 | # t.integer :failed_attempts, :default => 0, :null => false # Only if lock strategy is :failed_attempts 33 | # t.string :unlock_token # Only if unlock strategy is :email or :both 34 | # t.datetime :locked_at 35 | 36 | ## User Info 37 | t.string :name 38 | t.string :nickname 39 | t.string :image 40 | t.string :email 41 | 42 | ## Tokens 43 | t.json :tokens 44 | 45 | t.timestamps 46 | end 47 | 48 | add_index :users, :email, unique: true 49 | add_index :users, [:uid, :provider], unique: true 50 | add_index :users, :reset_password_token, unique: true 51 | add_index :users, :confirmation_token, unique: true 52 | # add_index :users, :unlock_token, unique: true 53 | end 54 | end 55 | -------------------------------------------------------------------------------- /backend/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: 20180306161431) do 14 | 15 | # These are extensions that must be enabled in order to support this database 16 | enable_extension "plpgsql" 17 | 18 | create_table "users", force: :cascade do |t| 19 | t.string "provider", default: "email", null: false 20 | t.string "uid", default: "", null: false 21 | t.string "encrypted_password", default: "", null: false 22 | t.string "reset_password_token" 23 | t.datetime "reset_password_sent_at" 24 | t.datetime "remember_created_at" 25 | t.integer "sign_in_count", default: 0, null: false 26 | t.datetime "current_sign_in_at" 27 | t.datetime "last_sign_in_at" 28 | t.string "current_sign_in_ip" 29 | t.string "last_sign_in_ip" 30 | t.string "confirmation_token" 31 | t.datetime "confirmed_at" 32 | t.datetime "confirmation_sent_at" 33 | t.string "unconfirmed_email" 34 | t.string "name" 35 | t.string "nickname" 36 | t.string "image" 37 | t.string "email" 38 | t.json "tokens" 39 | t.datetime "created_at", null: false 40 | t.datetime "updated_at", null: false 41 | t.index ["confirmation_token"], name: "index_users_on_confirmation_token", unique: true 42 | t.index ["email"], name: "index_users_on_email", unique: true 43 | t.index ["reset_password_token"], name: "index_users_on_reset_password_token", unique: true 44 | t.index ["uid", "provider"], name: "index_users_on_uid_and_provider", unique: true 45 | end 46 | 47 | end 48 | -------------------------------------------------------------------------------- /backend/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 | -------------------------------------------------------------------------------- /backend/docker-entrypoint.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | set -e 3 | 4 | if [ -f tmp/pids/server.pid ]; then 5 | rm tmp/pids/server.pid 6 | fi 7 | 8 | exec bundle exec "$@" 9 | -------------------------------------------------------------------------------- /backend/public/robots.txt: -------------------------------------------------------------------------------- 1 | # See http://www.robotstxt.org/robotstxt.html for documentation on how to use the robots.txt file 2 | -------------------------------------------------------------------------------- /backend/spec/spec_helper.rb: -------------------------------------------------------------------------------- 1 | # This file was generated by the `rspec --init` command. Conventionally, all 2 | # specs live under a `spec` directory, which RSpec adds to the `$LOAD_PATH`. 3 | # The generated `.rspec` file contains `--require spec_helper` which will cause 4 | # this file to always be loaded, without a need to explicitly require it in any 5 | # files. 6 | # 7 | # Given that it is always loaded, you are encouraged to keep this file as 8 | # light-weight as possible. Requiring heavyweight dependencies from this file 9 | # will add to the boot time of your test suite on EVERY test run, even for an 10 | # individual file that may not need all of that loaded. Instead, consider making 11 | # a separate helper file that requires the additional dependencies and performs 12 | # the additional setup, and require it from the spec files that actually need 13 | # it. 14 | # 15 | # See http://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration 16 | RSpec.configure do |config| 17 | # rspec-expectations config goes here. You can use an alternate 18 | # assertion/expectation library such as wrong or the stdlib/minitest 19 | # assertions if you prefer. 20 | config.expect_with :rspec do |expectations| 21 | # This option will default to `true` in RSpec 4. It makes the `description` 22 | # and `failure_message` of custom matchers include text for helper methods 23 | # defined using `chain`, e.g.: 24 | # be_bigger_than(2).and_smaller_than(4).description 25 | # # => "be bigger than 2 and smaller than 4" 26 | # ...rather than: 27 | # # => "be bigger than 2" 28 | expectations.include_chain_clauses_in_custom_matcher_descriptions = true 29 | end 30 | 31 | # rspec-mocks config goes here. You can use an alternate test double 32 | # library (such as bogus or mocha) by changing the `mock_with` option here. 33 | config.mock_with :rspec do |mocks| 34 | # Prevents you from mocking or stubbing a method that does not exist on 35 | # a real object. This is generally recommended, and will default to 36 | # `true` in RSpec 4. 37 | mocks.verify_partial_doubles = true 38 | end 39 | 40 | # This option will default to `:apply_to_host_groups` in RSpec 4 (and will 41 | # have no way to turn it off -- the option exists only for backwards 42 | # compatibility in RSpec 3). It causes shared context metadata to be 43 | # inherited by the metadata hash of host groups and examples, rather than 44 | # triggering implicit auto-inclusion in groups with matching metadata. 45 | config.shared_context_metadata_behavior = :apply_to_host_groups 46 | 47 | # The settings below are suggested to provide a good initial experience 48 | # with RSpec, but feel free to customize to your heart's content. 49 | =begin 50 | # This allows you to limit a spec run to individual examples or groups 51 | # you care about by tagging them with `:focus` metadata. When nothing 52 | # is tagged with `:focus`, all examples get run. RSpec also provides 53 | # aliases for `it`, `describe`, and `context` that include `:focus` 54 | # metadata: `fit`, `fdescribe` and `fcontext`, respectively. 55 | config.filter_run_when_matching :focus 56 | 57 | # Allows RSpec to persist some state between runs in order to support 58 | # the `--only-failures` and `--next-failure` CLI options. We recommend 59 | # you configure your source control system to ignore this file. 60 | config.example_status_persistence_file_path = "spec/examples.txt" 61 | 62 | # Limits the available syntax to the non-monkey patched syntax that is 63 | # recommended. For more details, see: 64 | # - http://rspec.info/blog/2012/06/rspecs-new-expectation-syntax/ 65 | # - http://www.teaisaweso.me/blog/2013/05/27/rspecs-new-message-expectation-syntax/ 66 | # - http://rspec.info/blog/2014/05/notable-changes-in-rspec-3/#zero-monkey-patching-mode 67 | config.disable_monkey_patching! 68 | 69 | # This setting enables warnings. It's recommended, but in some cases may 70 | # be too noisy due to issues in dependencies. 71 | config.warnings = true 72 | 73 | # Many RSpec users commonly either run the entire suite or an individual 74 | # file, and it's useful to allow more verbose output when running an 75 | # individual spec file. 76 | if config.files_to_run.one? 77 | # Use the documentation formatter for detailed output, 78 | # unless a formatter has already been configured 79 | # (e.g. via a command-line flag). 80 | config.default_formatter = "doc" 81 | end 82 | 83 | # Print the 10 slowest examples and example groups at the 84 | # end of the spec run, to help surface which specs are running 85 | # particularly slow. 86 | config.profile_examples = 10 87 | 88 | # Run specs in random order to surface order dependencies. If you find an 89 | # order dependency and want to debug it, you can fix the order by providing 90 | # the seed, which is printed after each run. 91 | # --seed 1234 92 | config.order = :random 93 | 94 | # Seed global randomization in this process using the `--seed` CLI option. 95 | # Setting this allows you to use `--seed` to deterministically reproduce 96 | # test failures related to randomization by passing the same `--seed` value 97 | # as the one that triggered the failure. 98 | Kernel.srand config.seed 99 | =end 100 | end 101 | -------------------------------------------------------------------------------- /config/nginx/nginx.conf: -------------------------------------------------------------------------------- 1 | # Similar approach we have in production, except that we do 2 | # not serve static files for the client nor assets, we upstream 3 | # everything 4 | 5 | server { 6 | listen 8080; 7 | server_name yourproject.docker; 8 | 9 | location /api { 10 | proxy_set_header Host $host; 11 | proxy_set_header X-Real-IP $remote_addr; 12 | proxy_pass http://backend:3000; 13 | } 14 | 15 | # Other to frontend 16 | location /sockjs-node { 17 | proxy_set_header X-Real-IP $remote_addr; 18 | proxy_set_header X-Forwarded-For $remote_addr; 19 | proxy_set_header Host $host; 20 | 21 | proxy_pass http://frontend:4000; 22 | 23 | proxy_redirect off; 24 | 25 | proxy_http_version 1.1; 26 | proxy_set_header Upgrade $http_upgrade; 27 | proxy_set_header Connection "upgrade"; 28 | } 29 | 30 | location / { 31 | proxy_set_header Host $host; 32 | proxy_set_header X-Real-IP $remote_addr; 33 | proxy_pass http://frontend:4000; 34 | } 35 | } -------------------------------------------------------------------------------- /docker-compose.yml: -------------------------------------------------------------------------------- 1 | version: '2' 2 | 3 | services: 4 | redis: 5 | image: redis 6 | volumes: 7 | - ./backend/tmp/redis:/data 8 | ports: 9 | - 6379:6379 10 | worker: 11 | build: backend 12 | command: bundle exec sidekiq 13 | environment: 14 | REDIS_URL: redis://redis:6379/0 15 | volumes: 16 | - ./backend:/usr/src/backend-app 17 | depends_on: 18 | - db 19 | - redis 20 | nginx: 21 | image: bitnami/nginx:1.10.2-r1 22 | volumes: 23 | - ./config/nginx:/bitnami/nginx/conf/vhosts 24 | depends_on: 25 | - backend 26 | - frontend 27 | environment: 28 | VIRTUAL_HOST: yourproject.docker 29 | VIRTUAL_PORT: 8080 30 | ports: 31 | - 8080:8080 32 | db: 33 | image: postgres 34 | volumes: 35 | - /var/lib/postgresql/data 36 | environment: 37 | POSTGRES_USER: postgres 38 | POSTGRES_PASSWORD: secret 39 | ALLOW_IP_RANGE: 0.0.0.0/0 40 | ports: 41 | - 54321:5432 42 | backend: 43 | build: backend 44 | depends_on: 45 | - db 46 | - redis 47 | - worker 48 | volumes: 49 | - ./backend:/usr/src/backend-app 50 | environment: 51 | REDIS_URL: redis://redis:6379/0 52 | SIDEKIQ_REDIS_URL: redis://redis:6379/1 53 | frontend: 54 | build: 55 | context: ./frontend/ 56 | depends_on: 57 | - backend 58 | command: npm start 59 | volumes: 60 | - ./frontend/:/usr/src/frontend-app 61 | - ./frontend/node_modules:/usr/src/frontend-app/node_modules 62 | ports: 63 | - "35729:35729" -------------------------------------------------------------------------------- /frontend/.babelrc: -------------------------------------------------------------------------------- 1 | { 2 | "presets": [ 3 | "react", 4 | "babel-preset-env", 5 | "stage-0" 6 | ], 7 | "plugins": [ 8 | "transform-runtime", 9 | "add-module-exports", 10 | "transform-decorators-legacy" 11 | ], 12 | "env": { 13 | "development": { 14 | "plugins": [] 15 | } 16 | } 17 | } -------------------------------------------------------------------------------- /frontend/.dockerignore: -------------------------------------------------------------------------------- 1 | .git 2 | .idea 3 | node_modules 4 | build 5 | npm-debug.log* 6 | npm-error.log* -------------------------------------------------------------------------------- /frontend/.gitignore: -------------------------------------------------------------------------------- 1 | # See https://help.github.com/ignore-files/ for more about ignoring files. 2 | 3 | # dependencies 4 | /node_modules 5 | 6 | # testing 7 | /coverage 8 | 9 | # production 10 | /build 11 | 12 | # misc 13 | .DS_Store 14 | .env.local 15 | .env.development.local 16 | .env.test.local 17 | .env.production.local 18 | 19 | npm-debug.log* 20 | yarn-debug.log* 21 | yarn-error.log* 22 | -------------------------------------------------------------------------------- /frontend/Dockerfile: -------------------------------------------------------------------------------- 1 | FROM node:9.4.0 2 | WORKDIR /usr/src/frontend-app 3 | COPY package*.json ./ 4 | RUN yarn install 5 | COPY . . 6 | EXPOSE 3000 7 | 8 | CMD ["yarn", "start"] -------------------------------------------------------------------------------- /frontend/config/env.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | const fs = require('fs'); 4 | const path = require('path'); 5 | const paths = require('./paths'); 6 | 7 | // Make sure that including paths.js after env.js will read .env variables. 8 | delete require.cache[require.resolve('./paths')]; 9 | 10 | const NODE_ENV = process.env.NODE_ENV; 11 | if (!NODE_ENV) { 12 | throw new Error( 13 | 'The NODE_ENV environment variable is required but was not specified.' 14 | ); 15 | } 16 | 17 | // https://github.com/bkeepers/dotenv#what-other-env-files-can-i-use 18 | var dotenvFiles = [ 19 | `${paths.dotenv}.${NODE_ENV}.local`, 20 | `${paths.dotenv}.${NODE_ENV}`, 21 | // Don't include `.env.local` for `test` environment 22 | // since normally you expect tests to produce the same 23 | // results for everyone 24 | NODE_ENV !== 'test' && `${paths.dotenv}.local`, 25 | paths.dotenv, 26 | ].filter(Boolean); 27 | 28 | // Load environment variables from .env* files. Suppress warnings using silent 29 | // if this file is missing. dotenv will never modify any environment variables 30 | // that have already been set. Variable expansion is supported in .env files. 31 | // https://github.com/motdotla/dotenv 32 | // https://github.com/motdotla/dotenv-expand 33 | dotenvFiles.forEach(dotenvFile => { 34 | if (fs.existsSync(dotenvFile)) { 35 | require('dotenv-expand')( 36 | require('dotenv').config({ 37 | path: dotenvFile, 38 | }) 39 | ); 40 | } 41 | }); 42 | 43 | // We support resolving modules according to `NODE_PATH`. 44 | // This lets you use absolute paths in imports inside large monorepos: 45 | // https://github.com/facebookincubator/create-react-app/issues/253. 46 | // It works similar to `NODE_PATH` in Node itself: 47 | // https://nodejs.org/api/modules.html#modules_loading_from_the_global_folders 48 | // Note that unlike in Node, only *relative* paths from `NODE_PATH` are honored. 49 | // Otherwise, we risk importing Node.js core modules into an app instead of Webpack shims. 50 | // https://github.com/facebookincubator/create-react-app/issues/1023#issuecomment-265344421 51 | // We also resolve them to make sure all tools using them work consistently. 52 | const appDirectory = fs.realpathSync(process.cwd()); 53 | process.env.NODE_PATH = (process.env.NODE_PATH || '') 54 | .split(path.delimiter) 55 | .filter(folder => folder && !path.isAbsolute(folder)) 56 | .map(folder => path.resolve(appDirectory, folder)) 57 | .join(path.delimiter); 58 | 59 | // Grab NODE_ENV and REACT_APP_* environment variables and prepare them to be 60 | // injected into the application via DefinePlugin in Webpack configuration. 61 | const REACT_APP = /^REACT_APP_/i; 62 | 63 | function getClientEnvironment(publicUrl) { 64 | const raw = Object.keys(process.env) 65 | .filter(key => REACT_APP.test(key)) 66 | .reduce( 67 | (env, key) => { 68 | env[key] = process.env[key]; 69 | return env; 70 | }, 71 | { 72 | // Useful for determining whether we’re running in production mode. 73 | // Most importantly, it switches React into the correct mode. 74 | NODE_ENV: process.env.NODE_ENV || 'development', 75 | // Useful for resolving the correct path to static assets in `public`. 76 | // For example, . 77 | // This should only be used as an escape hatch. Normally you would put 78 | // images into the `src` and `import` them in code to get their paths. 79 | PUBLIC_URL: publicUrl, 80 | } 81 | ); 82 | // Stringify all values so we can feed into Webpack DefinePlugin 83 | const stringified = { 84 | 'process.env': Object.keys(raw).reduce((env, key) => { 85 | env[key] = JSON.stringify(raw[key]); 86 | return env; 87 | }, {}), 88 | }; 89 | 90 | return { raw, stringified }; 91 | } 92 | 93 | module.exports = getClientEnvironment; 94 | -------------------------------------------------------------------------------- /frontend/config/jest/cssTransform.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | // This is a custom Jest transformer turning style imports into empty objects. 4 | // http://facebook.github.io/jest/docs/en/webpack.html 5 | 6 | module.exports = { 7 | process() { 8 | return 'module.exports = {};'; 9 | }, 10 | getCacheKey() { 11 | // The output is always the same. 12 | return 'cssTransform'; 13 | }, 14 | }; 15 | -------------------------------------------------------------------------------- /frontend/config/jest/fileTransform.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | const path = require('path'); 4 | 5 | // This is a custom Jest transformer turning file imports into filenames. 6 | // http://facebook.github.io/jest/docs/en/webpack.html 7 | 8 | module.exports = { 9 | process(src, filename) { 10 | return `module.exports = ${JSON.stringify(path.basename(filename))};`; 11 | }, 12 | }; 13 | -------------------------------------------------------------------------------- /frontend/config/paths.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | const path = require('path'); 4 | const fs = require('fs'); 5 | const url = require('url'); 6 | 7 | // Make sure any symlinks in the project folder are resolved: 8 | // https://github.com/facebookincubator/create-react-app/issues/637 9 | const appDirectory = fs.realpathSync(process.cwd()); 10 | const resolveApp = relativePath => path.resolve(appDirectory, relativePath); 11 | 12 | const envPublicUrl = process.env.PUBLIC_URL; 13 | 14 | function ensureSlash(path, needsSlash) { 15 | const hasSlash = path.endsWith('/'); 16 | if (hasSlash && !needsSlash) { 17 | return path.substr(path, path.length - 1); 18 | } else if (!hasSlash && needsSlash) { 19 | return `${path}/`; 20 | } else { 21 | return path; 22 | } 23 | } 24 | 25 | const getPublicUrl = appPackageJson => 26 | envPublicUrl || require(appPackageJson).homepage; 27 | 28 | // We use `PUBLIC_URL` environment variable or "homepage" field to infer 29 | // "public path" at which the app is served. 30 | // Webpack needs to know it to put the right