3
4

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

RailsアプリをOpsWorksにデプロイする

Posted at

環境

  • Ruby 2.1
  • Rails 4.2.0
  • MySQL
  • nginx and Unicorn

参考

サンプル

Railsアプリの準備

opsworksブランチの作成

RailsアプリにOpsWorks用のブランチを作成します。
例:私はRails 4.2 写経用サンプルアプリをクローンし、OpsWorks用のブランチを作成しました。

git checkout -b opsworks

Gemの追加

GemfileにMySQL接続用のライブラリを追加します。

gem 'mysql2', '~> 0.3.18'

therubyracerとunicorn行のコメントを外し、Gemを有効にします。

gem 'therubyracer', platforms: :ruby
gem 'unicorn'

アセットのプリコンパイル

deploy/before_symlink.rbファイルを追加し、シンボリックリンクステージの前にプリコンパイルを実行します。

mkdir deploy
vi deploy/before_symlink.rb
deploy/before_symlink.rb
run "cd #{release_path} && RAILS_ENV=production bundle exec rake assets:precompile"

GitHubリポジトリに反映

bundle install
git add -A
git commit -m OpsWorks
git push origin opsworks

OpsWorksの設定

Stack

デフォルト値のままで、Nameだけ入力し、「Add Stack」ボタンを押下します。

  • Amazon Linux 2014.09

Layers

Rails App Server

  • Ruby version 2.1
  • Rails stack nginx and Unicorn
  • RubyGems version 2.2.2
  • Bundler version 1.7.4

MySQL

  • デフォルト設定

Instances

Rails App Server, MySQL

  • t2.small などに変更します。

Apps

Application Source

  • Repository URL https://github.com/usutani/store_rails420.git
  • Branch/Revision opsworks

Environment Variables

  • SECRET_KEY_BASE Protected value

(参考)Mac:bundle exec rake secret | pbcopyでクリップボードにコピーします。

Deployments

  • Migrate database YES
  • Advanced >> Custom Chef JSON

アプリ名store_rails420を置き換えてください。

{
  "deploy":
  {
    "store_rails420":
    {
      "database":
      {
        "adapter": "mysql2"
      }
    }
  }
}
3
4
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
3
4

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?