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

Converting Rails config to railsconfig #823

Merged
merged 9 commits into from
Mar 2, 2017
Merged

Converting Rails config to railsconfig #823

merged 9 commits into from
Mar 2, 2017

Conversation

knkski
Copy link
Contributor

@knkski knkski commented Feb 22, 2017

Fixes https://github.com/department-of-veterans-affairs/vets.gov-team/issues/1299

The major advantages of railsconfig over the other options are that it supports YAML syntax unlike dotenv, and it supports local overrides unlike Figaro. It is also is easier to configure than Figaro, since the YAML can be grouped into blocks and doesn't have to look like ES_CLIENT_KEY_PATH: foo.

@@ -0,0 +1,8 @@
hca:
endpoint: https://test-foo.vets.gov
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Went with a fake url since the VA is touchy about real endpoints being in a public repo. This can be overridden for dev by putting something like this into config/settings.local.yml:

hca:
  endpoint: https://some-real-endpoint.va.gov

There was also some weird name conflict with the EVSS stuff, hence https://test-foo.vets.gov instead of just https://test.vets.gov

Copy link
Contributor

@jkassemi jkassemi left a comment

Choose a reason for hiding this comment

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

The override options may provide some flexibility with deployment configuration, which could prove useful. So 👍 there.

I prefer when platform optimization settings are defined with a RAILS_ENV, and application configuration is not dependent on the RAILS_ENV more in line with https://12factor.net/config. If we need to start using varying RAILS_ENVs then we'll need some changes to the devops deployments, which all run in production, along with some thought to how this affects the review instances.

Depending on how other folks on the application development teams feel, it'd likely be worth applying globally vs maintaining multiple configuration gems (figaro + railsconfig).

@knkski
Copy link
Contributor Author

knkski commented Feb 23, 2017

We can use this as we use Figaro now, with theproduction RAILS_ENV being used for everything but local dev. We would just plop down a config/settings.local.yml with the appropriate values when deploying. Basically, I think the major difference in this approach is that we don't use env vars by default (which is something that the 12 factor approach gets wrong, imo), we use unversioned settings files.

And yeah, whatever we choose for this I'd like to apply globally for all app configuration.

@leannammiller
Copy link

@knkski can you pls provide an update here?

@knkski
Copy link
Contributor Author

knkski commented Feb 27, 2017

@leannammiller: Sure. This is mostly done, just needs some testing. I'm working on getting the devops side of things ready to go: https://github.com/department-of-veterans-affairs/devops/pull/1520. I expect to have that ready to push to dev by tomorrow.

Copy link
Contributor

@aub aub left a comment

Choose a reason for hiding this comment

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

I like this approach a lot better than using environment variables, although I'm concerned about the size of the change here. Could we have changed one piece of the app at a time so we didn't have to make such a big single PR? Also, can we add some content to the PR instructing people about how to setup the configuration locally?

REPORTS_AWS_S3_BUCKET: 'bucket'
) do
# TODO(knkski): Find better way than `1.times do ...`
1.times do
Copy link
Contributor

Choose a reason for hiding this comment

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

Why do you need this?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Apparently I don't. I was running into an issue with a failing unit test, but I think it was actually unrelated to this.

expect(subject.aws_acl).to eq('private')
expect(subject.aws_bucket).to eq('evss_s3_bucket')
end
Settings.evss.s3.uploads_enabled = true
Copy link
Contributor

Choose a reason for hiding this comment

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

I'm concerned about these things where if the test raises an exception then it could cause the value to not be set back to false. Presumably that's what the ClimateControl thing handles by doing it in a block.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sure, I was wondering if there was a nice way to do that in Ruby other than just something like this:

begin
  Settings.foo = true
  expect(something).to eq(true)
ensure
  Settings.foo = false
end

If not, I'll go and convert these tests to ^^ format if that looks fine.

Copy link
Contributor

Choose a reason for hiding this comment

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

Yeah, that's a little ugly.... If you can make a function that takes the things you want to change as an argument then that function can itself contain the begin/ensure block:

def change_stuff(what_to_change)
   begin
    apply_changes
    yield
  ensure
    roll_back_changes
  end
end

In your case, I think it would be possible to do this by passing a hash to such a function:

change_stuff(foo: true)

Then the function could loop over the hash and make the requested changes to the Settings. This does seem like it could use some more thought though.... there might be cases where that doesn't work very well.

@knkski
Copy link
Contributor Author

knkski commented Feb 27, 2017

@aub: Definitely could have went with smaller chunked PRs. The worry I had with that is that we'd get halfway done, get distracted by something urgent and end up with n+1 ways of configuring vets-api.

Adding documentation sounds great, I'll get that added.

README.md Outdated
- Copy the [certificate](https://github.com/department-of-veterans-affairs/vets.gov-team/blob/master/Products/Identity/Identity%20Discovery%202016/certificates/vetsgov-localhost.crt) to ~/.certs
- Copy the [key](https://github.com/department-of-veterans-affairs/vets.gov-team/blob/master/Products/Identity/Identity%20Discovery%202016/certificates/vetsgov-localhost.key) to ~/.certs
- Create a hidden folder in your home directory: `mkdir ~/.certs`
- TODO(knkski): These are in a private repo...
Copy link
Contributor Author

Choose a reason for hiding this comment

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

@aub: These certs are now residing in a private repo. Do we want to make those available somehow, or just add a note telling external contributors to do something like touch ~/.certs/vetsgov-localhost.crt?

Copy link
Contributor

Choose a reason for hiding this comment

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

Good question. I think it's important that these be private, but I'm not sure what to tell people to do.

@knkski
Copy link
Contributor Author

knkski commented Feb 28, 2017

@aub: Added with_settings helper function to deal with temporarily changing the Settings object for testing

@knkski knkski merged commit ce5abc7 into master Mar 2, 2017
@knkski knkski removed the in progress label Mar 2, 2017
@knkski knkski deleted the railsconfig branch March 2, 2017 01:11
@jkassemi jkassemi restored the railsconfig branch March 6, 2017 20:23
@knkski knkski deleted the railsconfig branch March 9, 2017 05:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants