[RUBY] Run Docker environment Rails MySQL on Heroku. devise and hiding the twitter API

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.

① Change the command of docker-compose.yml

docker-compose.yml


command: /bin/sh -c "rm -f tmp/pids/server.pid && bundle exec rails s -p 3000 -b '0.0.0.0'"

② Introduce gem'dotenv-rails'

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

③ Introduce the API key while hiding it in .env of dotenv-rails

[* 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']

④ Change the environment variables on Heroku

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)

Environment variable settings for the Heroku app

--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'
$ 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>

Deploy to Heroku

Preparations required for Rails project

--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

Run Docker environment Rails MySQL on Heroku. devise and hiding the twitter API
Rails6 [API mode] + MySQL5.7 environment construction with Docker
Introduce Docker to the development environment and test environment of existing Rails and MySQL applications
Build Rails (API) x MySQL x Nuxt.js environment with Docker
Launch Nuxt.js + Rails API on Docker and try CRUD operation
How to run React and Rails on the same server
Rails + MySQL environment construction with Docker
Run the AWS CLI on Docker
[Environment construction with Docker] Rails 6 & MySQL 8
Deploy Rails on Docker to heroku
Rails 6 (API mode) + MySQL Docker environment creation by docker-compose (for Mac)
[Rails / Heroku / MySQL] How to reset the DB of Rails application on Heroku
I built a rails environment with docker and mysql, but I got stuck
Building Rails 6 and PostgreSQL environment with Docker
Create Rails 6 + MySQL environment with Docker compose
Deploy to heroku with Docker (Rails 6, MySQL)
[Rails & Docker & MySQL environment construction] I started the container, but I can't find MySQL ...?
[Docker] Development environment construction Rails6 / Ruby2.7 / MySQL8
Launching the production environment with docker + rails (ver5.2) and errors that occurred
Ruby on Rails ✕ Docker ✕ MySQL Introducing Docker and docker-compose to apps under development
Try the Docker environment on AWS ECS
[First environment construction] I tried to create a Rails 6 + MySQL 8.0 + Docker environment on Windows 10.
Building an environment for WordPress, MySQL and phpMyAdmin with Docker Compose on EC2
Procedure for introducing Docker into the development environment of existing Rails applications [Rails, MySQL, Docker]
(Basic authentication) environment variables in rails and Docker
Next.js + Rails (API) + Mysql on Docker's Hello World!
[Rails MySQL] How to reset DB on heroku
Compile and run Java on the command line
Environment construction method and troubleshooter at the time of joint development (rails, docker and github)
How to install Docker in the local environment of an existing Rails application [Rails 6 / MySQL 8]
[Rails AWS Docker] Build an existing Ruby on Rails + MySQL application with Docker and deploy it on AWS (5)
[Rails AWS Docker] Build an existing Ruby on Rails + MySQL application with Docker and deploy it on AWS (6)
[Rails AWS Docker] Build an existing Ruby on Rails + MySQL application with Docker and deploy it on AWS (3)
[Rails AWS Docker] Build an existing Ruby on Rails + MySQL application with Docker and deploy it on AWS (2)
[Rails AWS Docker] Build an existing Ruby on Rails + MySQL application with Docker and deploy it on AWS (1)
[Rails AWS Docker] Build an existing Ruby on Rails + MySQL application with Docker and deploy it on AWS (4)
Place "Create a to-do list using Rails API mode and React Hooks" on docker
Memo that Azure Functions × Node.js × Typescript was run by Docker on the local virtual environment and debugged from VS Code
virtulbox + vagrant + Docker + nginx + puma + MySQL Rails environment construction
Run the Android emulator on Docker using Android Emulator Container Scripts
SSL in the local environment of Docker / Rails / puma
[Rails] Google, Twitter, Facebook authentication using Devise and Omniauth
Rails Docker environment construction
Test run on rails
Run phpunit on Docker
Until you run Quarkus and run docker image on Amazon ECS
Easy environment construction of MySQL and Redis with Docker and Alfred
Install docker and docker-compose on ubuntu in the shortest process
[Environment construction] Get the Ruby on Rails 6 development environment within 1 hour
Rails application development environment construction with Docker [Docker, Rails, Puma, Nginx, MySQL]
Create Rails5 and postgresql environment with Docker and make pgadmin available
Organize communication in an environment that uses various resources on the host machine and Docker container