udemyのこちら
udemy
を学習中で、
gihub
上記アプリを作っています。
講座と全く同様に、
Rails 5系
Ruby 2.4.5
mysql2
Docker-composeでDBとwebに分けてローカルで作成し、herokuのデプロイをしようとしました。
しかし、heroku openにてApplication errorとなり、
heroku logs --tailにて
2020-08-31T00:05:17.338031+00:00 app[api]: Deployed web (09d5e5e0baba) by user shutainer@yahoo.co.jp 2020-08-31T00:05:17.338031+00:00 app[api]: Release v14 created by user shutainer@yahoo.co.jp 2020-08-31T00:05:17.566831+00:00 heroku[web.1]: State changed from crashed to starting 2020-08-31T00:05:33.102257+00:00 app[api]: Starting process with command `rails db:migrate` by user shutainer@yahoo.co.jp 2020-08-31T00:05:41.271963+00:00 heroku[web.1]: Starting process with command `irb` 2020-08-31T00:05:44.759411+00:00 app[web.1]: Switch to inspect mode. 2020-08-31T00:05:44.760171+00:00 app[web.1]: 2020-08-31T00:05:44.815317+00:00 heroku[web.1]: Process exited with status 0 2020-08-31T00:05:44.849695+00:00 heroku[web.1]: State changed from starting to crashed 2020-08-31T00:05:44.852418+00:00 heroku[web.1]: State changed from crashed to starting 2020-08-31T00:05:52.851790+00:00 heroku[run.7980]: State changed from starting to up 2020-08-31T00:05:52.856447+00:00 heroku[run.7980]: Awaiting client 2020-08-31T00:05:52.891424+00:00 heroku[run.7980]: Starting process with command `rails db:migrate` 2020-08-31T00:05:59.894902+00:00 heroku[run.7980]: Process exited with status 0 2020-08-31T00:05:59.927380+00:00 heroku[run.7980]: State changed from up to complete 2020-08-31T00:06:05.419295+00:00 heroku[web.1]: Starting process with command `irb` 2020-08-31T00:06:08.786074+00:00 app[web.1]: Switch to inspect mode. 2020-08-31T00:06:08.786799+00:00 app[web.1]: 2020-08-31T00:06:08.879555+00:00 heroku[web.1]: Process exited with status 0 2020-08-31T00:06:08.991140+00:00 heroku[web.1]: State changed from starting to crashed 2020-08-31T00:09:58.194158+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/" host=glacial-temple-79557.herokuapp.com request_id=432296e9-7359-4456-bbc2-b885e514a27d fwd="111.97.175.96" dyno= connect= service= status=503 bytes= protocol=https 2020-08-31T00:09:59.223351+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/favicon.ico" host=glacial-temple-79557.herokuapp.com request_id=12c8e692-769d-45a7-9967-ce77256746eb fwd="111.97.175.96" dyno= connect= service= status=503 bytes= protocol=https
となります。
さらに、
heroku run rails console cにて、
Running via Spring preloader in process 18 WARNING: Spring is running in production. To fix this make sure the spring gem is only present in `development` and `test` groups in your Gemfile and make sure you always use `bundle install --without development test` in production Loading production environment (Rails 5.0.7.2)
とでます。
そのため、
Dockerfile
1FROM ruby:2.4.5 2RUN apt-get update -qq && apt-get install -y build-essential nodejs 3RUN mkdir /app 4WORKDIR /app 5COPY Gemfile /app/Gemfile 6COPY Gemfile.lock /app/Gemfile.lock 7RUN bundle install --without development test 8COPY . /app
と書き換えましたが、同様です。
Rails on DockerをHerokuでDeployするまで
HerokuでMySQLを使おうとして詰まったところ
を参考にしました。
流れとしては、
clearDBをアドオンとして追加
configに設定
heroku CLIログイン
heroku containerにログイン
heroku create~~
heroku container:push web
heroku container:release web
heroku run rails db:migrate
heroku open
heroku run rails assets:precompile
heroku config:add RAILS_ENV=production
(アセットパイプラインは理解が追いついておりません)
以下Docker-compose.ymlです。
Docker
1version: '3' 2services: 3 web: 4 build: . 5 command: bundle exec rails s -p 3000 -b '0.0.0.0' 6 volumes: 7 - .:/app 8 ports: 9 - 3000:3000 10 depends_on: 11 - db 12 tty: true 13 stdin_open: true 14 db: 15 image: mysql:5.7 16 volumes: 17 - db-volume:/var/lib/mysql 18 environment: 19 MYSQL_ROOT_PASSWORD: password 20volumes: 21 db-volume: 22
追記
Gemfile
1source 'https://rubygems.org' 2 3 4# Bundle edge Rails instead: gem 'rails', github: 'rails/rails' 5gem 'rails', '~> 5.0.0', '>= 5.0.0.1' 6# Use mysql as the database for Active Record 7gem 'mysql2', '>= 0.3.18', '< 0.5' 8# Use Puma as the app server 9gem 'puma', '~> 3.0' 10# Use SCSS for stylesheets 11gem 'sass-rails', '~> 5.0' 12# Use Uglifier as compressor for JavaScript assets 13gem 'uglifier', '>= 1.3.0' 14# Use CoffeeScript for .coffee assets and views 15gem 'coffee-rails', '~> 4.2' 16# See https://github.com/rails/execjs#readme for more supported runtimes 17# gem 'therubyracer', platforms: :ruby 18 19# Use jquery as the JavaScript library 20gem 'jquery-rails' 21# Turbolinks makes navigating your web application faster. Read more: https://github.com/turbolinks/turbolinks 22gem 'turbolinks', '~> 5' 23# Build JSON APIs with ease. Read more: https://github.com/rails/jbuilder 24gem 'jbuilder', '~> 2.5' 25# Use Redis adapter to run Action Cable in production 26# gem 'redis', '~> 3.0' 27# Use ActiveModel has_secure_password 28gem 'bcrypt', '~> 3.1.7' 29gem 'bootstrap', '~> 4.0.0' 30gem 'mini_racer' 31gem 'kaminari' 32gem 'rails-i18n' 33 34# Use Capistrano for deployment 35# gem 'capistrano-rails', group: :development 36 37group :development, :test do 38 # Call 'byebug' anywhere in the code to stop execution and get a debugger console 39 gem 'byebug', platform: :mri 40 gem 'rails-flog', require: 'flog' 41end 42 43group :development do 44 # Access an IRB console on exception pages or by using <%= console %> anywhere in the code. 45 gem 'web-console' 46 gem 'listen', '~> 3.0.5' 47 # Spring speeds up development by keeping your application running in the background. Read more: https://github.com/rails/spring 48 gem 'spring' 49 gem 'spring-watcher-listen', '~> 2.0.0' 50 gem 'pry-byebug' 51 gem 'annotate' 52end 53 54# Windows does not include zoneinfo files, so bundle the tzinfo-data gem 55gem 'tzinfo-data', platforms: [:mingw, :mswin, :x64_mingw, :jruby] 56 57コード
あなたの回答
tips
プレビュー