This repository has been archived by the owner on Apr 17, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 472
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Perform some checks on some environment variables
Some environment variables are extremely important when deploying Portus. This commit makes Portus raise an exception during initialization process when there's something off about these environment variables. Fixes #580 Signed-off-by: Miquel Sabaté Solà <[email protected]>
- Loading branch information
Showing
3 changed files
with
31 additions
and
3 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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
# This file checks for important environment variables. Some of them have to be | ||
# set in order for Portus to work in certain scenarios (e.g. secret key base on | ||
# production), others are strong recommendations. | ||
|
||
# Checks that the secret value has been set either in `config/secrets.yml` or as | ||
# an environment variable. If this is not the case, then it raises an exception | ||
# with the proper message. | ||
def mandatory_secret!(env, value) | ||
return unless value.blank? | ||
return unless ENV["PORTUS_#{env}"].blank? | ||
|
||
raise "Environment variable `PORTUS_#{env}` has not been set! This variable is " \ | ||
"mandatory in production because it's needed for the generation of secrets." | ||
end | ||
|
||
if Rails.env.production? | ||
# Mandatory environment variables for production. | ||
mandatory_secret!("SECRET_KEY_BASE", Rails.application.secrets.secret_key_base) | ||
mandatory_secret!("KEY_PATH", Rails.application.secrets.encryption_private_key_path) | ||
mandatory_secret!("PASSWORD", Rails.application.secrets.portus_password) | ||
|
||
# Strongly recommended environment variables for production. | ||
if ENV["PORTUS_MACHINE_FQDN_VALUE"].blank? | ||
if APP_CONFIG["machine_fqdn"]["value"] == APP_CONFIG.default_of("machine_fqdn.value") | ||
Rails.logger.warn "You have not changed the FQDN configuration. Are you sure about this?" | ||
end | ||
end | ||
end |