I haven't written it to show it to others.
The continuation of the article that my father, Rails + MySQL + Nginx + Unicorn + Docker + CircieCI, created a development environment.
Add [* Rails *] how to use devise (rails5 version) to the environment created above, and add the Twitter API to gem'dotenv-rails'
I uploaded it to heroku in the production environment while hiding it with.
docker-compose.yml
command: /bin/sh -c "rm -f tmp/pids/server.pid && bundle exec rails s -p 3000 -b '0.0.0.0'"
Purpose: I don't want to put my Twitter API key locally on GitHub
I don't want to put the env file in Git management, so add the following to the .gitignore file.
Add .env
to .gitignore
.
This puts .env out of Git's control.
https://pikawaka.com/rails/dotenv-rails http://vdeep.net/rubyonrails-dotenv
[* Rails *] How to use devise (rails5 version) Rewrite the place to add the twitter API to ENV []
config/initializer/devise.rb
config.omniauth :twitter, ENV['TWITTER_API_KEY'], ENV['DATABASE_URL']
Maybe DATABASE_URL and TWIITER_API_KEY, DATABASE_URL are must.
Heroku GUI Setting Config Vars or [Heroku app environment variable settings (set with CUI)](https://qiita.com/murakami- Set with mm / items / 9587e21fc0ed57c803d0)
--ClearDB URL confirmation You can check the URL of ClearDB with the following command.
$ heroku config
=== <App name> Config Vars
CLEARDB_DATABASE_URL: mysql://<username>:<password>@<hostname>/<Database name>?reconnect=true
--Environment variable settings Set each value displayed by the above command to a variable.
$ heroku config:add DB_NAME='<Database name>'
$ heroku config:add DB_USERNAME='<username>'
$ heroku config:add DB_PASSWORD='<password>'
$ heroku config:add DB_HOSTNAME='<hostname>'
$ heroku config:add DB_PORT='3306'
$ heroku config:add DATABASE_URL='mysql2://<username>:<password>@<hostname>/<Database name>?reconnect=true'
DATABASE_URL
must start withmysql2: //
.
After checking the settings, the following is displayed.$ heroku config
=== <App name> Config Vars
CLEARDB_DATABASE_URL: mysql://<username>:<password>@<hostname>/<Database name>?reconnect=true
DATABASE_URL: mysql2://<username>:<password>@<hostname>/<Database name>?reconnect=true
DB_HOSTNAME: <hostname>
DB_NAME: <Database name>
DB_PASSWORD: <password>
DB_PORT: 3306
DB_USERNAME: <username>
--Added the following to config / environments / production.rb
(The settings around here will be corrected later.)
config.assets.compile = true
config.assets.initialize_on_precompile=false
Plus, set the Twitter API created with .env
of gem'dotenv-rails'
on heroku side.
reference https://qiita.com/ymstshinichiro/items/d6ea229f6eb4778006c2 https://golikyua.hatenablog.com/entry/2020/01/09/135254 https://www.sejuku.net/blog/tutorial/111347
Recommended Posts