{"id":167,"date":"2015-05-15T17:39:20","date_gmt":"2015-05-15T08:39:20","guid":{"rendered":"https:\/\/p-corporate-blog-cms.mmmcorp.co.jp\/blog\/2015\/05\/15\/heroku-practice"},"modified":"2015-05-15T17:39:20","modified_gmt":"2015-05-15T08:39:20","slug":"heroku-practice","status":"publish","type":"post","link":"https:\/\/p-corporate-blog-cms.mmmcorp.co.jp\/blog\/2015\/05\/15\/heroku-practice\/","title":{"rendered":"Heroku\u306e\u30c7\u30fc\u30bf\u30d9\u30fc\u30b9\u64cd\u4f5c"},"content":{"rendered":"

\u307e\u305f\u307e\u305f\u73fe\u5728\u30bb\u30d6\u306b\u6765\u3066\u304a\u308a\u307e\u3057\u3066\u3001\u4f1a\u793e\u5185\u304b\u3089\u306f\u3059\u3067\u306b\u3042\u3063\u3061\u306e\u4eba\u6271\u3044\u306b\u306a\u3063\u3066\u3044\u308b\u524d\u7530\u3067\u3059\u3002<\/p>\n

\u73fe\u5728\u81ea\u793e\u3067\u4f5c\u3063\u3066\u3044\u308b\u30a2\u30d7\u30ea\u30b1\u30fc\u30b7\u30e7\u30f3\u306f\u3001Heroku<\/a>\u3092\u4f7f\u7528\u3057\u3066\u304a\u308a\u307e\u3059\u3002
\n
Heroku<\/a>\u3092\u3054\u5b58\u77e5\u3067\u306a\u3044\u65b9\u3082\u3044\u3089\u3063\u3057\u3083\u3089\u308c\u308b\u304b\u3082\u3057\u308c\u307e\u305b\u3093\u304c\u3001git\u30b3\u30de\u30f3\u30c9\u3060\u3051\u3067\u7c21\u5358\u306bWeb\u30b5\u30fc\u30d3\u30b9\u3092\u30c7\u30d7\u30ed\u30a4\u3067\u304d\u308b\u30b5\u30fc\u30d3\u30b9\u3067\u3059\u3002
\nWeb\u30b5\u30fc\u30d3\u30b9\u3092\u30c7\u30d7\u30ed\u30a4\u3059\u308b\u70ba\u306b\u306f\u304a\u304a\u307e\u304b\u306b\u4ee5\u4e0b\u306e\u5de5\u7a0b\u304c\u5fc5\u8981\u3067\u3059\u3002<\/p>\n

1 \u30a4\u30f3\u30bf\u30fc\u30cd\u30c3\u30c8\u304b\u3089\u30a2\u30af\u30bb\u30b9\u53ef\u80fd\u306a\u30b5\u30fc\u30d0\u3092\u6e96\u5099
\n2 HTTP\u30b5\u30fc\u30d0\u3092\u30a4\u30f3\u30b9\u30c8\u30fc\u30eb
\n3 \u30c7\u30fc\u30bf\u30d9\u30fc\u30b9\u3092\u30a4\u30f3\u30b9\u30c8\u30fc\u30eb
\n4 \u30a2\u30d7\u30ea\u30b1\u30fc\u30b7\u30e7\u30f3\u3092\u6e96\u5099<\/p>\n

Heroku<\/a>\u306f\u4e0a\u8a18\u5de5\u7a0b\u306e1~3\u307e\u3067\u3092\u7c21\u5358\u306b\u6e96\u5099\u3067\u304d\u308b\u30b5\u30fc\u30d3\u30b9\u3067\u3059\u3002
\n\u958b\u767a\u8005\u306f\u81ea\u5206\u306e\u30a2\u30d7\u30ea\u3092\u3069\u306e\u3088\u3046\u306b\u4f5c\u308b\u304b\u3060\u3051\u306b\u5c02\u5ff5\u3067\u304d\u308b\u3068\u3044\u3046\u3053\u3068\u3067\u3059\u306d\u3002
\n\u30b9\u30bf\u30fc\u30c8\u30a2\u30c3\u30d7\u3067\u65e9\u304f\u30b5\u30fc\u30d3\u30b9\u3092\u30ea\u30ea\u30fc\u30b9\u3057\u305f\u3044\u5834\u5408\u306a\u3069\u306b\u3082\u3063\u3066\u3053\u3044\u3067\u3059\u3002
\n\u79c1\u3082\u30a4\u30f3\u30d5\u30e9\u3092\u52c9\u5f37\u4e2d\u3067\u3059\u304c\u3068\u3066\u3082\u96e3\u3057\u304f\u3001\u3059\u3050\u306b\u30de\u30b9\u30bf\u30fc\u3067\u304d\u308b\u3068\u3044\u3046\u5206\u91ce\u3067\u306f\u306a\u3044\u70ba\u3001
Heroku<\/a>\u306e\u3088\u3046\u306a\u30b5\u30fc\u30d3\u30b9\u306f\u5927\u5909\u6709\u96e3\u3044\u5b58\u5728\u3067\u3059\u3002<\/p>\n

Heroku<\/a>\u306e\u60c5\u5831\u306f\u305f\u304f\u3055\u3093\u30a4\u30f3\u30bf\u30fc\u30cd\u30c3\u30c8\u4e0a\u306b\u3042\u308a\u307e\u3059\u304c\u3001Heroku\u30b3\u30de\u30f3\u30c9\u3067Heroku\u30b5\u30fc\u30d0\u4e0a\u306ePostgreSQL\u306e\u64cd\u4f5c\u65b9\u6cd5\u306a\u3069\u3092\u5099\u5fd8\u9332\u304c\u3066\u3089\u66f8\u3044\u3066\u3044\u304d\u307e\u3059\u3002<\/p>\n

\u958b\u767a\u6a5f\u306fmac\u3001\u30a2\u30d7\u30ea\u30b1\u30fc\u30b7\u30e7\u30f3\u306fRuby on Rails\u3067\u69cb\u7bc9\u3057\u307e\u3059\u3002<\/p>\n

Heroku\u306e\u6e96\u5099<\/h4>\n

\u30a2\u30ab\u30a6\u30f3\u30c8\u304c\u307e\u3060\u306e\u5834\u5408\u306f\u30a2\u30ab\u30a6\u30f3\u30c8\u3092\u3053\u3061\u3089<\/a>\u304b\u3089\u4f5c\u308a\u307e\u3059\u3002<\/p>\n

Heroku\u30b3\u30de\u30f3\u30c9\u30e9\u30a4\u30f3\u30c4\u30fc\u30eb\u3092\u30a4\u30f3\u30b9\u30c8\u30fc\u30eb\u3002
\n
\u30b3\u30de\u30f3\u30c9\u30e9\u30a4\u30f3\u30c4\u30fc\u30eb<\/a><\/p>\n

\u78ba\u8a8d<\/p>\n

$ which heroku\n\/usr\/bin\/heroku<\/code><\/pre>\n

Heroku\u30b3\u30de\u30f3\u30c9\u304c\u4f7f\u3048\u308b\u3088\u3046\u306b\u30ed\u30b0\u30a4\u30f3\u306e\u767b\u9332\u3092\u3057\u307e\u3059\u3002<\/p>\n

heroku login<\/code><\/pre>\n

\u30b5\u30a4\u30f3\u30a2\u30c3\u30d7\u6642\u306eemail\u3068password\u3092\u805e\u304b\u308c\u307e\u3059\u306e\u3067\u767b\u9332\u3057\u305f\u3089Heroku\u30b3\u30de\u30f3\u30c9\u306e\u6e96\u5099\u304c\u7d42\u4e86\u3067\u3059\u3002<\/p>\n

Heroku\u30ed\u30b0\u30a4\u30f3\u753b\u9762\u304b\u3089\u30b3\u30f3\u30bd\u30fc\u30eb\u306b\u30ed\u30b0\u30a4\u30f3\u3057\u3066\u30a2\u30d7\u30ea\u30b1\u30fc\u30b7\u30e7\u30f3\u3092\u4f5c\u6210\u3057\u307e\u3059\u3002
\n\u307e\u305f\u3001\u9069\u5f53\u306arails\u30a2\u30d7\u30ea\u30b1\u30fc\u30b7\u30e7\u30f3\u306a\u3069\u3092\u6e96\u5099\u3057\u307e\u3059\u3002<\/p>\n

\u30a2\u30d7\u30ea\u30b1\u30fc\u30b7\u30e7\u30f3\u30c7\u30a3\u30ec\u30af\u30c8\u30ea\u306b\u3066\u3001git\u306e\u8a2d\u5b9a\u3092\u3057\u307e\u3059\u3002<\/p>\n

git init\ngit add .\ngit commit -m 'first commit'\ngit remote add heroku https:\/\/git.heroku.com\/\u30a2\u30d7\u30ea\u30b1\u30fc\u30b7\u30e7\u30f3\u540d.git\n\n\/\/ \u30c7\u30d7\u30ed\u30a4\ngit push heroku master<\/code><\/pre>\n

\u30b3\u30f3\u30bd\u30fc\u30eb\u306b\u3066\u30c7\u30fc\u30bf\u30d9\u30fc\u30b9\u306e\u6e96\u5099\u3002<\/p>\n

\u30a2\u30d7\u30ea\u3092\u9078\u629e \u2192 Resources \u2192 Add-ons\u306elearn more about add-ons\u3092\u30af\u30ea\u30c3\u30af
\n\u4e0b\u8a18\u306e Heroku Postgres \u3092\u9078\u629e\u3057\u307e\u3059\u3002<\/p>\n

\"\"<\/p>\n

\u30a2\u30d7\u30ea\u30b1\u30fc\u30b7\u30e7\u30f3\u3092\u30b3\u30de\u30f3\u30c9\u304b\u3089\u64cd\u4f5c\u3067\u304d\u308b\u3088\u3046\u306b\u3057\u307e\u3059\u3002<\/p>\n

heroku git:remote -a \u30a2\u30d7\u30ea\u30b1\u30fc\u30b7\u30e7\u30f3\u540d<\/code><\/pre>\n

\u4ee5\u4e0a\u3067\u6e96\u5099\u304c\u5b8c\u4e86\u3067\u3059\u3002<\/p>\n

\u30b5\u30fc\u30d0\u30fc\u4e0a\u306eDB\u3092\u64cd\u4f5c\u3059\u308b<\/h4>\n
heroku pg:psql<\/code><\/pre>\n

\u554f\u984c\u7121\u3051\u308c\u3070\u4e0b\u8a18\u306e\u3088\u3046\u306b\u8868\u793a\u3055\u308c\u3001sql\u30b3\u30de\u30f3\u30c9\u304c\u53e9\u3051\u308b\u3088\u3046\u306b\u306a\u3063\u3066\u3044\u308b\u3068\u601d\u3044\u307e\u3059\u3002<\/p>\n

\u30a2\u30d7\u30ea\u30b1\u30fc\u30b7\u30e7\u30f3\u540d::DB\u540d-><\/code><\/pre>\n

\u30b5\u30fc\u30d0\u30fc\u4e0a\u3067\u30de\u30a4\u30b0\u30ec\u30fc\u30c8\u3059\u308b<\/h4>\n
heroku run rake db:migrate<\/code><\/pre>\n

\u305f\u3060\u30de\u30a4\u30b0\u30ec\u30fc\u30c8\u3057\u305f\u3060\u3051\u3067\u306f\u30c7\u30fc\u30bf\u304c\u53cd\u6620\u3055\u308c\u307e\u305b\u3093\u306e\u3067\u3001\u4e0b\u8a18\u30b3\u30de\u30f3\u30c9\u3067\u30ea\u30b9\u30bf\u30fc\u30c8\u3055\u305b\u308b\u5fc5\u8981\u304c\u3042\u308a\u307e\u3059\u3002<\/p>\n

heroku restart<\/code><\/pre>\n

\u30c7\u30fc\u30bf\u30d9\u30fc\u30b9\u306e\u30d0\u30c3\u30af\u30a2\u30c3\u30d7\u3092\u53d6\u308b<\/h4>\n
heroku pg:backups capture<\/code><\/pre>\n

\u53e4\u3044\u60c5\u5831\u3060\u3068\u4e0b\u8a18\u30b3\u30de\u30f3\u30c9\u306b\u306a\u3063\u3066\u3044\u307e\u3059\u304c\u3001\u73fe\u5728\u306f\u4e0a\u8a18\u30b3\u30de\u30f3\u30c9\u304c\u6b63\u3068\u306a\u308a\u307e\u3059\u3002<\/p>\n

heroku pgbackups:capture<\/code><\/pre>\n

\u6210\u529f\u3059\u308b\u3068\u3001\u4e0b\u8a18\u306e\u3088\u3046\u306a\u30ed\u30b0\u304c\u8868\u793a\u3055\u308c\u307e\u3059\u3002<\/p>\n

DATABASE_URL ---backup---> b003<\/code><\/pre>\n

\u30ec\u30b9\u30c8\u30a2\u306f\u4e0b\u8a18\u30b3\u30de\u30f3\u30c9\u3067\u3059\u3002<\/p>\n

heroku pg:backups restore b003 DATABASE_URL<\/code><\/pre>\n

Heroku\u306e\u516c\u5f0f\u30ea\u30d5\u30a1\u30ec\u30f3\u30b9<\/a>\u306b\u3082\u3046\u5c11\u3057\u8a73\u3057\u3044\u60c5\u5831\u304c\u63b2\u8f09\u3055\u308c\u3066\u304a\u308a\u307e\u3059\u306e\u3067\u3054\u89a7\u304f\u3060\u3055\u3044\u3002<\/p>\n

Heroku\u306f\u6771\u4eac\u30ea\u30fc\u30b8\u30e7\u30f3\u304c\u307e\u3060\u7121\u3044\u3088\u3046\u3067\u3059\u304c\u3001\u3082\u3057\u51fa\u6765\u308c\u3070\u66f4\u306b\u3088\u3044\u30b5\u30fc\u30d3\u30b9\u306b\u306a\u308a\u307e\u3059\u306d\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"

\u307e\u305f\u307e\u305f\u73fe\u5728\u30bb\u30d6\u306b\u6765\u3066\u304a\u308a\u307e\u3057\u3066\u3001\u4f1a\u793e\u5185\u304b\u3089\u306f\u3059\u3067\u306b\u3042\u3063\u3061\u306e\u4eba\u6271\u3044\u306b\u306a\u3063\u3066\u3044\u308b\u524d\u7530\u3067\u3059\u3002 \u73fe\u5728\u81ea\u793e\u3067\u4f5c\u3063\u3066\u3044\u308b\u30a2\u30d7\u30ea\u30b1\u30fc\u30b7\u30e7\u30f3\u306f\u3001Heroku\u3092\u4f7f\u7528\u3057\u3066\u304a\u308a\u307e\u3059\u3002 Heroku\u3092\u3054\u5b58\u77e5\u3067\u306a\u3044\u65b9\u3082\u3044\u3089\u3063\u3057\u3083\u3089\u308c\u308b\u304b\u3082\u3057\u308c\u307e\u305b\u3093\u304c\u3001git\u30b3\u30de\u30f3\u30c9\u3060\u3051\u3067\u7c21\u5358\u306bWeb\u30b5\u30fc\u30d3\u30b9\u3092\u30c7\u30d7\u30ed\u30a4\u3067\u304d\u308b\u30b5\u30fc\u30d3\u30b9\u3067\u3059\u3002 Web\u30b5\u30fc\u30d3\u30b9\u3092\u30c7\u30d7\u30ed\u30a4\u3059\u308b\u70ba\u306b\u306f\u304a\u304a\u307e\u304b\u306b\u4ee5\u4e0b\u306e\u5de5\u7a0b\u304c\u5fc5\u8981\u3067\u3059\u3002 1 \u30a4\u30f3\u30bf\u30fc\u30cd\u30c3\u30c8\u304b\u3089\u30a2\u30af\u30bb\u30b9\u53ef […]<\/p>\n","protected":false},"author":1,"featured_media":826,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[9],"tags":[],"aioseo_notices":[],"_links":{"self":[{"href":"https:\/\/p-corporate-blog-cms.mmmcorp.co.jp\/wp-json\/wp\/v2\/posts\/167"}],"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=167"}],"version-history":[{"count":0,"href":"https:\/\/p-corporate-blog-cms.mmmcorp.co.jp\/wp-json\/wp\/v2\/posts\/167\/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=167"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/p-corporate-blog-cms.mmmcorp.co.jp\/wp-json\/wp\/v2\/categories?post=167"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/p-corporate-blog-cms.mmmcorp.co.jp\/wp-json\/wp\/v2\/tags?post=167"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}