feat: use custom docker image for airflow to avoid runtime pip install
This commit is contained in:
@@ -0,0 +1,4 @@
|
|||||||
|
FROM apache/airflow:2.9.2
|
||||||
|
|
||||||
|
COPY airflow/requirements.txt /requirements.txt
|
||||||
|
RUN pip install --no-cache-dir -r /requirements.txt
|
||||||
@@ -9,12 +9,15 @@ BOOKINGS_INIT_DAYS ?= 1
|
|||||||
|
|
||||||
.PHONY: up stop down clean airflow-init logs gp-psql ddl-gp \
|
.PHONY: up stop down clean airflow-init logs gp-psql ddl-gp \
|
||||||
bookings-clone-demodb bookings-init bookings-psql bookings-generate-day \
|
bookings-clone-demodb bookings-init bookings-psql bookings-generate-day \
|
||||||
dev-setup dev-sync dev-lock test lint fmt clean-venv
|
dev-setup dev-sync dev-lock test lint fmt clean-venv build
|
||||||
SHELL := /bin/bash
|
SHELL := /bin/bash
|
||||||
|
|
||||||
up:
|
up:
|
||||||
docker compose -f docker-compose.yml up -d
|
docker compose -f docker-compose.yml up -d
|
||||||
|
|
||||||
|
build:
|
||||||
|
docker compose -f docker-compose.yml build
|
||||||
|
|
||||||
stop:
|
stop:
|
||||||
docker compose -f docker-compose.yml stop
|
docker compose -f docker-compose.yml stop
|
||||||
|
|
||||||
|
|||||||
+11
-13
@@ -14,7 +14,7 @@ services:
|
|||||||
volumes:
|
volumes:
|
||||||
- pgmeta:/var/lib/postgresql/data
|
- pgmeta:/var/lib/postgresql/data
|
||||||
healthcheck:
|
healthcheck:
|
||||||
test: ["CMD-SHELL", "pg_isready -U ${PG_USER} -d ${PG_DB}"]
|
test: [ "CMD-SHELL", "pg_isready -U ${PG_USER} -d ${PG_DB}" ]
|
||||||
interval: 5s
|
interval: 5s
|
||||||
timeout: 5s
|
timeout: 5s
|
||||||
retries: 20
|
retries: 20
|
||||||
@@ -35,7 +35,7 @@ services:
|
|||||||
# В этот каталог будет монтироваться генератор demodb
|
# В этот каталог будет монтироваться генератор demodb
|
||||||
- ./bookings:/bookings:ro
|
- ./bookings:/bookings:ro
|
||||||
healthcheck:
|
healthcheck:
|
||||||
test: ["CMD-SHELL", "pg_isready -U ${BOOKINGS_DB_USER} -d ${BOOKINGS_DB_NAME}"]
|
test: [ "CMD-SHELL", "pg_isready -U ${BOOKINGS_DB_USER} -d ${BOOKINGS_DB_NAME}" ]
|
||||||
interval: 5s
|
interval: 5s
|
||||||
timeout: 5s
|
timeout: 5s
|
||||||
retries: 20
|
retries: 20
|
||||||
@@ -61,13 +61,14 @@ services:
|
|||||||
- greenplum_data:/data
|
- greenplum_data:/data
|
||||||
# Простая проверка доступности: psql откликается
|
# Простая проверка доступности: psql откликается
|
||||||
healthcheck:
|
healthcheck:
|
||||||
test: ["CMD-SHELL", "pg_isready -h 127.0.0.1 -p 5432 -U ${GP_USER:-gpadmin} -d ${GP_DB:-gp_dwh} || echo 1"]
|
test: [ "CMD-SHELL", "pg_isready -h 127.0.0.1 -p 5432 -U ${GP_USER:-gpadmin} -d ${GP_DB:-gp_dwh} || echo 1" ]
|
||||||
interval: 10s
|
interval: 10s
|
||||||
timeout: 5s
|
timeout: 5s
|
||||||
retries: 30
|
retries: 30
|
||||||
|
|
||||||
airflow-webserver:
|
airflow-webserver:
|
||||||
image: apache/airflow:2.9.2
|
build: .
|
||||||
|
image: airflow-custom:latest
|
||||||
container_name: gp_airflow_web
|
container_name: gp_airflow_web
|
||||||
env_file: .env
|
env_file: .env
|
||||||
environment:
|
environment:
|
||||||
@@ -77,9 +78,7 @@ services:
|
|||||||
AIRFLOW__WEBSERVER__SECRET_KEY: ${AIRFLOW__WEBSERVER__SECRET_KEY}
|
AIRFLOW__WEBSERVER__SECRET_KEY: ${AIRFLOW__WEBSERVER__SECRET_KEY}
|
||||||
AIRFLOW_CONN_GREENPLUM_CONN: postgresql://${GP_USER}:${GP_PASSWORD}@greenplum:${GP_PORT:-5432}/${GP_DB}
|
AIRFLOW_CONN_GREENPLUM_CONN: postgresql://${GP_USER}:${GP_PASSWORD}@greenplum:${GP_PORT:-5432}/${GP_DB}
|
||||||
AIRFLOW_CONN_BOOKINGS_DB: postgresql://${BOOKINGS_DB_USER}:${BOOKINGS_DB_PASSWORD}@bookings-db:5432/demo
|
AIRFLOW_CONN_BOOKINGS_DB: postgresql://${BOOKINGS_DB_USER}:${BOOKINGS_DB_PASSWORD}@bookings-db:5432/demo
|
||||||
command: >
|
command: airflow webserver
|
||||||
bash -lc "pip install --no-cache-dir -r /opt/airflow/requirements.txt &&
|
|
||||||
airflow webserver"
|
|
||||||
ports:
|
ports:
|
||||||
- "8080:8080"
|
- "8080:8080"
|
||||||
volumes:
|
volumes:
|
||||||
@@ -96,7 +95,8 @@ services:
|
|||||||
condition: service_completed_successfully
|
condition: service_completed_successfully
|
||||||
|
|
||||||
airflow-scheduler:
|
airflow-scheduler:
|
||||||
image: apache/airflow:2.9.2
|
build: .
|
||||||
|
image: airflow-custom:latest
|
||||||
container_name: gp_airflow_sch
|
container_name: gp_airflow_sch
|
||||||
env_file: .env
|
env_file: .env
|
||||||
environment:
|
environment:
|
||||||
@@ -106,9 +106,7 @@ services:
|
|||||||
AIRFLOW__WEBSERVER__SECRET_KEY: ${AIRFLOW__WEBSERVER__SECRET_KEY}
|
AIRFLOW__WEBSERVER__SECRET_KEY: ${AIRFLOW__WEBSERVER__SECRET_KEY}
|
||||||
AIRFLOW_CONN_GREENPLUM_CONN: postgresql://${GP_USER}:${GP_PASSWORD}@greenplum:${GP_PORT:-5432}/${GP_DB}
|
AIRFLOW_CONN_GREENPLUM_CONN: postgresql://${GP_USER}:${GP_PASSWORD}@greenplum:${GP_PORT:-5432}/${GP_DB}
|
||||||
AIRFLOW_CONN_BOOKINGS_DB: postgresql://${BOOKINGS_DB_USER}:${BOOKINGS_DB_PASSWORD}@bookings-db:5432/demo
|
AIRFLOW_CONN_BOOKINGS_DB: postgresql://${BOOKINGS_DB_USER}:${BOOKINGS_DB_PASSWORD}@bookings-db:5432/demo
|
||||||
command: >
|
command: airflow scheduler
|
||||||
bash -lc "pip install --no-cache-dir -r /opt/airflow/requirements.txt &&
|
|
||||||
airflow scheduler"
|
|
||||||
volumes:
|
volumes:
|
||||||
- ./airflow/dags:/opt/airflow/dags
|
- ./airflow/dags:/opt/airflow/dags
|
||||||
- ./airflow/requirements.txt:/opt/airflow/requirements.txt
|
- ./airflow/requirements.txt:/opt/airflow/requirements.txt
|
||||||
@@ -123,7 +121,8 @@ services:
|
|||||||
condition: service_completed_successfully
|
condition: service_completed_successfully
|
||||||
|
|
||||||
airflow-init:
|
airflow-init:
|
||||||
image: apache/airflow:2.9.2
|
build: .
|
||||||
|
image: airflow-custom:latest
|
||||||
# container_name: gp_airflow_init
|
# container_name: gp_airflow_init
|
||||||
user: "0"
|
user: "0"
|
||||||
env_file: .env
|
env_file: .env
|
||||||
@@ -143,7 +142,6 @@ services:
|
|||||||
bash -lc "
|
bash -lc "
|
||||||
set -e;
|
set -e;
|
||||||
mkdir -p /opt/airflow/data && chown -R airflow:root /opt/airflow/data;
|
mkdir -p /opt/airflow/data && chown -R airflow:root /opt/airflow/data;
|
||||||
su -s /bin/bash airflow -c \"PATH='/home/airflow/.local/bin:$${PATH}' pip install --no-cache-dir -r /opt/airflow/requirements.txt\";
|
|
||||||
# Дожидаемся готовности БД ретрая миграции
|
# Дожидаемся готовности БД ретрая миграции
|
||||||
for i in {1..30}; do
|
for i in {1..30}; do
|
||||||
su -s /bin/bash airflow -c \"PATH='/home/airflow/.local/bin:$${PATH}' airflow db migrate\" && break || echo 'waiting for pgmeta' && sleep 3;
|
su -s /bin/bash airflow -c \"PATH='/home/airflow/.local/bin:$${PATH}' airflow db migrate\" && break || echo 'waiting for pgmeta' && sleep 3;
|
||||||
|
|||||||
Reference in New Issue
Block a user