Skip to content

Instantly share code, notes, and snippets.

@sigmadream

sigmadream/Capfile

Last active Apr 28, 2016
Embed
What would you like to do?
Deploy Rails 5.0.0.beta3(Nginx, Puma, Capistrano3, PostgreSQL, rbenv)
require 'capistrano/setup'
require 'capistrano/deploy'
require 'capistrano/nginx'
require 'capistrano/puma'
require 'capistrano/puma/nginx'
require 'capistrano/rbenv'
require 'capistrano/rails'
require 'capistrano/rails/db'
require 'capistrano/rails/console'
require 'capistrano/upload-config'
Dir.glob('lib/capistrano/tasks/*.rake').each { |r| import r }
# config valid only for current version of Capistrano
lock '3.4.1'
set :repo_url, '<<여러분의 레포>>'
set :user, '<<여러분의 계정>>'
set :application, '<<여러분의 앱 이름>>'
server '<<여러분의 IP주소>>', user: "#{fetch(:user)}", roles: %w{app db web}, primary: true
set :deploy_to, "/home/#{fetch(:user)}/apps/#{fetch(:application)}"
set :linked_files, fetch(:linked_files, []).push('config/database.yml', 'config/secrets.yml', 'config/puma.rb')
set :linked_dirs, fetch(:linked_dirs, []).push('log', 'tmp/pids', 'tmp/cache', 'tmp/sockets', 'vendor/bundle', 'public/system', 'public/uploads')
set :config_example_suffix, '.example'
set :config_files, %w{config/database.yml config/secrets.yml}
set :puma_conf, "#{shared_path}/config/puma.rb"
set :rbenv_type, :user # or :system, depends on your rbenv setup
set :rbenv_ruby, '2.3.0' # run ruby -v on server to ensure the version is correct
set :rbenv_prefix, "RBENV_ROOT=#{fetch(:rbenv_path)} RBENV_VERSION=#{fetch(:rbenv_ruby)} #{fetch(:rbenv_path)}/bin/rbenv exec"
set :rbenv_map_bins, %w{rake gem bundle ruby rails}
set :rbenv_roles, :all # default value
namespace :deploy do
before 'check:linked_files', 'config:push'
before 'check:linked_files', 'puma:config'
before 'check:linked_files', 'puma:nginx_config'
before 'deploy:migrate', 'deploy:db:create'
after :restart, :clear_cache do
on roles(:web), in: :groups, limit: 3, wait: 10 do
# Here we can do anything such as:
# within release_path do
# execute :rake, 'cache:clear'
# end
end
end
after 'puma:smart_restart', 'nginx:restart'
end

VM 초기 설정

$ sudo apt-get update
$ sudo apt-get upgrade
$ sudo apt-get -y install git-core curl zlib1g-dev build-essential libssl-dev libreadline-dev libyaml-dev libsqlite3-dev sqlite3 libxml2-dev libxslt1-dev libcurl4-openssl-dev python-software-properties libffi-dev

rbenv and ruby 2.3

$ cd
$ git clone https://github.com/rbenv/rbenv.git ~/.rbenv
$ echo 'export PATH="$HOME/.rbenv/bin:$PATH"' >> ~/.bashrc
$ echo 'eval "$(rbenv init -)"' >> ~/.bashrc
$ source .bashrc

$ git clone https://github.com/rbenv/ruby-build.git ~/.rbenv/plugins/ruby-build
$ echo 'export PATH="$HOME/.rbenv/plugins/ruby-build/bin:$PATH"' >> ~/.bashrc
$ source .bashrc

$ git clone https://github.com/rbenv/rbenv-gem-rehash.git ~/.rbenv/plugins/rbenv-gem-rehash
$ rbenv install 2.3.0
$ rbenv global 2.3.0
$ ruby -v
ruby 2.3.0p0 (2015-12-25 revision 53290) [x86_64-linux]

rails 5(beta3)

$ gem install bundler
$ curl -sL https://deb.nodesource.com/setup_4.x | sudo -E bash -
$ sudo apt-get install -y nodejs
$ gem install rails --pre
$ rbenv rehash

Nginx

$ sudo add-apt-repository ppa:nginx/stable
$ sudo apt-get update
$ sudo apt-get -y install nginx
$ sudo rm /etc/nginx/sites-available/default

Locale

$ export LANGUAGE=en_US.UTF-8
$ export LANG=en_US.UTF-8
$ export LC_ALL=en_US.UTF-8
$ locale-gen en_US.UTF-8
$ sudo dpkg-reconfigure locales

Puma

$ wget https://raw.githubusercontent.com/puma/puma/master/tools/jungle/upstart/puma-manager.conf
$ wget https://raw.githubusercontent.com/puma/puma/master/tools/jungle/upstart/puma.conf
$ vi puma.conf
.. setuid deployer
.. setgid deployer
$ sudo cp puma.conf puma-manager.conf /etc/init
$ sudo touch /etc/puma.conf
``

# Capistrano3

gem 'capistrano', '> 3.4' gem 'capistrano-rbenv', '> 2.0' gem 'capistrano3-nginx', '> 2.1', '>= 2.1.4' gem 'capistrano3-puma', '> 1.2', '>= 1.2.1' gem 'capistrano-rails', '> 1.1', '>= 1.1.6' gem 'capistrano-rails-db', '> 0.0.2' gem 'capistrano-rails-console', '> 1.0', '>= 1.0.2' gem 'capistrano-upload-config', '> 0.7.0'

$ bundle install $ cap install


## Edit Capfile
## Edit config/deploy.rb

$ cp config/database.yml config/database.yml.example
$ cp config/secrets.yml config/secrets.yml.example
$ cap production config:init
$ echo '/config/database.production.yml' >> .gitignore
$ echo '/config/secrets.production.yml' >> .gitignore

## Edit or Leave  config/database.production.yml
## Edit or Leave  config/secrets.production.yml

$ rails g capistrano:nginx_puma:config

## Edit or Leave config/deploy/templates/nginx_conf.erb
## Edit or Leave  config/deploy/templates/puma.rb.erb

$ git add --all
$ git commit -m "Test Depoly"

$ cap production deploy

$ vi /etc/puma.conf

/home/deployer/apps/<<여러분의 앱>>/current


## Server/Service Restart!
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment