This template provides a production-ready setup for running dbt with Apache Airflow using Docker. It includes a complete development environment with PostgreSQL, dbt, and Airflow configured to work together seamlessly.
- Docker and Docker Compose
- Python 3.12 or later
make
command-line tool- Git
- Create a new repository from this template
- Clone your new repository
- Start the development environment:
make init # Create virtual environment and install dependencies
make docker-up # Start all services
-
Access Airflow at http://localhost:18080
- Username:
admin
- Password:
admin
- Username:
-
See docs/example-workflow.md for a guide on running and fixing the example dbt workflow. This dbt example comes from
dbt init
and has an intentional validation error.
dbt-airflow-template/
├── airflow/
│ ├── dags/ # Airflow DAG definitions
│ ├── dbt/ # dbt project files
│ ├── logs/ # Airflow and dbt logs
│ └── plugins/ # Airflow plugins
├── docker/ # Docker configuration files
├── docs/ # Documentation
└── Makefile # Development automation
- Create a new repository from this template
- Clone your new repository
- Initialize the development environment:
make init # Create virtual environment and install dependencies
make docker-up # Start all services
This template includes several code quality tools:
- pre-commit hooks for automated checks
- ruff for Python linting and formatting
- mypy for static type checking
To run code quality checks manually:
make pre-commit # Run all pre-commit checks
make pre-commit-upgrade # Update pre-commit hooks to latest versions
The checks will also run automatically on git commit
.
- Activate the virtual environment:
source .venv/bin/activate
-
Make changes to your dbt models in
airflow/dbt/models/
-
Test dbt models:
make test-dbt
The development environment includes:
- Airflow Webserver (http://localhost:18080)
- Airflow Scheduler
- PostgreSQL (port 15432)
Common commands:
make docker-up # Start services
make docker-down # Stop services
make docker-logs # View logs
make docker-clean # Remove containers and volumes
Create a .env
file in the root directory to override default
settings:
POSTGRES_USER=airflow
POSTGRES_PASSWORD=airflow
POSTGRES_DB=airflow
POSTGRES_HOST=postgres
- dbt profiles are stored in
airflow/dbt/profiles.yml
- Models are located in
airflow/dbt/models/
- The default target database is the same PostgreSQL instance used by Airflow
- DAGs are stored in
airflow/dags/
- The example DAG (
example_dbt_dag.py
) demonstrates how to:- Run dbt commands in Airflow
- Handle dependencies between dbt tasks
- Implement proper error handling
- Build the production Docker image:
make docker-build DOCKER_REGISTRY=your-registry DOCKER_PACKAGE=your-package DOCKER_TAG=your-tag
- Push the image to your registry:
make docker-push DOCKER_REGISTRY=your-registry DOCKER_PACKAGE=your-package DOCKER_TAG=your-tag
- Logs are stored in
airflow/logs/
- Dependencies are managed through
pyproject.toml
- Docker requirements are automatically compiled to
docker/requirements.txt
-
If Airflow fails to start:
- Check logs:
make docker-logs
- Ensure PostgreSQL is healthy:
make docker-ps
- Try cleaning and restarting:
make docker-clean docker-up
- Check logs:
-
If dbt tests fail:
- Verify database connections in
profiles.yml
- Check dbt logs in
airflow/logs/
- Run
make test-dbt
for detailed error messages
- Verify database connections in
- Create a feature branch or fork
- Make your changes
- Ensure all code quality checks pass:
make pre-commit
- Test thoroughly: at a minimum
make docker-up
should build, run, and example workflow should start (which will fail by design). See docs/example-workflow.md for more info. - Submit a pull request
This template is distributed under the MIT license. See LICENSE
file
for more information.