For now, we will use virtual enviroments, Based on https://www.youtube.com/watch?v=z7xyNOF8tak&t=4s and https://airflow.apache.org/docs/apache-airflow/stable/start/local.html and https://github.com/apache/airflow/blob/master/airflow/providers/docker/example_dags/example_docker_copy_data.py
- Create a virtual enviroment venv
Example
python3 -m venv venv
-
Activate the virtual enviroment.
-
Install apache-airflow
AIRFLOW_VERSION=2.0.1
PYTHON_VERSION="$(python --version | cut -d " " -f 2 | cut -d "." -f 1-2)"
CONSTRAINT_URL="https://raw.githubusercontent.com/apache/airflow/constraints-${AIRFLOW_VERSION}/constraints-${PYTHON_VERSION}.txt"
pip install "apache-airflow==${AIRFLOW_VERSION}" --constraint "${CONSTRAINT_URL}"
pip install apache-airflow-providers-docker
- Export airflow environment to the project directory
export AIRFLOW_HOME=.
- initialize the database
airflow db init
- Create an user
airflow users create \
--username admin \
--firstname Peter \
--lastname Parker \
--role Admin \
--email spiderman@superhero.org
- start the web server, default port is 8080
airflow webserver --port 8080
- In a new terminal, start the scheduler
export AIRFLOW_HOME=.
airflow scheduler
- In a new terminal, run dag script
export AIRFLOW_HOME=.
python dags/toy_example_dag.py
- set enable_xcom_pickling = True in airflow.cfg