{"id":5123,"date":"2020-03-31T20:55:44","date_gmt":"2020-03-31T11:55:44","guid":{"rendered":"https:\/\/yumishin.com\/?p=5123"},"modified":"2020-04-01T08:56:32","modified_gmt":"2020-03-31T23:56:32","slug":"rails5-mysql-docker-heroku","status":"publish","type":"post","link":"https:\/\/yumishin.com\/?p=5123","title":{"rendered":"Rails5\uff0bMySQL\uff0bDocker\u3092Heroku\u306b\u30c7\u30d7\u30ed\u30a4\u3059\u308b\u65b9\u6cd5"},"content":{"rendered":"<p>Rails5\uff0bMySQL\uff0bDocker\u3092Heroku\u306b\u30c7\u30d7\u30ed\u30a4\u3059\u308b\u65b9\u6cd5\u306b\u3064\u3044\u3066\u7c21\u5358\u306b\u307e\u3068\u3081\u3066\u304a\u304f\u3002<\/p>\n<h2 id=\"i-0\">\u74b0\u5883<\/h2>\n<ul>\n<li>macOS Catalina 10.15.4<\/li>\n<li>Ruby 2.5.3<\/li>\n<li>Rails 5.2.4<\/li>\n<li>MySQL 5.7<\/li>\n<li>Heroku 7.39.1<\/li>\n<li>Git 2.24.1<\/li>\n<\/ul>\n<h2 id=\"i-1\">\u524d\u63d0<\/h2>\n<ol>\n<li>Rails5 + MySQL\u306eDocker\u74b0\u5883\u3092\u4f5c\u6210\u3057\u3001\u30d6\u30e9\u30a6\u30b6\u4e0a\u3067localhost:3000\u306b\u30a2\u30af\u30bb\u30b9\u3057\u3066\u30b5\u30fc\u30d0\u30fc\u306e\u8d77\u52d5\u3092\u78ba\u8a8d\u3057\u3066\u3044\u308b\u3053\u3068<\/li>\n<li>Heroku\u306b\u30af\u30ec\u30b8\u30c3\u30c8\u30ab\u30fc\u30c9\u767b\u9332\u3092\u3057\u3066\u3044\u3066\u3001MySQL\u3092Heroku\u3067\u4f7f\u3048\u308b\u3088\u3046\u306b\u306a\u3063\u3066\u3044\u308b\u3053\u3068<\/li>\n<\/ol>\n<h2 id=\"i-2\">Heroku\u3078\u306e\u30c7\u30d7\u30ed\u30a4\u624b\u9806<\/h2>\n<div class=\"tl\">\n<div class=\"tl-content main-bdr\">\n<div class=\"tl_label\">STEP.1<\/div>\n<div class=\"tl_title\">\u30a2\u30d7\u30ea\u30d5\u30a9\u30eb\u30c0\u76f4\u4e0b\uff08Gemfile\u3068\u540c\u3058\u968e\u5c64\uff09\u306bheroku.yml\u306e\u4f5c\u6210<\/div>\n<div class=\"tl_main\">\n<div class=\"pre_tag\"><span><i class=\"fa fa-code\"><\/i> \u30bf\u30fc\u30df\u30ca\u30eb<\/span><\/p>\n<pre><code>$ touch heroku.yml<\/code><\/pre>\n<\/div>\n<p>\u30a2\u30d7\u30ea\u30d5\u30a9\u30eb\u30c0\u306e\u76f4\u4e0b\u306bheroku.yml\u30d5\u30a1\u30a4\u30eb\u3092\u4f5c\u6210\u3002Gemfile\u3084gitignore\u306a\u3069\u3068\u540c\u3058\u968e\u5c64\u3002heroku.yml\u306f\u4f7f\u3063\u3066\u3044\u308b\u30c6\u30ad\u30b9\u30c8\u30a8\u30c7\u30a3\u30bf\u3067\u4f5c\u6210\u3057\u3066\u3082\u3044\u3044\u3057\u3001\u30bf\u30fc\u30df\u30ca\u30eb\u304b\u3089\u4f5c\u6210\u3057\u3066\u3082OK\u3002touch\u30b3\u30de\u30f3\u30c9\u306f\u30d5\u30a1\u30a4\u30eb\u3092\u4f5c\u6210\u3059\u308b\u6642\u306b\u4f7f\u3046\u30b3\u30de\u30f3\u30c9\u3002<\/p>\n<div class=\"pre_tag\"><span><i class=\"fa fa-code\"><\/i> heroku.yml<\/span><\/p>\n<pre><code>build:\n  docker:\n    web: Dockerfile\nrun:\n  web: bundle exec puma -C config\/puma.rb<\/code><\/pre>\n<\/div>\n<p>\u4f5c\u6210\u3057\u305fheroku.yml\u306b\u306f\u4e0a\u8a18\u5185\u5bb9\u3092\u8a18\u8ff0\u3002\u30d5\u30a1\u30a4\u30eb\u306e\u5185\u5bb9\u306fDockerfile\u306b\u8a18\u8ff0\u3057\u305f\u5185\u5bb9\u306b\u3057\u305f\u304c\u3063\u3066\u30b3\u30f3\u30c6\u30ca\u3092Heroku\u306bUp\u3057\u3066\u304f\u3060\u3055\u3044\u306d\u3001\u305d\u3057\u3066puma\u3082\u52d5\u304b\u3057\u3066\u304f\u3060\u3055\u3044\u306d\u3001\u3068\u3044\u3046\u611f\u3058<\/p>\n<\/div>\n<div class=\"tl_marker main-bdr main-bc\"><\/div>\n<\/div>\n<div class=\"tl-content main-bdr\">\n<div class=\"tl_label\">STEP.2<\/div>\n<div class=\"tl_title\">Heroku\u306b\u30ed\u30b0\u30a4\u30f3\u3059\u308b<\/div>\n<div class=\"tl_main\">\n<div class=\"pre_tag\"><span><i class=\"fa fa-code\"><\/i> \u30bf\u30fc\u30df\u30ca\u30eb<\/span><\/p>\n<pre><code>$ heroku login<\/code><\/pre>\n<\/div>\n<p>\u4f5c\u6210\u3057\u305fheroku.yml\u306b\u306f\u4e0b\u8a18\u5185\u5bb9\u3092\u8a18\u8ff0\u3002\u9014\u4e2d\u3067\u30a8\u30f3\u30bf\u30fc\u30ad\u30fc\u3092\u62bc\u3059\u3068\u30d6\u30e9\u30a6\u30b6\u304c\u7acb\u3061\u4e0a\u304c\u308b\u3002\u30d6\u30e9\u30a6\u30b6\u64cd\u4f5c\u3067\u30ed\u30b0\u30a4\u30f3\u304c\u7d42\u308f\u308b\u3068\u3001\u30bf\u30fc\u30df\u30ca\u30eb\u306e\u65b9\u3082\u30ed\u30b0\u30a4\u30f3\u3067\u304d\u308b\u3002<\/p>\n<\/div>\n<div class=\"tl_marker main-bdr main-bc\"><\/div>\n<\/div>\n<div class=\"tl-content main-bdr\">\n<div class=\"tl_label\">STEP.3<\/div>\n<div class=\"tl_title\">Heroku\u306e\u30a2\u30d7\u30ea\u30b1\u30fc\u30b7\u30e7\u30f3\u3092\u4f5c\u6210\u3059\u308b<\/div>\n<div class=\"tl_main\">\n<div class=\"pre_tag\"><span><i class=\"fa fa-code\"><\/i> \u30bf\u30fc\u30df\u30ca\u30eb<\/span><\/p>\n<pre><code>$ heroku create<\/code><\/pre>\n<\/div>\n<p>\u4f5c\u6210\u3057\u305fheroku.yml\u306b\u306f\u4e0b\u8a18\u5185\u5bb9\u3092\u8a18\u8ff0\u3002\u3061\u306a\u307f\u306b$ heroku create \u597d\u304d\u306a\u540d\u524d \u3067\u305d\u306e\u597d\u304d\u306a\u540d\u524d\u304c\u30a2\u30d7\u30ea\u540d\u306eURL\u306b\u4f7f\u3048\u308b\u3002<\/p>\n<\/div>\n<div class=\"tl_marker main-bdr main-bc\"><\/div>\n<\/div>\n<div class=\"tl-content main-bdr\">\n<div class=\"tl_label\">STEP.4<\/div>\n<div class=\"tl_title\">Heroku\u3067MySQL\u3092\u4f7f\u7528\u3067\u304d\u308b\u3088\u3046\u306b\u3059\u308b<\/div>\n<div class=\"tl_main\">\n<div class=\"pre_tag\"><span><i class=\"fa fa-code\"><\/i> \u30bf\u30fc\u30df\u30ca\u30eb<\/span><\/p>\n<pre><code>$ heroku addons:add cleardb:ignite --version=5.7<\/code><\/pre>\n<\/div>\n<p>Heroku\u3067\u306fPostgresQL\u304c\u57fa\u672c\u7684\u306b\u7121\u6599\u3067\u4f7f\u3048\u308b\u304c\u3001Heroku\u306b\u30af\u30ec\u30b8\u30c3\u30c8\u30ab\u30fc\u30c9\u767b\u9332\u3055\u308c\u3066\u3044\u308b\u3068MySQL\u3082\u4f7f\u7528\u3067\u304d\u308b\u3002\u4e0a\u8a18\u30b3\u30de\u30f3\u30c9\u3092\u5165\u529b\u3002<\/p>\n<p>Heroku\u306e\u8ffd\u52a0\u30aa\u30d7\u30b7\u30e7\u30f3\u3067\u3042\u308bcleardb\u3068\u3044\u3046MySQL\u7528\u3092\u4f7f\u3048\u308b\u3088\u3046\u306b\u3059\u308b\u30a2\u30c9\u30aa\u30f3\u3092\u5165\u308c\u3066\u304f\u3060\u3055\u3044\u306d\u3001ignite\u3068\u3044\u3046\u7121\u6599\u306e\u3084\u3064\u3002\u305d\u3057\u3066MySQL\u306e\u30d0\u30fc\u30b8\u30e7\u30f3\u306f5.7\u3067\u304a\u9858\u3044\u3057\u307e\u3059\u3068\u3044\u3046\u611f\u3058\u3002<\/p>\n<p>Heroku\u5074\u306e\u8a2d\u5b9a\u3060\u3068MySQL5.6\u304c\u6700\u521d\u306f\u8a2d\u5b9a\u3055\u308c\u3066\u3044\u308b\u3002\u30a2\u30d7\u30ea\u3067\u4f7f\u3063\u3066\u3044\u308b\u30d0\u30fc\u30b8\u30e7\u30f3\u3092\u5408\u308f\u305b\u306a\u3044\u3068\u63a5\u7d9a\u30a8\u30e9\u30fc\u304c\u8d77\u304d\u308b\u3053\u3068\u304c\u3042\u308b\u306e\u3067\u3001\u30d0\u30fc\u30b8\u30e7\u30f3\u306f\u958b\u767a\u74b0\u5883\u3068\u30c7\u30d7\u30ed\u30a4\u3059\u308b\u74b0\u5883\u3067\u5408\u308f\u305b\u305f\u307b\u3046\u304c\u3044\u3044\u3002<\/p>\n<\/div>\n<div class=\"tl_marker main-bdr main-bc\"><\/div>\n<\/div>\n<div class=\"tl-content main-bdr\">\n<div class=\"tl_label\">STEP.5<\/div>\n<div class=\"tl_title\">Heroku\u4e0a\u3067MySQL\u3092\u4f7f\u3046\u305f\u3081\u306e\u74b0\u5883\u5909\u6570\u3092\u8a2d\u5b9a\u3059\u308b<\/div>\n<div class=\"tl_main\">\n<div class=\"pre_tag\"><span><i class=\"fa fa-code\"><\/i> \u30bf\u30fc\u30df\u30ca\u30eb<\/span><\/p>\n<pre><code>$ heroku config:set DATABASE_URL=`heroku config:get CLEARDB_DATABASE_URL | sed -- s\/mysql\/mysql2\/`<\/code><\/pre>\n<\/div>\n<p>\u3053\u306e\u8fba\u308a\u306e\u8a2d\u5b9a\u306fHeroku\u516c\u5f0f\u30db\u30fc\u30e0\u30da\u30fc\u30b8\u306b\u8a18\u8f09\u3055\u308c\u3066\u3044\u308b\u3068\u304a\u308a\u306b\u9032\u3081\u3066\u3044\u308b\u3002\u6c17\u306b\u306a\u308b\u65b9\u306f\u516c\u5f0f\u30db\u30fc\u30e0\u30da\u30fc\u30b8\u8981\u53c2\u7167\u3002<\/p>\n<\/div>\n<div class=\"tl_marker main-bdr main-bc\"><\/div>\n<\/div>\n<div class=\"tl-content main-bdr\">\n<div class=\"tl_label\">STEP.6<\/div>\n<div class=\"tl_title\">Heroku\u5074\u3067Stack\u3092container\u306b\u30bb\u30c3\u30c8\u3059\u308b<\/div>\n<div class=\"tl_main\">\n<div class=\"pre_tag\"><span><i class=\"fa fa-code\"><\/i> \u30bf\u30fc\u30df\u30ca\u30eb<\/span><\/p>\n<pre><code>$ heroku stack:set container<\/code><\/pre>\n<\/div>\n<p>Heroku\u306b\u306f\u30b3\u30f3\u30c6\u30ca\u3092\u30c7\u30d7\u30ed\u30a4\u3059\u308b\u65b9\u6cd5\u304c\u3044\u304f\u3064\u304b\u3042\u308b\u304cHeroku.yml\u3092\u4f7f\u3063\u3066\u30c7\u30d7\u30ed\u30a4\u3059\u308b\u306b\u306f\u4e0a\u8a18\u30b3\u30de\u30f3\u30c9\u304c\u5fc5\u8981\u3002\u3053\u308c\u3082Heroku\u306e\u516c\u5f0f\u30db\u30fc\u30e0\u30da\u30fc\u30b8\u306b\u4e57\u3063\u3066\u3044\u308b\u306e\u3067\u8981\u78ba\u8a8d\u3002<\/p>\n<\/div>\n<div class=\"tl_marker main-bdr main-bc\"><\/div>\n<\/div>\n<div class=\"tl-content main-bdr\">\n<div class=\"tl_label\">STEP.7<\/div>\n<div class=\"tl_title\">Heroku\u306b\u30c7\u30d7\u30ed\u30a4\u3059\u308b<\/div>\n<div class=\"tl_main\">\n<div class=\"pre_tag\"><span><i class=\"fa fa-code\"><\/i> \u30bf\u30fc\u30df\u30ca\u30eb<\/span><\/p>\n<pre><code>$ git init\n$ git add -A\n$ git commit -m \"\u30b3\u30df\u30c3\u30c8\u30e1\u30c3\u30bb\u30fc\u30b8\"\n$ git push heroku master<\/code><\/pre>\n<\/div>\n<\/div>\n<div class=\"tl_marker main-bdr main-bc\"><\/div>\n<\/div>\n<div class=\"tl-content main-bdr\">\n<div class=\"tl_label\">STEP.8<\/div>\n<div class=\"tl_title\">\u30c7\u30d7\u30ed\u30a4\u3067\u304d\u3066\u3044\u308b\u304b\u78ba\u8a8d\u3059\u308b<\/div>\n<div class=\"tl_main\">\n<div class=\"pre_tag\"><span><i class=\"fa fa-code\"><\/i> \u30bf\u30fc\u30df\u30ca\u30eb<\/span><\/p>\n<pre><code>$ heroku open<\/code><\/pre>\n<\/div>\n<\/div>\n<div class=\"tl_marker main-bdr main-bc\"><\/div>\n<\/div>\n<\/div>\n","protected":false},"excerpt":{"rendered":"<p>Rails5\uff0bMySQL\uff0bDocker\u3092Heroku\u306b\u30c7\u30d7\u30ed\u30a4\u3059\u308b\u65b9\u6cd5\u306b\u3064\u3044\u3066\u7c21\u5358\u306b\u307e\u3068\u3081\u3066\u304a\u304f\u3002 \u74b0\u5883 macOS Catalina 10.15.4 Ruby 2.5.3 Rails 5.2.4 MySQL 5.7 H &#8230; <\/p>\n","protected":false},"author":1,"featured_media":5143,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[272],"tags":[],"class_list":{"0":"post-5123","1":"post","2":"type-post","3":"status-publish","4":"format-standard","5":"has-post-thumbnail","7":"category-programing","8":"entry"},"_links":{"self":[{"href":"https:\/\/yumishin.com\/index.php?rest_route=\/wp\/v2\/posts\/5123","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/yumishin.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/yumishin.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/yumishin.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/yumishin.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=5123"}],"version-history":[{"count":3,"href":"https:\/\/yumishin.com\/index.php?rest_route=\/wp\/v2\/posts\/5123\/revisions"}],"predecessor-version":[{"id":5142,"href":"https:\/\/yumishin.com\/index.php?rest_route=\/wp\/v2\/posts\/5123\/revisions\/5142"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/yumishin.com\/index.php?rest_route=\/wp\/v2\/media\/5143"}],"wp:attachment":[{"href":"https:\/\/yumishin.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=5123"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/yumishin.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=5123"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/yumishin.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=5123"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}