This boilerplate is designed for setting up Python projects using Docker, enabling a seamless development experience both locally and in containerized environments. It includes Husky for commit hooks and linting, and Poetry for Python dependency management and virtual environments, all running within Docker containers. This setup eliminates the need for local installation of these tools, ensuring a consistent development environment.
- Dockerfile: Defines the Python environment and installs dependencies via Poetry, creating a virtual environment.
- docker-compose.yml: Manages services, including the Node.js environment for Husky and the Python application.
- Husky Setup: Manages pre-commit hooks and linting, executed within a Node.js Docker container.
- Entrypoint Script: Ensures the virtual environment is correctly set up and synchronized on container start.
- Clone the repository.
- Run the setup script to install Husky and other dependencies:
./setup.sh
The virtual environment is managed within the Docker container to ensure consistency across development setups. An entrypoint script checks if the virtual environment (/usr/src/app/.venv
) is empty and, if so, repopulates it using Poetry.
-
To run commands within this virtual environment:
docker compose exec app poetry run <command>
-
To add new Python packages:
docker compose exec app poetry add <package-name>
Start the application with Docker Compose:
docker compose up
This command initiates the entrypoint script, ensuring the virtual environment is prepared before starting the application.
/app
: Contains the Python application, Dockerfile, and the virtual environment.- Root directory: Contains configuration files, setup scripts, and Node.js related files.
- Modify the Dockerfile for specific Python versions or dependencies.
- Update
docker-compose.yml
for additional services or configurations. - Adjust the entrypoint script as needed for specific startup behaviors.
This project utilizes the docker compose
command, the modern iteration of docker-compose
. Integrated directly into the Docker CLI, it streamlines defining and running multi-container Docker applications. Commands like docker-compose up
or docker-compose build
are now simplified to docker compose up
and docker compose build
, enhancing user experience by embedding common tools into Docker's core command set.
Contributions to improve this boilerplate are welcome. Please adhere to standard GitHub pull request procedures.
MIT. See LICENSE for more details.