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

Tests: Should we encrypt our config.env file? #41

Open
absorpheus opened this issue Sep 30, 2017 · 0 comments
Open

Tests: Should we encrypt our config.env file? #41

absorpheus opened this issue Sep 30, 2017 · 0 comments
Assignees
Labels

Comments

@absorpheus
Copy link

absorpheus commented Sep 30, 2017

I had some trouble getting the tests to work on travis mainly because travis was complaining that it can't find the config.env file (as we have added it to .gitignore file)

So I used travis cli to encrypt the environment variables and add them to our .travis.yml file so travis can access them when running the tests ( see: https://docs.travis-ci.com/user/environment-variables/#Encrypting-environment-variables ) however the problem with this is that tests done locally do not work (using npm run test) because it needs to read the environment variables from the config.env using env2.

I added a workaround to this by adding the following code (check email.js)

if (process.env.TRAVIS !== true) {
  require('env2')('./config.env')
}

This code checks if the current environment is not travis, and if true will load the environment variables from the config.env file.

This is a working solution, as both tests now work locally and on travis however this is going to be quite cumbersome to keep on adding this code whenever we want to load in the environment variables - for example, when working with our database.

I'm just thinking if we have multiple files which will need to access environment variables this will not be an elegant solution, as we will keep on having to paste in that code.

However, we could instead encrypt our config.env file using travis, host it on github and then add a line of code which will decrypt the file and load our environment variables when we build our project.

This way we don't need to worry which environment we are on when loading our environment variables:

See here for more info how to encrypt a file using travis cli: https://github.com/travis-ci/travis.rb#encrypt-file

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

4 participants