-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Auto-generate env var values, e.g for
SECRET_KEY_BASE
(#440)
When specifying `:env_vars` in the tomo config file, you can now use a special `:generate_secret` value. This will automatically generate a secret using `SecureRandom.hex(64)` the first time it is needed. The tomo configuration template created by `tomo init` now includes this env var value: ``` SECRET_KEY_BASE: :generate_secret ``` This means that the first time the app is deployed, an appropriate value for `SECRET_KEY_BASE` will be generated automatically, without prompting the user.
- Loading branch information
1 parent
0b1d026
commit 4547f4e
Showing
6 changed files
with
66 additions
and
20 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -44,10 +44,12 @@ export RAILS_ENV=production | |
export PUMA_THREADS=20 | ||
``` | ||
|
||
For environment variables that are used for secrets or other sensitive data, you can specify `:prompt` instead of the actual value. In this case tomo will prompt interactively for the value the first time it is needed. For example: | ||
#### `:prompt` | ||
|
||
For environment variables that are used for API keys or other sensitive data, you can specify `:prompt` instead of the actual value. In this case tomo will prompt interactively for the value the first time it is needed. For example: | ||
|
||
```ruby | ||
set env_vars: { SECRET_KEY_BASE: :prompt } | ||
set env_vars: { DATABASE_URL: :prompt } | ||
``` | ||
|
||
The first time `env:update` is run, tomo will prompt for the value: | ||
|
@@ -57,11 +59,19 @@ $ tomo deploy | |
tomo deploy v1.0.0 | ||
→ Connecting to [email protected] | ||
• env:update | ||
SECRET_KEY_BASE? | ||
DATABASE_URL? | ||
``` | ||
|
||
Once the environment variable exists in the envrc file, tomo will no longer prompt for it. | ||
|
||
#### `:generate_secret` | ||
|
||
Similarly, for environment variables that requires a randomly generated secret value, like `SECRET_KEY_BASE`, you can specify `:generate_secret`. In this case, tomo will generate a value using `SecureRandom.hex(64)` the first time it is needed. | ||
|
||
```ruby | ||
set env_vars: { SECRET_KEY_BASE: :generate_secret } | ||
``` | ||
|
||
`env:update` is intended for use as a [deploy](../commands/deploy.md) task. It should be run at the beginning of a deploy to ensure that the environment has all the latest values before other tasks are run. | ||
|
||
### env:set | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters