Configuration¶
Configuration versus Environment variable¶
There are three configuration levels:
Project config,
Execution config,
Application config.
- Project configuration
Project configuration is related to how the team works and how deployment should be done. This description is done by a project configuration file:
project.cws.yml
. This project configuration file describes the commands and options associated to the project.- Execution configuration
As for the Twelve-Factor App : “The twelve-factor app stores config in environment variables. Env vars are easy to change between deploys without changing any code;”. Using environment variables is highly recommanded to enable easy code deployments to differents systems: Changing configuration is just updating variables in the configuration in the CI/CD process.
- Application configuration
At last : “application config does not vary between deploys, and so is best done in the code.”
That’s why entries are defined in the code. The link from entry to function is always the same.
In Flask, there is only the concept of application configuration as the excution configuration if out of is scope (mainly associated to the USWGI server).
In CoWorks, we use the concept of stage for execution configuration deployed in lambda variables.
Project configuration¶
Stage is a key concept for the deployment. Stages are defined thru the concept of workspace in terraform, stage for AWS API Gateway and variables of AWS Lambda.
Workspace definition¶
The workspace
value will correspond to the CWS_STAGE
variable value.
You certainly may need to attach environment variables to your project. Of course thoses variables may depend on the stage status. How? You just need to create and specify custom environment files.
CoWorks uses dotenv files to allow you to define your environment variables for stages.
Dotenv file are named .env
and .env_{CWS_STAGE}
.
As example you can deploy the specific stage dev
of the microservice app
defined in the app
python file
in the folder tech
:
$ CWS_STAGE=dev deploy
The environment variables accessible from the lambda must be defined in .env
and .env_dev
.
Project configuration file¶
A project configuration file is a YAML file containg the command and options defined for the project.
Example¶
Example of a project.cws.yml file:
version: 3
commands:
run:
host: localhost
port: 5000
deploy:
class: fpr.cws.deploy.fpr_deploy
profile_name: fpr-customer
bucket: coworks-microservice
customer: neorezo
project: cws_utils_mail
layers:
- arn:aws:lambda:eu-west-1:935392763270:layer:coworks-0.6.8
workspaces:
dev:
commands:
run:
port: 8000
deploy:
layers:
- arn:aws:lambda:eu-west-1:935392763270:layer:coworks-dev
Structure¶
Field |
Value |
Description |
---|---|---|
version |
3 |
YAML syntax version |
commands |
Command Structure List (below) |
List of commands |
workspaces |
Workspace Structure List (below) |
List of workspaces where commands are redefined |
Command Name |
Command Option |
Project Value |
---|---|---|
run |
||
host |
localhost |
|
port |
5000 |
Workspace Name |
Command Name |
Command Option |
Project Value |
---|---|---|---|
dev |
|||
run |
|||
port |
8000 |