This project sets up a Flask application with Docker and PostgreSQL, including an isolated testing environment. Environment variables are configured to switch between development and test databases.
flask_project/
├── app/
│ ├── __init__.py
│ ├── config.py
│ ├── models.py
│ ├── routes.py
│ ├── tests/
│ │ ├── __init__.py
│ │ └── test_routes.py
├── docker/
│ ├── flask/
│ │ ├── Dockerfile
│ │ └── init-db.sh
├── .gitignore
├── docker-compose.yml
├── manage.py
├── requirements.in
├── requirements.txt
└── README.md
-
Build and run the Docker containers:
docker-compose up --build
-
Run the tests:
docker-compose run web python -m unittest discover -s app/tests
- Docker Compose is used to manage the multi-container application, including the Flask app and PostgreSQL database.
- Flask-SQLAlchemy is used for ORM (Object-Relational Mapping) to handle database operations.
- psycopg2-binary is used as the PostgreSQL database adapter for Python.
- Environment Configuration allows switching between development and test databases using environment variables.