{"id":272,"date":"2016-06-02T18:46:29","date_gmt":"2016-06-02T09:46:29","guid":{"rendered":"https:\/\/p-corporate-blog-cms.mmmcorp.co.jp\/blog\/2016\/06\/02\/deploy-rails-to-opsworks-chef11-with-custom-layer"},"modified":"2016-06-02T18:46:29","modified_gmt":"2016-06-02T09:46:29","slug":"deploy-rails-to-opsworks-chef11-with-custom-layer","status":"publish","type":"post","link":"https:\/\/p-corporate-blog-cms.mmmcorp.co.jp\/blog\/2016\/06\/02\/deploy-rails-to-opsworks-chef11-with-custom-layer\/","title":{"rendered":"\u3010OpsWorks(Chef11)\u3011\u8907\u6570\u306eRails\u30ec\u30a4\u30e4\u30fc\u3067\u7c21\u5358\u306b\u30de\u30a4\u30af\u30ed\u30b5\u30fc\u30d3\u30b9\u30a2\u30fc\u30ad\u30c6\u30af\u30c1\u30e3\u74b0\u5883\u3092\u69cb\u7bc9\u3059\u308b5\u3064\u306e\u8a2d\u5b9a"},"content":{"rendered":"

\u524d\u7530\u3067\u3059\u3002
\n\u4eca\u3061\u3087\u3046\u3069AWS\u30b5\u30df\u30c3\u30c8<\/a>\u304c\u958b\u50ac\u3055\u308c\u3066\u3044\u307e\u3059\u306d\u3002
\n
\u6628\u5e74\u306e\u3088\u3046\u306bYouTube\u306b\u30a2\u30c3\u30d7<\/a>\u3055\u308c\u308b\u3068\u601d\u3044\u307e\u3059\u306e\u3067\u3001\u307e\u305f\u6642\u9593\u304c\u3042\u308b\u6642\u306b\u898b\u3066\u307f\u3088\u3046\u304b\u3068\u601d\u3063\u3066\u3044\u307e\u3059\u3002<\/p>\n

\u3055\u3066\u30d6\u30ed\u30b0\u3067\u3059\u304c\u3001\u524d\u56de\u306e\u7d9a\u304d\u306e\u300cChef12\u306b\u5bfe\u5fdc\u3057\u305fAWS OpsWorks\u306bRails\u30a2\u30d7\u30ea\u3092\u30c7\u30d7\u30ed\u30a4\u3059\u308b\u300d<\/a>\u306e\u7b2c3\u56de\u76ee\u3092\u3084\u308d\u3046\u304b\u3068\u601d\u3044\u307e\u3057\u305f\u304c\u3001\u5c11\u3057\u5909\u3048\u3066\u3001\u300cOpsWorks Chef11\u7248\u306b\u3001\u8907\u6570\u306eRails\u30a2\u30d7\u30ea\u3092\u30c7\u30d7\u30ed\u30a4\u3067\u304d\u308b\u30de\u30a4\u30af\u30ed\u30b5\u30fc\u30d3\u30b9\u74b0\u5883\u3092\u69cb\u7bc9\u3059\u308b\u300d\u3068\u3044\u3046\u5185\u5bb9\u3067\u66f8\u304d\u305f\u3044\u3068\u601d\u3044\u307e\u3059\u3002<\/p>\n

Chef11\u7248\u306eOpsWorks\u306b\u306f\u3001\u30c7\u30d5\u30a9\u30eb\u30c8\u3067Rails\u30ec\u30a4\u30e4\u30fc\u304c\u30bb\u30c3\u30c8\u3055\u308c\u3066\u3044\u308b\u306e\u3067\u3001Rails\u30a2\u30d7\u30ea\u30b1\u30fc\u30b7\u30e7\u30f3\u3092\u30c7\u30d7\u30ed\u30a4\u3059\u308b\u306e\u306f\u7c21\u5358\u3067\u3059\u3002
\n\u3057\u304b\u3057Chef11\u7248\u3067\u306f\u3001\u30b9\u30bf\u30c3\u30af\u5185\u306b\u306f1\u3064\u306eRails\u30ec\u30a4\u30e4\u30fc\u3057\u304b\u4f5c\u6210\u51fa\u6765\u306a\u3044\u3088\u3046\u306b\u306a\u3063\u3066\u304a\u308a\u3001\u30b9\u30bf\u30c3\u30af\u5185\u30672\u3064\u4ee5\u4e0a\u306eRails\u30a2\u30d7\u30ea\u304c\u5fc5\u8981\u3068\u306a\u3063\u305f\u5834\u5408\u3001\u81ea\u5206\u3067\u7528\u610f\u3057\u306a\u3051\u308c\u3070\u306a\u308a\u307e\u305b\u3093\u3002
\n\u4eca\u56de\u306f\u30b9\u30bf\u30c3\u30af\u5185\u306b\u3001\u3044\u304f\u3064\u3082\u4f5c\u308b\u3053\u3068\u304c\u51fa\u6765\u308bCustom\u30ec\u30a4\u30e4\u30fc\u3092\u4f7f\u3063\u3066\u3001\u8907\u6570\u306e\u30ab\u30b9\u30bf\u30e0Rails\u30ec\u30a4\u30e4\u30fc\u3092\u4f5c\u6210\u3057\u3001\u5404\u30ec\u30a4\u30e4\u30fc\u306bRails\u30a2\u30d7\u30ea\u3092\u30c7\u30d7\u30ed\u30a4\u3059\u308bOpsWorks\u74b0\u5883\u3092\u69cb\u7bc9\u3057\u3066\u307f\u307e\u3057\u305f\u3002<\/p>\n

\u30b4\u30fc\u30eb\u56f3<\/h4>\n

\"\"<\/p>\n

\u6e96\u5099<\/h2>\n

\u5fc5\u8981\u306a\u3082\u306e<\/h4>\n

VPC(\u30c7\u30d5\u30a9\u30eb\u30c8\u3067\u3082\u826f\u3044), EC2\u7528\u30bb\u30ad\u30e5\u30ea\u30c6\u30a3\u30b0\u30eb\u30fc\u30d7, EC2\u30ad\u30fc\u30da\u30a2, RDS(MySQL 5.6.27), Rails\u30a2\u30d7\u30ea\u30b1\u30fc\u30b7\u30e7\u30f3(Rails 4.2.6, ruby 2.2.5, bundler 1.12.4, GitHub\u304bBitBucket\u306b\u30a2\u30c3\u30d7\u30ed\u30fc\u30c9\u3055\u308c\u3066\u3044\u308b\u72b6\u614b), Custom Chef Cookbooks\u30ec\u30dd\u30b8\u30c8\u30ea<\/p>\n

OpsWorks\u6e96\u5099<\/h4>\n

OpsWorks\u306eStack\u3092\u4f5c\u6210\u3057\u3001Custom\u30ec\u30a4\u30e4\u30fc\u306e\u4f5c\u6210\u3001RDS\u306e\u8a2d\u5b9a\u3001\u30a2\u30d7\u30ea\u30b1\u30fc\u30b7\u30e7\u30f3\u306e\u8a2d\u5b9a\u306a\u3069\u3092\u6e08\u307e\u305b\u3066\u304a\u304d\u307e\u3059\u3002<\/p>\n

Custom Layer\u306bRails\u30a2\u30d7\u30ea\u3092\u30c7\u30d7\u30ed\u30a4\u3059\u308b5\u3064\u306e\u8a2d\u5b9a<\/h2>\n

1. OpsWorks Stack\u306bCustomJSON\u3092\u30bb\u30c3\u30c8<\/h4>\n

\u30c7\u30d7\u30ed\u30a4\u6642\u306bmigration\u3059\u308b\u70ba\u306e\u8a2d\u5b9a\u3067\u3059\u3002<\/p>\n

{\n  "deploy": {\n    "\u30a2\u30d7\u30ea\u30b1\u30fc\u30b7\u30e7\u30f3\u540d": {\n      "migrate": true\n    }\n  }\n}<\/code><\/pre>\n

2. Custom Layer\u306bCustomJSON\u3092\u30bb\u30c3\u30c8<\/h4>\n

Stack\u306eCustomJSON\u306b\u8a2d\u5b9a\u3057\u3066\u3082\u826f\u3044\u306e\u3067\u3059\u304c\u3001Stack\u5185\u306b\u69d8\u3005\u306a\u30ec\u30a4\u30e4\u30fc\u304c\u5b58\u5728\u3059\u308b\u5834\u5408\u306bRails\u30ec\u30a4\u30e4\u30fc\u306b\u3060\u3051CustomJSON\u3092\u30bb\u30c3\u30c8\u3057\u305f\u3044\u306e\u3067\u3001\u30ec\u30a4\u30e4\u30fc\u306b\u30bb\u30c3\u30c8\u3057\u307e\u3059\u3002
\nruby_version 2.2<\/code>\u3068\u306a\u3063\u3066\u3044\u307e\u3059\u304c\u3001\u30ce\u30fc\u30c9\u306b\u306f2.2\u306e\u6700\u65b0\u306e\u30d0\u30fc\u30b8\u30e7\u30f3\u304c\u30a4\u30f3\u30b9\u30c8\u30fc\u30eb\u3055\u308c\u307e\u3059\u3002(2016\/6\/3\u73fe\u5728\u306f2.2.5)<\/p>\n

{\n  "opsworks": {\n    "rails_stack": {\n      "name": "nginx_unicorn"\n    },\n    "ruby_version": "2.2"\n  },\n  "languages": {\n    "ruby": {\n      "ruby_bin": "\/usr\/bin\/ruby"\n    }\n  },\n  "rails": {\n    "max_pool_size": 2\n  },\n  "unicorn": {\n  },\n  "opsworks_bundler": {\n    "version": "1.12.4",\n    "manage_package": true\n  }\n}<\/code><\/pre>\n

3. \u30ec\u30a4\u30e4\u30fc\u306b\u30ec\u30b7\u30d4\u3092\u30bb\u30c3\u30c8<\/h4>\n

OpsWorks\u3067\u7528\u610f\u3055\u308c\u3066\u3044\u308b\u30ec\u30b7\u30d4\u3092\u4f7f\u3044\u307e\u3059\u3002<\/p>\n

\"\"<\/p>\n

4. \u30c7\u30d7\u30ed\u30a4\u30ec\u30b7\u30d4\u3092\u7528\u610f\u3057\u3001deploy.rb\u3092\u4fee\u6b63<\/h4>\n

OpsWorks Chef 11.10: release-chef-11.10 (2016\/6\/3\u73fe\u5728)<\/a>\u3092\u30c0\u30a6\u30f3\u30ed\u30fc\u30c9\u3057\u3066\u3001deploy<\/code>\u30ec\u30b7\u30d4\u3092\u30c7\u30a3\u30ec\u30af\u30c8\u30ea\u3054\u3068\u81ea\u5206\u306e\u30ab\u30b9\u30bf\u30e0Cookbooks\u306b\u6301\u3063\u3066\u884c\u304d\u3001\u4e0b\u8a18\u30b3\u30fc\u30c9\u3060\u3051\u7de8\u96c6\u3057\u3066git push<\/code>\u3057\u307e\u3059\u3002<\/p>\n

deploy\/definition\/opsworks_deploy.rb<\/code><\/p>\n

81\u884c\u76ee\u3042\u305f\u308a<\/strong><\/p>\n

# \u5909\u66f4\u524d  if deploy[:application_type] == 'rails' && node[:opsworks][:instance][:layers].include?('rails-app')\n  if deploy[:application_type] == 'rails' && deploy[:application] == '\u30a2\u30d7\u30ea\u30b1\u30fc\u30b7\u30e7\u30f3\u540d'\n    restart_command "sleep #{deploy[:sleep_before_restart]} && #{node[:opsworks][:rails_stack][:restart_command]}"\n  end<\/code><\/pre>\n

174\u884c\u76ee\u3042\u305f\u308a<\/strong><\/p>\n

# \u5909\u66f4\u524d if deploy[:application_type] == 'rails' && node[:opsworks][:instance][:layers].include?('rails-app')\n  if deploy[:application_type] == 'rails' && deploy[:application] == '\u30a2\u30d7\u30ea\u30b1\u30fc\u30b7\u30e7\u30f3\u540d'\n    case node[:opsworks][:rails_stack][:name]<\/code><\/pre>\n

171\u884c\u76ee\u3042\u305f\u308a\u306fUnicorn\u306e\u518d\u8d77\u52d5\u8a2d\u5b9a\u3001174\u884c\u76ee\u3042\u305f\u308a\u306fNginx\u306eUnicorn\u8a2d\u5b9a\u3067\u3059\u3002<\/p>\n

5. Rails\u30a2\u30d7\u30ea\u306eGemfile\u306bunicorn\u3092\u8a18\u5165\u3059\u308b<\/h4>\n

Gemfile<\/code><\/p>\n

group :staging, :production do\n  gem 'unicorn'\nend<\/code><\/pre>\n
\n

\u624b\u3063\u53d6\u308a\u65e9\u304f\u5b9f\u88c5\u3057\u305f\u3044\u65b9\u306f\u3001\u4e0a\u8a18\u5b9f\u88c5\u3060\u3051\u3067\u3044\u3051\u308b\u304b\u3068\u601d\u3044\u307e\u3059\u306e\u3067\u304a\u8a66\u3057\u304f\u3060\u3055\u3044\u3002
\n\u30c7\u30d0\u30c3\u30b0\u306a\u3069\u3067\u4e0a\u8a18\u8a2d\u5b9a\u306b\u305f\u3069\u308a\u7740\u3044\u305f\u7d4c\u7def\u306a\u3069\u3092\u66f8\u304d\u305f\u304b\u3063\u305f\u306e\u3067\u3059\u304c\u3001\u529b\u5c3d\u304d\u307e\u3057\u305f\u3002\u3002
\n\u672c\u5f53\u306f\u305d\u3063\u3061\u306e\u307b\u3046\u304c\u5927\u4e8b\u304b\u3082\u3057\u308c\u307e\u305b\u3093\u3002<\/p>\n

\u5f0a\u793e\u306fAWS\u306b\u3088\u308b\u30b9\u30b1\u30fc\u30e9\u30d6\u30eb\u3067\u7d20\u65e9\u3044\u30b5\u30fc\u30d3\u30b9\u69cb\u7bc9\u3092\u5f97\u610f\u3068\u3057\u3066\u304a\u308a\u307e\u3059\u306e\u3067\u3001\u3044\u3064\u3082\u3067\u3054\u76f8\u8ac7\u304f\u3060\u3055\u3044\u307e\u305b\uff01<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"

\u524d\u7530\u3067\u3059\u3002 \u4eca\u3061\u3087\u3046\u3069AWS\u30b5\u30df\u30c3\u30c8\u304c\u958b\u50ac\u3055\u308c\u3066\u3044\u307e\u3059\u306d\u3002 \u6628\u5e74\u306e\u3088\u3046\u306bYouTube\u306b\u30a2\u30c3\u30d7\u3055\u308c\u308b\u3068\u601d\u3044\u307e\u3059\u306e\u3067\u3001\u307e\u305f\u6642\u9593\u304c\u3042\u308b\u6642\u306b\u898b\u3066\u307f\u3088\u3046\u304b\u3068\u601d\u3063\u3066\u3044\u307e\u3059\u3002 \u3055\u3066\u30d6\u30ed\u30b0\u3067\u3059\u304c\u3001\u524d\u56de\u306e\u7d9a\u304d\u306e\u300cChef12\u306b\u5bfe\u5fdc\u3057\u305fAWS OpsWorks\u306bRails\u30a2\u30d7\u30ea\u3092\u30c7\u30d7\u30ed\u30a4\u3059\u308b\u300d\u306e\u7b2c3\u56de\u76ee\u3092\u3084\u308d\u3046\u304b\u3068\u601d\u3044\u307e\u3057\u305f\u304c\u3001\u5c11\u3057\u5909\u3048\u3066\u3001\u300cOpsWorks Chef11\u7248\u306b\u3001\u8907\u6570\u306eRails\u30a2\u30d7\u30ea\u3092\u30c7\u30d7\u30ed\u30a4\u3067\u304d\u308b […]<\/p>\n","protected":false},"author":1,"featured_media":826,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[13],"tags":[84,42],"aioseo_notices":[],"_links":{"self":[{"href":"https:\/\/p-corporate-blog-cms.mmmcorp.co.jp\/wp-json\/wp\/v2\/posts\/272"}],"collection":[{"href":"https:\/\/p-corporate-blog-cms.mmmcorp.co.jp\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/p-corporate-blog-cms.mmmcorp.co.jp\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/p-corporate-blog-cms.mmmcorp.co.jp\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/p-corporate-blog-cms.mmmcorp.co.jp\/wp-json\/wp\/v2\/comments?post=272"}],"version-history":[{"count":0,"href":"https:\/\/p-corporate-blog-cms.mmmcorp.co.jp\/wp-json\/wp\/v2\/posts\/272\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/p-corporate-blog-cms.mmmcorp.co.jp\/wp-json\/wp\/v2\/media\/826"}],"wp:attachment":[{"href":"https:\/\/p-corporate-blog-cms.mmmcorp.co.jp\/wp-json\/wp\/v2\/media?parent=272"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/p-corporate-blog-cms.mmmcorp.co.jp\/wp-json\/wp\/v2\/categories?post=272"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/p-corporate-blog-cms.mmmcorp.co.jp\/wp-json\/wp\/v2\/tags?post=272"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}