Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improved generated config/application.cr commented code to work once uncommented. #429

Merged
merged 2 commits into from Dec 2, 2017

Conversation

elorest
Copy link
Member

@elorest elorest commented Dec 2, 2017

Description of the Change

  1. Uncommented PORT env logic by default and converted to int32.
  2. Added valid secret_key_base to commented out secret_key_base settings code.
  3. Added checks so that ENV vars are only applied if they exist. That way the standard practice of using default settings in development and test but ENV vars in production will still work without constant code changes.
  4. Changed example settings values to match correct type for setting (bool, int32) etc. ENV vars are all strings and fail by default.

Benefits

Within Rails and Phoenix every ENV override has default values that are used instead if they're not set.

For example: If a PORT isn't set it goes to 3000, if an RAILS_ENV isn't set it goes to development, if DATABASE_URL isn't set it uses settings from database.yml.
I don't think that it's clear to users that uncommenting the code in application.cr will work differently.
For instance if settings port is 3000, ENV["PORT"] should only override that if ENV["PORT"] has a value. Otherwise we just end up with a project that doesn't work.

settings.port = ENV["PORT"] will fail in too many situations that aren't expected by people coming from rails/laravel, pheonix, hanami.

Instead it should be settings.port = ENV["PORT"].to_i if ENV["PORT"]?.

Otherwise we just end up with a weird situation were we load values in and immediately overwrite them with values that may not even exist.

We now end up with example code that will work out of the box, which will result in fewer complaints.

Copy link
Contributor

@marksiemers marksiemers left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just a question about whether or not we should provide hard-coded defaults for any missing ENV variables.

#
#
# Process Count: This will enable Amber to be used in cluster mode,
# spinning an instance for each number of process specified here.
# Rule of thumb, always leave at least 1 core available for system processes/resources.
#
# settings.port = (ENV["PORT"] ||= 80).to_i
# settings.process_count = ENV["PROCESS_COUNT"].to_i if ENV["PROCESS_COUNT"]?
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should there be a hardcoded fallback here?

settings.process_count = ENV["PROCESS_COUNT"]? ? ENV["PROCESS_COUNT"].to_i : 1 

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We already have process_count = 1 here

Notice ]? , so returns nil if not found and setting attribute is not assigned.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes. There is already a fall back for all of them. They just weren't being used if the environment var was missing.

#
# PORT: This is the port that you're application will run on. Examples would be (80, 443, 3000, 8080)
#
settings.port = ENV["PORT"].to_i if ENV["PORT"]?
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same question here, should there be a default, or do we want it to fail loudly if that ENV variable isn't there?

Copy link
Contributor

@faustinoaq faustinoaq Dec 2, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We're already using port = 3000 here

:ditto:

Do we want it to fail loudly if that ENV variable isn't there?

I will not fail because is checking PORT availability first if ENV["PORT"]?

@elorest
Copy link
Member Author

elorest commented Dec 2, 2017

It's pointless to have a default if we're going to overwrite it with a non existent environment var.

I strongly feel that we should follow the same pattern that all the other Frameworks we have used for the last 10 years follow.

Use the default unless the environment variable exists.

@elorest elorest merged commit 7edaba0 into master Dec 2, 2017
@eliasjpr eliasjpr added this to the 0.5.0 - Features & Bugfixes milestone Dec 22, 2017
@eliasjpr eliasjpr deleted the is/port_should_support_ENV branch January 12, 2018 01:04
@faustinoaq faustinoaq added this to Done in Framework 2018 May 5, 2018
@faustinoaq faustinoaq removed this from Done in Framework 2018 Jun 13, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
No open projects
Development

Successfully merging this pull request may close these issues.

None yet

4 participants