๐ CLI to manage Apache Airflow in Docker environments with ease
Project description
๐ Airflow Docker CLI
A powerful command-line tool to manage Apache Airflow environments using Docker
Features โข Installation โข Quick Start โข Commands โข Troubleshooting
โจ Features
- ๐ณ Easy Setup: Launch a complete Airflow environment with a single command
- ๐ฏ Developer Friendly: Hot-reload DAGs, instant testing, and debugging tools
- ๐ฆ Pre-configured Stack: PostgreSQL, Redis, MongoDB, Spark, and DBGate included
- ๐ง Built-in Tools: Code linting, DAG validation, and interactive shell access
- ๐ Monitoring: Quick status checks and log viewing
- ๐จ Beautiful CLI: Colorful output with emojis and clear status indicators
- ๐ Multiple Workers: Celery executor with configurable Spark workers
๐ Prerequisites
Before you begin, ensure you have the following installed:
- Python 3.7+ - Download
- Docker Desktop - Download
- Docker Engine 20.10+
- Docker Compose v2+
- Git (optional) - For version control
System Requirements
- RAM: Minimum 4GB available (8GB+ recommended)
- Disk Space: At least 10GB free
- OS: Linux, macOS, or Windows with WSL2
๐ Installation
From PyPI (Recommended)
pip install airflow-cli
From Source
# Clone the repository
git clone https://github.com/lema-ufpb/airflow-cli.git
cd airflow-cli
# Install in development mode
pip install -e .
# Or install with dev dependencies
pip install -e ".[dev]"
Verify Installation
actl --help
You should see the CLI help menu with available commands.
โก Quick Start
1. Initialize Airflow Environment
actl up
This command will:
- โ Check Docker installation and requirements
- โ
Create
docker-compose.ymlconfiguration - โ
Set up directory structure (
dags/,logs/,plugins/) - โ Start all Airflow services
- โ Initialize the Airflow database
- โ Create admin user
First startup may take 2-3 minutes while Docker pulls images and initializes services.
2. Access the Airflow UI
Once started, open your browser:
๐ Airflow Web UI: http://localhost:8080
- Username:
airflow - Password:
airflow
๐ง DBGate (Database UI): http://localhost:3100
โก Spark Master UI: http://localhost:8080 (on port 8081 internally)
3. Check Status
actl status
4. Create Your First DAG
Create a DAG file in the dags/ directory:
# dags/my_first_dag.py
from airflow import DAG
from airflow.operators.bash import BashOperator
from datetime import datetime, timedelta
default_args = {
'owner': 'airflow',
'depends_on_past': False,
'start_date': datetime(2024, 1, 1),
'retries': 1,
'retry_delay': timedelta(minutes=5),
}
with DAG(
'my_first_dag',
default_args=default_args,
description='My first Airflow DAG',
schedule_interval=timedelta(days=1),
catchup=False,
) as dag:
task1 = BashOperator(
task_id='print_date',
bash_command='date',
)
task2 = BashOperator(
task_id='print_hello',
bash_command='echo "Hello from Airflow!"',
)
task1 >> task2
5. Test Your DAG
# List available DAGs
actl list
# Run a specific DAG
actl run my_first_dag
actl run
6. Stop the Environment
# Stop services (keeps data)
actl down
# Stop and remove all data
actl down --volumes
๐ Commands
Core Commands
| Command | Description | Example |
|---|---|---|
actl up |
Start the Airflow environment | actl up --build |
actl down |
Stop the environment | actl down --volumes |
actl status |
Check service health | actl status |
actl restart |
Restart services | actl restart scheduler |
Development Commands
| Command | Description | Example |
|---|---|---|
actl list |
List available DAGs | actl list |
actl run |
Execute a DAG | actl run my_dag |
actl fix |
Run code quality checks | actl fix --autofix |
actl shell |
Open interactive shell | actl shell --service worker |
Monitoring Commands
| Command | Description | Example |
|---|---|---|
actl logs |
View container logs | actl logs scheduler -f |
actl logs -n 100 |
Show last 100 lines | actl logs worker -n 100 |
๐ฏ Detailed Command Reference
actl up
Start the complete Airflow environment.
# Basic startup
actl up
# Rebuild images before starting
actl up --build
What it does:
- Creates necessary directories
- Copies docker-compose.yml if missing
- Starts all containers (postgres, redis, airflow components, spark, mongo)
- Waits for services to become healthy
- Displays access URLs
actl down
Stop the Airflow environment.
# Stop services (preserve data)
actl down
# Stop and remove volumes (โ ๏ธ deletes all data!)
actl down --volumes
actl status
Display the current status of all containers.
actl status
Shows:
- Container names
- Status (running/stopped/unhealthy)
- Ports
- Health check status
actl logs
View logs from containers.
# View all logs (last 50 lines)
actl logs
# Follow logs in real-time
actl logs scheduler -f
# View specific service logs
actl logs worker -n 200
# Available services: webserver, scheduler, worker, triggerer, all
actl run
Execute a DAG for testing.
# Run DAG by ID
actl run my_dag_id
# Run with specific execution date
actl run my_dag_id --date 2024-01-01
actl run
Config File Structure:
args:
id: "my_dag_id"
actl list
List all DAGs found in the dags directory.
actl list
Shows:
- Python files containing DAGs
- Config files with DAG IDs
- Relative paths
actl fix
Run code quality checks with flake8.
# Check code quality
actl fix
# Auto-fix issues (requires autopep8)
actl fix --autofix
actl shell
Open an interactive bash shell in a container.
# Open shell in worker container (default)
actl shell
# Open shell in specific service
actl shell --service scheduler
# Available services: worker, scheduler, webserver
Useful inside shell:
# List DAGs
airflow dags list
# Test a task
airflow tasks test my_dag my_task 2024-01-01
# Check connections
airflow connections list
actl restart
Restart services without full shutdown.
# Restart all services
actl restart
# Restart specific service
actl restart scheduler
๐๏ธ Architecture
The CLI sets up the following services:
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ Docker Environment โ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโค
โ โ
โ โโโโโโโโโโโโโโโโ โโโโโโโโโโโโโโโโ โโโโโโโโโโโโโ โ
โ โ Airflow โ โ Airflow โ โ Airflow โ โ
โ โ Web Server โ โ Scheduler โ โ Worker โ โ
โ โ (Port 8080) โ โ โ โ (Celery) โ โ
โ โโโโโโโโโโโโโโโโ โโโโโโโโโโโโโโโโ โโโโโโโโโโโโโ โ
โ โ
โ โโโโโโโโโโโโโโโโ โโโโโโโโโโโโโโโโ โ
โ โ Airflow โ โ Airflow โ โ
โ โ Triggerer โ โDAG Processor โ โ
โ โโโโโโโโโโโโโโโโ โโโโโโโโโโโโโโโโ โ
โ โ
โ โโโโโโโโโโโโโโโโ โโโโโโโโโโโโโโโโ โโโโโโโโโโโโโ โ
โ โ PostgreSQL โ โ Redis โ โ MongoDB โ โ
โ โ (Port 5432) โ โ (Port 6379) โ โ(Port 27017โ โ
โ โโโโโโโโโโโโโโโโ โโโโโโโโโโโโโโโโ โโโโโโโโโโโโโ โ
โ โ
โ โโโโโโโโโโโโโโโโ โโโโโโโโโโโโโโโโ โ
โ โSpark Master โ โ Spark Workersโ โ
โ โ (Port 7077) โ โ (2 nodes) โ โ
โ โโโโโโโโโโโโโโโโ โโโโโโโโโโโโโโโโ โ
โ โ
โ โโโโโโโโโโโโโโโโ โ
โ โ DBGate โ Database Management UI โ
โ โ (Port 3100) โ โ
โ โโโโโโโโโโโโโโโโ โ
โ โ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
๐๏ธ Directory Structure
your-project/
โโโ dags/ # Your DAG files
โ โโโ my_dag/
โ โ โโ-config/parameters.yml # Config parameters
โ โ โโโ dag.py # DAG definition
โ โโโ another_dag.py
โโโ logs/ # Airflow logs (auto-created)
โโโ plugins/ # Airflow plugins (auto-created)
โโโ data/ # Shared data directory
โโโ docker-compose.yml # Docker configuration (auto-created)
๐ Troubleshooting
Docker Not Running
Error: โ Docker daemon is not running!
Solution:
- Linux:
sudo systemctl start docker - macOS/Windows: Start Docker Desktop application
Port Already in Use
Error: โ ๏ธ Port 8080 is already in use
Solution:
-
Find process using the port:
# Linux/macOS lsof -i :8080 # Windows netstat -ano | findstr :8080
-
Stop the process or modify
docker-compose.ymlto use different ports
Services Unhealthy
Error: โ ๏ธ Some services are unhealthy!
Solution:
# Check logs
actl logs scheduler
actl logs worker
# Restart services
actl restart
# Full reset (โ ๏ธ removes data)
actl down --volumes
actl up
DAG Not Appearing
Issues:
- DAG file not in
dags/directory - Python syntax errors
- DAG paused by default
Solution:
# Check DAG list
actl list
# Validate DAG syntax
actl fix
# Check logs
actl logs scheduler -f
# Open shell and check
actl shell
airflow dags list
Permission Denied (Linux)
Error: permission denied while connecting to Docker
Solution:
# Add user to docker group
sudo usermod -aG docker $USER
# Log out and back in, then verify
docker ps
Low Disk Space
Error: System slow or containers failing
Solution:
# Clean Docker system
docker system prune -a --volumes
# Remove old images
docker image prune -a
๐ง Advanced Usage
Custom Docker Compose
You can modify the generated docker-compose.yml to:
- Change resource limits
- Add custom environment variables
- Configure different executors
- Add new services
Environment Variables
Create a .env file:
_AIRFLOW_WWW_USER_USERNAME=admin
_AIRFLOW_WWW_USER_PASSWORD=secure_password
AIRFLOW_VAR_MY_VARIABLE=value
๐ค Contributing
Contributions are welcome! Please feel free to submit a Pull Request.
- Fork the repository
- Create your feature branch (
git checkout -b feature/AmazingFeature) - Commit your changes (
git commit -m 'Add some AmazingFeature') - Push to the branch (
git push origin feature/AmazingFeature) - Open a Pull Request
๐ License
This project is licensed under the MIT License - see the LICENSE file for details.
๐ Acknowledgments
- Apache Airflow team for the amazing orchestration platform
- Docker team for containerization
- LEMA-UFPB for development and maintenance
๐ Support
- ๐ Issues: GitHub Issues
- ๐ Documentation: Official Docs
โญ Star us on GitHub โ it helps!
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file airflow_cli-1.0.7.tar.gz.
File metadata
- Download URL: airflow_cli-1.0.7.tar.gz
- Upload date:
- Size: 23.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.11.14
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
6ef2d75a150038ea9581e142747f845ed8dda5bb1a94ecc73932e34a3dfec938
|
|
| MD5 |
53b16c88da1421dd7ecc3d1772efccf2
|
|
| BLAKE2b-256 |
fd5f1d954e6ff952ebea54168396903b30659dd37e6f17102fb572cd0aacf47b
|
File details
Details for the file airflow_cli-1.0.7-py3-none-any.whl.
File metadata
- Download URL: airflow_cli-1.0.7-py3-none-any.whl
- Upload date:
- Size: 18.0 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.11.14
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
76aa12b1a17bd09d4b61bc1e57e005533c1d299c6fcaa4d56bd0deddf0058469
|
|
| MD5 |
77787b1aca276a04d3ab0e6ac91fcb7c
|
|
| BLAKE2b-256 |
c06ff92f05ad131b2d711132ab102b30f107da98c75cb83bcdd3d2a4a13f6efe
|