Skip to content

Instantly share code, notes, and snippets.

@s4na
Last active January 6, 2020 11:20
Show Gist options
  • Save s4na/e5eb5039a3eccb642e78ef75865f1d6f to your computer and use it in GitHub Desktop.
Save s4na/e5eb5039a3eccb642e78ef75865f1d6f to your computer and use it in GitHub Desktop.

Heroku

Setup

create Heroku account

Heroku CLI install

==> heroku
To use the Heroku CLI's autocomplete --
  Via homebrew's shell completion:
    1) Follow homebrew's install instructions https://docs.brew.sh/Shell-Completion
        NOTE: For zsh, as the instructions mention, be sure compinit is autoloaded
              and called, either explicitly or via a framework like oh-my-zsh.
    2) Then run
      $ heroku autocomplete --refresh-cache

  OR

  Use our standalone setup:
    1) Run and follow the install steps:
      $ heroku autocomplete

Bash completion has been installed to:
  /usr/local/etc/bash_completion.d

zsh completions have been installed to:
  /usr/local/share/zsh/site-functions
  • $ heroku autocomplete --refresh-cache
    • Enter key push
    • agree in browser
  • $ heroku login
  • $ heroku --version
  • $ heroku apps
  • $ heroku logout

Heroku Create App

  • Create App
  • input name

Setup Gemfile

ref: https://qiita.com/NaokiIshimura/items/eee473675d624a17310f

group :development, :test do
  gem "sqlite3", "~> 1.4"
end

group :production do
  gem 'pg'
end

Change Database settings

change production database settings

production:
  url: <%= ENV["DATABASE_URL"] %>

Procfile

Need server restart procedure

https://github.com/s4na/heroku_sample/commit/eb391e2f6d085eabf646d4c53c428c5f2a84ac4a https://github.com/s4na/heroku_sample/commit/1ec5eea06f3b1622b135eb3ea87219c2046829fb

attention: Foreign key constraints for migration files

https://teratail.com/questions/77287

Error.1: git push heroku master

$ git push heroku master
fatal: 'heroku' does not appear to be a git repository
fatal: Could not read from remote repository.

Please make sure you have the correct access rights
and the repository exists.
solution
$ git remote add heroku <Heroku/ app/ settings/ Heroku Git URL>

https://qiita.com/sayama0402/items/e2c9e65786259dc55e11

Error.2: git push heroku master

Message
remote: ###### WARNING:
remote: 
remote:        You set your `config.assets.compile = true` in production.
remote:        This can negatively impact the performance of your application.
remote:        
remote:        For more information can be found in this article:
remote:          https://devcenter.heroku.com/articles/rails-asset-pipeline#compile-set-to-true-in-production
remote:        
remote: 
remote: 
remote: ###### WARNING:
remote: 
remote:        You set your `config.active_storage.service` to :local in production.
remote:        If you are uploading files to this app, they will not persist after the app
remote:        is restarted, on one-off dynos, or if the app has multiple dynos.
remote:        Heroku applications have an ephemeral file system. To
remote:        persist uploaded files, please use a service such as S3 and update your Rails
remote:        configuration.
remote:        
remote:        For more information can be found in this article:
remote:          https://devcenter.heroku.com/articles/active-storage-on-heroku
remote:        
remote: 
remote: 
remote: ###### WARNING:
remote: 
remote:        We detected that some binary dependencies required to
remote:        use all the preview features of Active Storage are not
remote:        present on this system.
remote:        
remote:        For more information please see:
remote:          https://devcenter.heroku.com/articles/active-storage-on-heroku
remote:        
remote: 
remote: 
remote: ###### WARNING:
remote: 
remote:        No Procfile detected, using the default web server.
remote:        We recommend explicitly declaring how to boot your server process via a Procfile.
remote:        https://devcenter.heroku.com/articles/ruby-default-web-server

Error.2-1

You set your config.assets.compile = true in production. This can negatively impact the performance of your application.

For more information can be found in this article: https://devcenter.heroku.com/articles/rails-asset-pipeline#compile-set-to-true-in-production

Solition

Turn off

Error.2-2

You set your config.active_storage.service to :local in production. If you are uploading files to this app, they will not persist after the app is restarted, on one-off dynos, or if the app has multiple dynos. Heroku applications have an ephemeral file system. To persist uploaded files, please use a service such as S3 and update your Rails configuration.

For more information can be found in this article: https://devcenter.heroku.com/articles/active-storage-on-heroku

Error.2-3

We detected that some binary dependencies required to use all the preview features of Active Storage are not present on this system.

For more information please see: https://devcenter.heroku.com/articles/active-storage-on-heroku

Error.2-4

No Procfile detected, using the default web server. We recommend explicitly declaring how to boot your server process via a Procfile. https://devcenter.heroku.com/articles/ruby-default-web-server

Solution

add Procfile

Error

The page you were looking for doesn't exist. You may have mistyped the address or the page may have moved.

If you are the application owner check the logs for more information.

Solution 1

$ heroku run rake db:migrate

Solution 2

change routes.rb By default, hello rails is not set to routes.rb

Add Add-ons

Postgres

Menu/ Elements/ Heroku Postgres/ Install Heroku Postgres/ Add to provision to / Provision add-on

Reference

Add environment variable

Ref: https://qiita.com/chihiro/items/b8a3ef54716842dd115a

show log

$ heroku logs -a twi-note

show Env list

$ heroku config -a Application_Name

Set Env

$ heroku config:set ENV_NAME=value -a Application_Name

SSL

Error 3

ActiveRecord::StatementInvalid: PG::UndefinedColumn: ERROR: column "provider" does not exist

Solution

s4na/twi-note#139

migration fileの書き方が間違っていたので修正。

Error 4

OAuth::Unauthorized (403 Forbidden):

https://qiita.com/mh4gf/items/41d2c868317edea5045b

s4na/twi-note#138

Add production URL to Twitter Developer callbacks URL

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment