Skip to content

Instantly share code, notes, and snippets.

@shun115
Last active November 27, 2019 08:52
Show Gist options
  • Save shun115/2ead30de934f792f57abcfea9f78206d to your computer and use it in GitHub Desktop.
Save shun115/2ead30de934f792f57abcfea9f78206d to your computer and use it in GitHub Desktop.
new rails5 project
$ cd path/to/project
$ Dockerfile-local-dev
FROM ruby:2.6.1
RUN apt update -qq \
&& apt install -y build-essential \
curl
RUN curl -sL https://deb.nodesource.com/setup_10.x | bash - \
&& apt install -y nodejs
RUN curl -sS https://dl.yarnpkg.com/debian/pubkey.gpg | apt-key add - \
&& echo "deb https://dl.yarnpkg.com/debian/ stable main" | tee /etc/apt/sources.list.d/yarn.list \
&& apt update \
&& apt install -y yarn
RUN mkdir /root/.ssh
RUN mkdir /webapp
ENV APP_ROOT /webapp
WORKDIR $APP_ROOT
ENV ENTRYKIT_VERSION 0.4.0
RUN wget https://github.com/progrium/entrykit/releases/download/v${ENTRYKIT_VERSION}/entrykit_${ENTRYKIT_VERSION}_Linux_x86_64.tgz \
&& tar -xvzf entrykit_${ENTRYKIT_VERSION}_Linux_x86_64.tgz \
&& rm entrykit_${ENTRYKIT_VERSION}_Linux_x86_64.tgz \
&& mv entrykit /bin/entrykit \
&& chmod +x /bin/entrykit \
&& entrykit --symlink
ENTRYPOINT [ \
"prehook", "ruby -v", "--", \
"prehook", "bundle install -j4", "--"]
$ docker-compose-local-dev.yml
version: '3'
services:
app:
container_name: XXX
build:
context: .
dockerfile: Dockerfile-local-dev
command: sh -c "rm -f tmp/pids/server.pid && rails s -p 3000 -b '0.0.0.0'"
volumes:
- .:/webapp
- ${HOME}/.ssh/XXX:/root/.ssh/XXX
- bundle_data:/usr/local/bundle
ports:
- "3000:3000"
env_file: docker-env-local-dev
volumes:
bundle_data:
driver: local
$ docker-env-local-dev
RAILS_DATABASE_HOST=host.docker.internal
$ bundle init
$ vi Gemfile
$ cat Gemfile
source "https://rubygems.org"
gem "rails"
$ dup
$ drun rails new XXX -T -d mysql
$ mv XXX/* . # dotfilesも。 .gitは要らない
$ git init
$ database.yml
encoding: utf8mb4
charset: utf8mb4
collation: utf8mb4_general_ci
host: <%= ENV['RAILS_DATABASE_HOST'] || 'localhost' %>
$ vi .gitignore
# Ignore bundler config.
/.bundle
# Ignore all logfiles and tempfiles.
/log/*
/tmp/*
!/log/.keep
!/tmp/.keep
# Ignore Byebug command history file.
.byebug_history
#rails specific
.sass-cache/
/public/system
/public/assets
/public/uploads
# generic files to ignore
*~
*.DS_Store
*.swp
.rvmrc
.ruby-version
/.idea
/.codeintel
/vendor/bundle
.capistrano/
$ vi Gemfile
gem 'settingslogic'
gem 'aws-sdk', require: false
group :development, :test do
# Call 'byebug' anywhere in the code to stop execution and get a debugger console
gem 'byebug', platforms: [:mri, :mingw, :x64_mingw]
gem 'rspec-rails', '~> 3.8'
gem 'rails-controller-testing'
gem 'spring-commands-rspec'
gem 'factory_bot_rails'
gem 'guard'
gem 'guard-rspec'
gem 'terminal-notifier'
gem 'terminal-notifier-guard'
gem 'ffaker'
gem 'bullet'
gem 'annotate'
gem 'awesome_print'
gem 'shoulda-matchers', '~> 3.1'
end
group :deployment do
gem 'capistrano', require: false
gem 'capistrano-rails', require: false
gem 'capistrano-rvm', require: false
gem 'capistrano-rbenv', require: false
gem 'capistrano-bundler', require: false
gem 'capistrano-scm-gitcopy', require: false
end
$ dup
$ dexec bundle
$ drails g rspec:install
$ dexec guard init
$ Gurdfile
guard :rspec, cmd: "bundle exec spring rspec -f doc" do
$ rails_helper.rb
config.include FactoryBot::Syntax::Methods
# use for file upload test
config.include ActionDispatch::TestProcess
FactoryBot::SyntaxRunner.class_eval do
include ActionDispatch::TestProcess
end
config.after(:all) do
FileUtils.rm_rf(Dir["#{Rails.root}/public/test_data/[^.]*"])
end
# config.before(:suite) do
# require File.join(Rails.root, 'db', 'seeds.rb')
# end
$ application.rb
config.time_zone = 'Tokyo'
config.active_record.default_timezone = :local
config.i18n.default_locale = :ja
config.autoload_paths << Rails.root.join('lib')
config.eager_load_paths << Rails.root.join('lib')
config.generators do |g|
g.assets false
g.helper false
end
$ plugins.rb lib/plugins/tx_around_action.rb
Rails.application.config.to_prepare do
Dir[Rails.root.join('lib/plugins/**/*.rb')].sort.each do |file|
require file
end
end
$ settingslogic
$ config/setting.yml
defaults: &defaults
development:
<<: *defaults
test:
<<: *defaults
staging:
<<: *defaults
production:
<<: *defaults
$ setting.rb
class Setting < Settingslogic
source "#{Rails.root}/config/setting.yml"
namespace Rails.env
end
$ filter_parameter_loggingの検討
$ lib/api_error.rb
$ protect_from_forgery
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment