Skip to content

Commit

Permalink
Merge pull request #15 from ToruHirashima/aws-deploy
Browse files Browse the repository at this point in the history
自動デプロイ機能実装
  • Loading branch information
shinichiro-motoike authored Mar 2, 2020
2 parents 3a13f4b + 69e64b0 commit 0a0095b
Show file tree
Hide file tree
Showing 6 changed files with 150 additions and 20 deletions.
44 changes: 44 additions & 0 deletions Capfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
# Load DSL and set up stages
require "capistrano/setup"

# Include default deployment tasks
require "capistrano/deploy"

# Load the SCM plugin appropriate to your project:
#
# require "capistrano/scm/hg"
# install_plugin Capistrano::SCM::Hg
# or
# require "capistrano/scm/svn"
# install_plugin Capistrano::SCM::Svn
# or
require "capistrano/scm/git"
install_plugin Capistrano::SCM::Git

# Include tasks from other gems included in your Gemfile
#
# For documentation on these, see for example:
#
# https://github.com/capistrano/rvm
# https://github.com/capistrano/rbenv
# https://github.com/capistrano/chruby
# https://github.com/capistrano/bundler
# https://github.com/capistrano/rails
# https://github.com/capistrano/passenger
#
# require "capistrano/rvm"
# require "capistrano/rbenv"
# require "capistrano/chruby"
# require "capistrano/bundler"
# require "capistrano/rails/assets"
# require "capistrano/rails/migrations"
# require "capistrano/passenger"

require 'capistrano/rbenv'
require 'capistrano/bundler'
require 'capistrano/rails/assets'
require 'capistrano/rails/migrations'
require 'capistrano3/unicorn'

# Load custom tasks from `lib/capistrano/tasks` if you have any defined
Dir.glob("lib/capistrano/tasks/*.rake").each { |r| import r }
2 changes: 1 addition & 1 deletion config/credentials.yml.enc
Original file line number Diff line number Diff line change
@@ -1 +1 @@
Xq5kVC/AkvsJ0RMff9QjHSbdenECqbOkb4arQXxEkx6ESPwladLidt84Ju3jxpi9RAmovSwzuPdLFA0Kbqq7LeIt7NBz09Z9Yw0ajOtLJl0kJbfBQ8HXVVQ8gcLnUAAkEkVZ5UurdVRf7qUTSEH0S1FjwtzAMCFiBogfVXzYRsNd8T5pvTHZOvLNR+fWm8EynonouuWfnb15Sj8iLeTAYKp6qjl25MWfoE9Uj3yv5WE0WyCGK+4rtlG/mN4/aCpQ62KSqhK4bHVGAtrRBNAK77mhpCeDC1CGa08PHiLTDQlraGxf6akc0DxHT2A3qBVnMftGCGiI1RMopoU8UUEBt3xu5jn8eT5CinKDbFRTe95fod//ZQMIO+GmAmb5V4iFrQdEm+wvJtOJCYOclZVsymA7oXUy59hLdXzX--x/EXYxVgrg/QhZF+--XHVaw08P3on7axLhaKDZPw==
N6/q5IsA60SKTXwvQi7w0pzXSWVpgd1xMTOTRvJngqTGUtwNsv78iPmZ+DywtT/3avgH0v1s5EGgW3lriofEty+SDeUm98RKlg65JQGdbFDSKeNQIcqpaOSXf7ETE1mCb2Ni7RVuAIquUmHRoSKFfRMhHYLWyZ7T6O/1NGL1W+3JUC/1bMXjXmDwdQCQFuDE3IFDm0fUCj+p7yhZ6/UAMY+JDZ7E/2IXaZa2/sYmi9Ec1Gd82IRzhdQFmTz0+xe9dTLJQ0VyncridKDAbKoj6zJxqw8FcTltFAGa1aX3S2A/LxP9+d6ZJgrqgRYL1qyiWz7XMMPVFcEvdUNOB1D/bN2BYyVbhzIezx8xh78OwO1j3pi356u3f6cQJzlxPDWTIa+MhkgsHEClmfxkpG1b8U4=--yeS1D2EZpQq2McAG--Jz0OqdZPjjvPpwOR9ugZ2Q==
34 changes: 34 additions & 0 deletions config/deploy.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
# config valid only for current version of Capistrano
# capistranoのバージョンを記載。固定のバージョンを利用し続け、バージョン変更によるトラブルを防止する
lock '3.12.0'

# Capistranoのログの表示に利用する
set :application, 'freemarket_sample_65a'

# どのリポジトリからアプリをpullするかを指定する
set :repo_url, '[email protected]:ToruHirashima/freemarket_sample_65a.git'

# バージョンが変わっても共通で参照するディレクトリを指定
set :linked_dirs, fetch(:linked_dirs, []).push('log', 'tmp/pids', 'tmp/cache', 'tmp/sockets', 'vendor/bundle', 'public/system', 'public/uploads')

set :rbenv_type, :user
set :rbenv_ruby, '2.5.1' #カリキュラム通りに進めた場合、2.5.1か2.3.1です

# どの公開鍵を利用してデプロイするか
set :ssh_options, auth_methods: ['publickey'],
keys: ['~/.ssh/freemarket_sample_65a.pem']

# プロセス番号を記載したファイルの場所
set :unicorn_pid, -> { "#{shared_path}/tmp/pids/unicorn.pid" }

# Unicornの設定ファイルの場所
set :unicorn_config_path, -> { "#{current_path}/config/unicorn.rb" }
set :keep_releases, 5

# デプロイ処理が終わった後、Unicornを再起動するための記述
after 'deploy:publishing', 'deploy:restart'
namespace :deploy do
task :restart do
invoke 'unicorn:restart'
end
end
3 changes: 1 addition & 2 deletions config/deploy/production.rb
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
# server "db.example.com", user: "deploy", roles: %w{db}
server "52.193.148.9", user: "ec2-user", roles: %w{app db web}

set :rails_env, "production"
set :unicorn_rack_env, "production"

# role-based syntax
# ==================
# ==================
61 changes: 61 additions & 0 deletions config/deploy/staging.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
# server-based syntax
# ======================
# Defines a single server with a list of roles and multiple properties.
# You can define all roles on a single server, or split them:

# server "example.com", user: "deploy", roles: %w{app db web}, my_property: :my_value
# server "example.com", user: "deploy", roles: %w{app web}, other_property: :other_value
# server "db.example.com", user: "deploy", roles: %w{db}



# role-based syntax
# ==================

# Defines a role with one or multiple servers. The primary server in each
# group is considered to be the first unless any hosts have the primary
# property set. Specify the username and a domain or IP for the server.
# Don't use `:all`, it's a meta role.

# role :app, %w{[email protected]}, my_property: :my_value
# role :web, %w{[email protected] [email protected]}, other_property: :other_value
# role :db, %w{[email protected]}



# Configuration
# =============
# You can set any configuration variable like in config/deploy.rb
# These variables are then only loaded and set in this stage.
# For available Capistrano configuration variables see the documentation page.
# http://capistranorb.com/documentation/getting-started/configuration/
# Feel free to add new variables to customise your setup.



# Custom SSH Options
# ==================
# You may pass any option but keep in mind that net/ssh understands a
# limited set of options, consult the Net::SSH documentation.
# http://net-ssh.github.io/net-ssh/classes/Net/SSH.html#method-c-start
#
# Global options
# --------------
# set :ssh_options, {
# keys: %w(/home/rlisowski/.ssh/id_rsa),
# forward_agent: false,
# auth_methods: %w(password)
# }
#
# The server-based syntax can be used to override options:
# ------------------------------------
# server "example.com",
# user: "user_name",
# roles: %w{web app},
# ssh_options: {
# user: "user_name", # overrides user setting above
# keys: %w(/home/user_name/.ssh/id_rsa),
# forward_agent: false,
# auth_methods: %w(publickey password)
# # password: "please use keys"
# }
26 changes: 9 additions & 17 deletions config/unicorn.rb
Original file line number Diff line number Diff line change
@@ -1,22 +1,14 @@
app_path = File.expand_path('../../', __FILE__)
app_path = File.expand_path('../../../', __FILE__)

#アプリケーションサーバの性能を決定する
worker_processes 1

#アプリケーションの設置されているディレクトリを指定
working_directory app_path

#Unicornの起動に必要なファイルの設置場所を指定
pid "#{app_path}/tmp/pids/unicorn.pid"

#ポート番号を指定
listen "#{app_path}/tmp/sockets/unicorn.sock"

#エラーのログを記録するファイルを指定
stderr_path "#{app_path}/log/unicorn.stderr.log"

#通常のログを記録するファイルを指定
stdout_path "#{app_path}/log/unicorn.stdout.log"
# currentを指定
working_directory "#{app_path}/current"

# それぞれ、sharedの中を参照するよう変更
listen "#{app_path}/shared/tmp/sockets/unicorn.sock"
pid "#{app_path}/shared/tmp/pids/unicorn.pid"
stderr_path "#{app_path}/shared/log/unicorn.stderr.log"
stdout_path "#{app_path}/shared/log/unicorn.stdout.log"

#Railsアプリケーションの応答を待つ上限時間を設定
timeout 60
Expand Down

0 comments on commit 0a0095b

Please sign in to comment.