- A push to the repository triggers a build in TravisCI.
- Tests run. If any tests fail, exit the build without deploying.
- If the build meets the deployment conditions in
travis.yml
(for example, the branch name ismaster
), start deployment. If not, exit the build. - TravisCI calls a deployment script, passing the appropriate stage (such as "dev" or "prod"). The stage depends on what branch triggered the build; for instance, a push to
master
will deploy to the "prod" stage. - The deployment script starts by assigning stage-specific environment variables to their root names.
- For example, in a deployment to the "dev" stage, we assign the value of the environment variable
DEV_DYNAMODB_ENDPOINT
to an environment variableDYNAMODB_ENDPOINT
. - We do this because TravisCI doesn't currently have a concept of stage-specific environment variables, but we want to use Travis for multiple stage deployments.
- Environment variable values live in
travis.yml
and are assigned byscripts/assign-env-vars.js
.
- For example, in a deployment to the "dev" stage, we assign the value of the environment variable
- The deployment script sets the
SLS_STAGE
env var to the stage name used in Serverless deploy (such as "dev" or prod"). - The deployment script calls each service's
deploy
NPM script.- Services using Serverless deploy with the
stage
set to the value of$SLS_STAGE
. This is configured in the service'sserverless.yml
.
- Services using Serverless deploy with the
There are a few places env vars are set:
- In
travis.yml
(for deployment) - In
.env
and.env.local
files (for development; via dotenv) - At the beginning of NPM scripts
- Any env vars that are necessary for production should go in
travis.yml
. Do not rely on.env
files for deployment. - If you add an env var to
travis.yml
, add it to the list of env vars inscripts/assign-env-vars.js
. This script sanity checks that all required env vars are defined and also manages stage-specific env vars during CI. - Avoid assigning env vars in NPM scripts.
.env.local
should not be in source control. These files are specific to the developer.- Any variables in
.env.local
should have defaults in.env
. Otherwise, new env vars will break other developers' local apps.