Skip to content

Commit b61895a

Browse files
coder2jcoder2j
coder2j
authored and
coder2j
committed
MINOR: add tutorial of Airflow docker image extending and customising
1 parent a843fc7 commit b61895a

File tree

4 files changed

+47
-1
lines changed

4 files changed

+47
-1
lines changed

Dockerfile

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
FROM apache/airflow:2.0.1
2+
COPY requirements.txt /requirements.txt
3+
RUN pip install --user --upgrade pip
4+
RUN pip install --no-cache-dir --user -r /requirements.txt

dags/dag_with_python_dependencies.py

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
from datetime import datetime, timedelta
2+
3+
from airflow import DAG
4+
from airflow.operators.python import PythonOperator
5+
6+
7+
default_args = {
8+
'owner': 'coder2j',
9+
'retry': 5,
10+
'retry_delay': timedelta(minutes=5)
11+
}
12+
13+
14+
def get_sklearn():
15+
import sklearn
16+
print(f"sklearn with version: {sklearn.__version__} ")
17+
18+
19+
def get_matplotlib():
20+
import matplotlib
21+
print(f"matplotlib with version: {matplotlib.__version__}")
22+
23+
24+
with DAG(
25+
default_args=default_args,
26+
dag_id="dag_with_python_dependencies_v03",
27+
start_date=datetime(2021, 10, 12),
28+
schedule_interval='@daily'
29+
) as dag:
30+
task1 = PythonOperator(
31+
task_id='get_sklearn',
32+
python_callable=get_sklearn
33+
)
34+
35+
task2 = PythonOperator(
36+
task_id='get_matplotlib',
37+
python_callable=get_matplotlib
38+
)
39+
40+
task1 >> task2

docker-compose.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@
3939
version: '3'
4040
x-airflow-common:
4141
&airflow-common
42-
image: ${AIRFLOW_IMAGE_NAME:-apache/airflow:2.0.1}
42+
image: ${AIRFLOW_IMAGE_NAME:-extending_airflow:latest}
4343
environment:
4444
&airflow-common-env
4545
AIRFLOW__CORE__EXECUTOR: LocalExecutor

requirements.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
scikit-learn==0.24.2
2+
matplotlib==3.3.3

0 commit comments

Comments
 (0)