Movatterモバイル変換


[0]ホーム

URL:


Skip to content
DEV Community
Log in Create account

DEV Community

Cover image for Rails encrypted credentials with docker compose
Sulman Baig
Sulman Baig

Posted on • Originally published atsulmanweb.com

     

Rails encrypted credentials with docker compose

Ruby on Rails 5.2 removed the simplesecrets.yml file and replaced it withcredentials.yml.enc. This file is encrypted, so it is easy to use in version control. To decrypt this encrypted file there ismaster.keyin config file which should not be included in version control.

Edit credentials file

Locally installed rails app credentials can be edited with following command

EDITOR=nano rails credentials:edit
Enter fullscreen modeExit fullscreen mode

EDITOR tells which editor we want to use to edit credentials like some people love vim editor as well.

Sometimes ui-based editors don’t open this way. As we have to wait for the editor to open.

EDITOR="mate --wait" rails credentials:edit
Enter fullscreen modeExit fullscreen mode

Multiple environments

Rails 6 allowed multiple files for different rails environments. For example, without dependency of environment are saved inconfig/credentials.yml.enc. But variable which are different for development environment are saved inconfig/credentials/development.yml.enc and decrypted with keyconfig/credentials/development.key.

So editing for development can be called by:

EDITOR=nano rails credentials:edit--environment development
Enter fullscreen modeExit fullscreen mode

For more info, visit:https://blog.saeloun.com/2019/10/10/rails-6-adds-support-for-multi-environment-credentials.html

Calling credentials edit in docker compose

When rails is not locally installed but inside a container, then to call a cli method inside a container is a bit different. I use the following command to update the credentials:

docker-compose run--rm-eEDITOR=nano api rails credentials:edit
Enter fullscreen modeExit fullscreen mode

Here,api is the container name created with docker compose. Furthermore,--rm is being used because run creates a copy of the container, so it will remove the container volume after it is closed.

Happy Coding!

Top comments(0)

Subscribe
pic
Create template

Templates let you quickly answer FAQs or store snippets for re-use.

Dismiss

Are you sure you want to hide this comment? It will become hidden in your post, but will still be visible via the comment'spermalink.

For further actions, you may consider blocking this person and/orreporting abuse

Senior Software Engineer with 11 years of expertise in Ruby on Rails and Vue.js, specializing in health, e-commerce, staffing, and transport. Experienced in software development and version analysis.
  • Location
    Multan, Pakistan
  • Education
    MS Software Engineering
  • Work
    Sr. Software Engineer #RubyOnRails #VueJS
  • Joined

More fromSulman Baig

DEV Community

We're a place where coders share, stay up-to-date and grow their careers.

Log in Create account

[8]ページ先頭

©2009-2025 Movatter.jp