.env.SAMPLE
Any environment variables needed in the application should be put into .env.SAMPLE
.properties
files that are committed to the repo..env.SAMPLE
file should never contain an actual value for any secret, but should instead contain
placeholder values; for example:
GOOGLE_CLIENT_ID=put-client-id-here
.env.SAMPLE
should be committed to the GitHub repo.The actual values go into a file .env
that is copied from .env.SAMPLE
, but that is NOT committed to the repo.
.env
goes into your .gitignore
When adding new properties to the application that are necessary for the application to run, it is helpful to have fallback values, especially if those values are not accessed during tests.
As an example, in src/main/resources/application.properties
, we see lines that contain fallback values for GOOGLE_CLIENT_ID
, GOOGLE_CLIENT_SECRET
and ADMIN_EMAILS
:
spring.security.oauth2.client.registration.google.client-id=${GOOGLE_CLIENT_ID:${env.GOOGLE_CLIENT_ID:client_id_unset}}
spring.security.oauth2.client.registration.google.client-secret=${GOOGLE_CLIENT_SECRET:${env.GOOGLE_CLIENT_SECRET:client_secret_unset}}
spring.security.oauth2.client.registration.google.scope=email,profile
...
app.admin.emails=${ADMIN_EMAILS:${env.ADMIN_EMAILS:phtcon@ucsb.edu}}
The fallback values, in this case being:
Env variable | Default Value |
---|---|
GOOGLE_CLIENT_ID |
client_id_unset |
GOOGLE_CLIENT_SECRET |
client_secret_unset |
ADMIN_EMAILS |
phtcon@ucsb.edu |
While the values for GOOGLE_CLIENT_ID
and GOOGLE_CLIENT_SECRET
will not work in practice (i.e. with these values, OAuth login
will fail), having a default value:
It is recommended that if/when any additional environment variables are added to .env.SAMPLE
that
similar fallback values be included in the .properties
files.