curl -LfO '<https://airflow.apache.org/docs/apache-airflow/3.0.4/docker-compose.yaml>'
위 코드를 통해 Airflow에서 제공하는 docker_compose.yaml을 다운받고 아래와 같이 수정 후
docker-compose up airflow-init
을 실행합니다.
AIRFLOW__DATABASE__SQL_ALCHEMY_CONN: postgresql+psycopg2://postgres:2464@postgres/api2db ## 수정함
AIRFLOW__CELERY__RESULT_BACKEND: db+postgresql://postgres:2464@postgres/api2db ## 수정함
...
services:
postgres:
image: postgres:15
environment:
POSTGRES_USER: postgres
POSTGRES_PASSWORD: 2464
POSTGRES_DB: api2db
volumes:
- postgres-db-volume:/var/lib/postgresql/data
healthcheck:
test: ["CMD", "pg_isready", "-U", "postgres"]
interval: 10s
retries: 5
start_period: 5s
restart: always
아래 코드를 통해 정상적으로 DB가 생성되었는지 확인하였습니다.
api_data_pipeline on main [?]
❯ docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
604cb708da51 apache/airflow:3.0.4 "/usr/bin/dumb-init …" 4 minutes ago Up 3 minutes (healthy) 8080/tcp api_data_pipeline-airflow-worker-1
bd07f9eb75b8 apache/airflow:3.0.4 "/usr/bin/dumb-init …" 4 minutes ago Up 4 minutes (healthy) 8080/tcp api_data_pipeline-airflow-dag-processor-1
b2f36971653c apache/airflow:3.0.4 "/usr/bin/dumb-init …" 4 minutes ago Up 4 minutes (healthy) 8080/tcp api_data_pipeline-airflow-scheduler-1
ba525e9a541d apache/airflow:3.0.4 "/usr/bin/dumb-init …" 4 minutes ago Up 4 minutes (healthy) 8080/tcp api_data_pipeline-airflow-triggerer-1
3c5c9ad275df apache/airflow:3.0.4 "/usr/bin/dumb-init …" 4 minutes ago Up 4 minutes (healthy) 0.0.0.0:8080->8080/tcp, [::]:8080->8080/tcp api_data_pipeline-airflow-apiserver-1
44e778c0ed35 postgres:15 "docker-entrypoint.s…" 5 minutes ago Up 5 minutes (healthy) 5432/tcp api_data_pipeline-postgres-1
4774d7cd00e4 redis:7.2-bookworm "docker-entrypoint.s…" 5 minutes ago Up 5 minutes (healthy) 6379/tcp api_data_pipeline-redis-1
api_data_pipeline on main [?]
❯ docker exec -it postgres bash
Error response from daemon: No such container: postgres
api_data_pipeline on main [?]
❯ docker exec -it api_data_pipeline-postgres-1 bash
root@44e778c0ed35:/#
root@44e778c0ed35:/#
root@44e778c0ed35:/# psql -U postgres -d api2db
다음은 아래 홈페이지에서 제공하는 환률 데이터 API를 사용해 보았습니다.
Airflow에서 제공하는 로그를 사용해 보았습니다.
from airflow.utils.log.logging_mixin import LoggingMixin
log = LoggingMixin().log
log.info('...')
위와같이 log
를 사용하면 UI에서 쉽게 확인이 가능합니다.
위와같이 DAG 안에 Task마다 로그를 쉽게 학인이 가능합니다. 기본적인 설정에서는 INFO
레벨 까지의 로그만 출력되도록 설정이 되어 있지만 이번 프로젝트에서는 최종 단계인 DEBUG
단계까지 출력되도록 설정 했습니다.
방법은 airflow.cfg에서 logging_level
을 설정해주는 것입니다. 코드는 아래와 같습니다.