-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdocker-compose.yml
More file actions
97 lines (91 loc) · 4.88 KB
/
docker-compose.yml
File metadata and controls
97 lines (91 loc) · 4.88 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
# =====================================================================
# KOIN Airflow Docker Compose 설정
# ---------------------------------------------------------------------
# * Executor: LocalExecutor (Redis 불필요, 경량 구성)
# * 컨테이너: postgres, airflow-init, airflow-webserver, airflow-scheduler
# * 접속: http://localhost:8080 (ID/PW는 .env 파일에서 설정)
# =====================================================================
version: "3.8"
# ---------------------------------------------------------------------------
# 공통 설정 (YAML 앵커)
# - airflow-webserver와 airflow-scheduler가 이 설정을 상속받습니다.
# - <<: *airflow-common 으로 참조합니다.
# ---------------------------------------------------------------------------
x-airflow-common: &airflow-common
build: . # 현재 디렉토리의 Dockerfile로 커스텀 이미지 빌드
environment:
# --- Airflow 핵심 설정 ---
AIRFLOW__CORE__EXECUTOR: LocalExecutor # LocalExecutor: 단일 머신에서 병렬 태스크 실행 (Celery 불필요)
AIRFLOW__CORE__LOAD_EXAMPLES: "false" # Airflow 예제 DAG 비활성화
AIRFLOW__DATABASE__SQL_ALCHEMY_CONN: postgresql+psycopg2://airflow:airflow@postgres/airflow # 메타데이터 DB 연결 (postgres 컨테이너)
AIRFLOW__CORE__DAGS_FOLDER: /opt/airflow/dags # DAG 파일 경로 (호스트의 ./dags가 마운트됨)
AIRFLOW__LOGGING__BASE_LOG_FOLDER: /opt/airflow/logs # 태스크 실행 로그 저장 경로
AIRFLOW__WEBSERVER__EXPOSE_CONFIG: "true" # 웹 UI에서 Airflow 설정 확인 가능
# --- GCP 인증 ---
GOOGLE_APPLICATION_CREDENTIALS: /opt/airflow/keys/gcp-key.json # GCP 서비스 계정 키 경로 (Dataform/BigQuery API 호출 시 사용)
env_file:
- .env # 환경변수 파일 (.env.example 참고하여 생성)
volumes:
- ./dags:/opt/airflow/dags # DAG 소스코드 마운트 (호스트 수정 → 컨테이너 즉시 반영)
- ./logs:/opt/airflow/logs # 로그 영속화 (컨테이너 재시작 시에도 유지)
- ./plugins:/opt/airflow/plugins # 커스텀 플러그인 마운트
- ./keys:/opt/airflow/keys:ro # GCP 키 마운트 (읽기 전용, :ro)
depends_on:
postgres:
condition: service_healthy # postgres가 준비된 후에만 Airflow 컨테이너 시작
services:
# ---------------------------------------------------------------------------
# PostgreSQL: Airflow 메타데이터 DB
# - DAG 실행 이력, 태스크 상태, XCom 데이터 등을 저장합니다.
# - 데이터는 ./postgres-data에 영속화됩니다.
# ---------------------------------------------------------------------------
postgres:
image: postgres:15
environment:
POSTGRES_USER: airflow
POSTGRES_PASSWORD: airflow
POSTGRES_DB: airflow
volumes:
- ./postgres-data:/var/lib/postgresql/data # DB 데이터 영속화
healthcheck:
test: ["CMD-SHELL", "pg_isready -U airflow"] # PostgreSQL 준비 상태 확인
interval: 10s # 10초마다 체크
retries: 5 # 5회 실패 시 unhealthy
# ---------------------------------------------------------------------------
# Airflow Init: 초기화 전용 컨테이너 (1회 실행 후 종료)
# - DB 마이그레이션 (테이블 생성/업데이트)
# - 관리자 계정 생성 (ID/PW는 .env에서 읽음)
# ---------------------------------------------------------------------------
airflow-init:
<<: *airflow-common # 공통 설정 상속
entrypoint: /bin/bash
command: >
-c "airflow db migrate &&
airflow users create
--username $${AIRFLOW_ADMIN_USER}
--password $${AIRFLOW_ADMIN_PASSWORD}
--firstname Admin
--lastname User
--role Admin
--email $${AIRFLOW_ADMIN_EMAIL}"
restart: "no" # 초기화 후 재시작하지 않음
# ---------------------------------------------------------------------------
# Airflow Webserver: 웹 UI 서버
# - http://localhost:8080 으로 접속
# - DAG 목록 확인, 수동 트리거, 태스크 로그 조회 등
# ---------------------------------------------------------------------------
airflow-webserver:
<<: *airflow-common
command: webserver
ports:
- "8080:8080" # 호스트 8080 → 컨테이너 8080 포트 매핑
restart: always # 비정상 종료 시 자동 재시작
# ---------------------------------------------------------------------------
# Airflow Scheduler: DAG 스케줄링 엔진
# - DAG 파일을 주기적으로 파싱하여 실행 스케줄을 관리합니다.
# - schedule에 따라 태스크를 트리거하고, 의존성 순서대로 실행합니다.
# ---------------------------------------------------------------------------
airflow-scheduler:
<<: *airflow-common
command: scheduler
restart: always