Skip to main content

๐Ÿš€ CLI to manage Apache Airflow in Docker environments with ease

Project description

๐Ÿš€ Airflow Docker CLI

Python Version License Docker

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.yml configuration
  • โœ… 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

# Or use config.yml structure
# dags/my_first_dag/config.yml
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

# Auto-detect from config.yml
actl run

Config File Structure:

# dags/my_dag/config.yml
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.yml      # DAG configuration
โ”‚   โ”‚   โ””โ”€โ”€ 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:

  1. Find process using the port:

    # Linux/macOS
    lsof -i :8080
    
    # Windows
    netstat -ano | findstr :8080
    
  2. Stop the process or modify docker-compose.yml to 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.

  1. Fork the repository
  2. Create your feature branch (git checkout -b feature/AmazingFeature)
  3. Commit your changes (git commit -m 'Add some AmazingFeature')
  4. Push to the branch (git push origin feature/AmazingFeature)
  5. 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


โญ Star us on GitHub โ€” it helps!

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

airflow_cli-1.0.3.post0.tar.gz (22.6 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

airflow_cli-1.0.3.post0-py3-none-any.whl (17.7 kB view details)

Uploaded Python 3

File details

Details for the file airflow_cli-1.0.3.post0.tar.gz.

File metadata

  • Download URL: airflow_cli-1.0.3.post0.tar.gz
  • Upload date:
  • Size: 22.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.11.14

File hashes

Hashes for airflow_cli-1.0.3.post0.tar.gz
Algorithm Hash digest
SHA256 39783b3f44af39084f262ee2456c443a50b5289f5ff088005c8632ab7abbaa34
MD5 21bacee21ffc87d1379a50ae8f151882
BLAKE2b-256 5c249a29f6cd2c35aaae2dcbe4719fceb8ec290ee1600ae7676f46e98d72f47c

See more details on using hashes here.

File details

Details for the file airflow_cli-1.0.3.post0-py3-none-any.whl.

File metadata

File hashes

Hashes for airflow_cli-1.0.3.post0-py3-none-any.whl
Algorithm Hash digest
SHA256 b8d224fb2778f0335fc58918f7055724a996a1de106c0753acfea2eec4372c34
MD5 2ee94ed0d2a635308fe934c6d4c9bb80
BLAKE2b-256 18899031183f7fefd6f384d8d70231d7a796729426233a2847107ede3d703d19

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page