...

/

Build a Web Stack

Build a Web Stack

Let’s learn to configure our system for production in clean architecture.

Build a web application

Now that we’ve successfully containerized the tests, we can devise a production-ready setup of the whole application, running both a web server and a database in Docker containers.

To run a production-ready infrastructure, we need to put a WSGI server in front of the web framework and a web server in front of it. We’ll also need to run a database container that we’ll initialize only once.

The steps toward achieving a production-ready configuration aren’t complicated, and the final setup won’t be too different from what we already did for the tests. We need to follow these steps:

  1. Create a JSON configuration with environment variables suitable for production.
  2. Create a suitable configuration for Docker Compose, and configure the containers.
  3. Add commands to manage.py that allow us to control the processes.

Step 1: Create the JSON configuration file

We’ve created the config/production.json file, which is similar to the one we created for the tests.

Press + to interact
[
{
"name": "FLASK_ENV",
"value": "production"
},
{
"name": "FLASK_CONFIG",
"value": "production"
},
{
"name": "POSTGRES_DB",
"value": "postgres"
},
{
"name": "POSTGRES_USER",
"value": "postgres"
},
{
"name": "POSTGRES_HOSTNAME",
"value": "localhost"
},
{
"name": "POSTGRES_PORT",
"value": "5432"
},
{
"name": "POSTGRES_PASSWORD",
"value": "postgres"
},
{
"name": "APPLICATION_DB",
"value": "application"
}
]

Both FLASK_ENV and FLASK_CONFIG are set to production. It’s important to remember that the first is an internal Flask variable with two possible fixed values (development and production). In contrast, the second is an arbitrary name that has the final effect of loading a specific configuration ...

Access this course and 1400+ top-rated courses and projects.