openfisca / legislation-explorer

Explore legislation formulas and parameters.
https://legislation.demo.openfisca.org
GNU Affero General Public License v3.0
26 stars 12 forks source link

Shift from file-based configuration to environment variables #165

Closed MattiSG closed 6 years ago

MattiSG commented 6 years ago

Main objective and features

This changeset shifts the configuration mechanism from file-based to environment variables.

This allows to create instances for new tax and benefit systems (countries) without committing a full config file to the shared repository, leaving it to each instance to define their configuration at runtime.

This also allows to run the Legislation Explorer on application-level cloud providers (PaaS) such as Heroku, which do not allow modification of the filesystem between checkout and execution.

In order to facilitate usage, support is also provided for a .env file that can list all environment variables, for these cases where the operator has control over the filesystem.

This changeset also:

Clients impact

All automatic deployments will fail when this PR is merged. Since the configuration mechanism now relies on variables being injected, you will need to update your setup to define these variables.

For convenience, here are the previously defined configuration files as .env files, as well as suggested migration paths:

France

Define a .env file at the root of the current clone with the following data:

API_URL=https://fr.openfisca.org/api/v21
PATHNAME=/legislation
CHANGELOG_URL=https://github.com/openfisca/openfisca-france/blob/master/CHANGELOG.md
MATOMO_URL=https://stats.data.gouv.fr
MATOMO_SITE_ID=4
UI_STRINGS={"en":{"countryName":"France","search_placeholder":"smic, salaire net"},"fr":{"countryName":"France","search_placeholder":"smic, salaire net"}}

I recommend to start considering alternatives to deploy_prod.sh now, as it is very unlikely this France-specific file will survive in the long term.

Tunisia

Define a .env file at the root of the current clone with the following data:

API_URL=https://api.openfisca.tn
CHANGELOG_URL=https://github.com/openfisca/openfisca-tunisia/blob/master/CHANGELOG.md
UI_STRINGS={"en":{"countryName":"Tunisia"},"fr":{"countryName":"Tunisie"}}

I recommend to consider options for automatic deployment, as the app currently fails if the API is updated without the app being rebuilt.

Aotearoa

API_URL=https://openfisca-aotearoa.herokuapp.com
CHANGELOG_URL=https://github.com/ServiceInnovationLab/openfisca-aotearoa/blob/master/CHANGELOG.md
UI_STRINGS={"en":{"countryName":"Aotearoa New Zealand","search_placeholder":"rates rebate, threshold"},"fr":{"countryName":"Nouvelle-Zélande","search_placeholder":"rates rebate, threshold"}}}
MattiSG commented 6 years ago

Should close #167.

MattiSG commented 6 years ago

Alright, thanks everybody for the thoughtful reviews. We're finally ready to merge! I just rebased, checked the diff, and will merge as soon as CI passes.

@openfisca/france-admin beware! As I did not get any reply in the last 18 days regarding deployment updates, I decided to take the safest direction and deactivated autodeploy (see 5da4e75). I will let you open another PR if you want to use CI for CD again.

@openfisca/aotearoa you should be ready to use with Heroku! Let me know if you need more help than what was explained earlier in https://github.com/openfisca/legislation-explorer/pull/165#issue-203043794 🙂

MattiSG commented 6 years ago

We're stuck because of https://github.com/openfisca/legislation-explorer/issues/169.

MattiSG commented 6 years ago

Fastest way out of this for @openfisca/aotearoa who would like to switch to Heroku is to merge this branch into the master of your fork.

Best solution is to open a separate PR to switch integration tests to the country template.

Necessary feature is to support the new slash syntax.