Create docker-compose config for deploy
Description
-
Create a new docker-compose
file (docker-compose.prod.yml
) (at the root of the project), to be used in the production environment, -
It should make use of the Dockerfile
we already have for the backend, -
For the frontend, it should be built (with production settings: npm run build
) on startup, and then container will not be required. You can reuse what we currently have. -
All client requests should go through an Nginx container -
Nginx should be configured to serve the static files properly (with gzip
configuration if possible) -
The Django app should be through Uwsgi with 4 workers (for now) -
The database stays the same, -
You should have one persistent volume for the database (just like currently) -
Only nginx (exposed on port 80) must be visible from outside; you can make use of private network where it makes sense.
Env variables: Env variables are used to contain all IDs / very short configuration.
-
Create a dev.env file with all the current env variables set in docker-compose.yml
-
Update docker-compose.yml
to make use of this file. -
Create a prod.env file (**and add it to .gitignore
) that will hold the production IDs (we will set the values later; it should have all the same entries as dev.env, with different values).
Configuration files:
You might need to create configuration files for nginx & uwsgi. Put them in a folder prod_conf
at the root of the repo. You can then map them as dynamic volumes in docker-compose
.
You might want to create different env files for the different aspect of the app and not to share all IDs in all containers. If so, put them in other .env
files in prod_conf
.
NB: no django migrations should be applied automatically.
Other
-
Make sure django is configured properly ( allowed_host
, etc.)
Conclusion
The app should be up and running with production settings with a simple docker-compose up --build --file docker-compose.prod.yml
Documentation
-
Make sure to document (in the documentation) the exact steps required to put the app in production (all the commands and files to edit).
TODO
-
Handle logging properly -
Find a workaround for node_modules assets not being present if no npm i
or needed to map them from the image (beurk)
Edited by Florent Chehab