An open source repository to host Airflow DAGs that transform publicly available population statistics into a standardized format.
This repo is preconfigured to run Apache Airflow via Docker Compose, giving you an Airflow Web UI at http://localhost:8081.
- Docker and Docker Compose
- Linux/macOS (Windows WSL2 should also work)
-
Create the
.envfile with your UID (recommended to match host permissions):echo "AIRFLOW_UID=$(id -u)" > .env
If you skip this step, the default
AIRFLOW_UID=50000from the included.envwill be used. -
Initialize Airflow metadata DB and create an admin user (one-time):
docker compose up airflow-init
-
Start the Airflow services (webserver, scheduler, triggerer, postgres):
docker compose up -d
-
Open the Airflow Web UI:
- URL: http://localhost:8081
- Username:
airflow - Password:
airflow
-
Stop the stack when done:
docker compose down
To view logs:
docker compose logs -f airflow-webserver
docker compose logs -f airflow-scheduler.
├── dags/ # Place your DAG .py files here
│ └── example_viss_dag.py # Sample DAG to verify the setup
├── plugins/ # Custom plugins (optional)
├── logs/ # Airflow logs (mounted volume)
├── requirements.txt # Python deps installed into containers
├── docker-compose.yaml # Airflow stack definition
├── .env # AIRFLOW_UID for file permissions
└── README.md
- Add your DAG files under
dags/. Airflow will auto-detect changes within ~1 minute. - Use the Airflow Web UI to trigger runs manually, or set a
schedule_intervalin your DAG.
backfill_remaining runs the audited batch in
dags/backfill_remaining_plan.json. Trigger the controller once. It advances three
independent queues: one UN fertility country, one health/reference DAG, and one
age-pyramid country at a time. Every launch waits for existing runs in its family
to finish. Sensors and child-DAG waits release executor slots; the controller
resumes through normal Airflow restarts. It has no automatic schedule.
Age-pyramid DAGs now process one year at a time, allow up to 12 hours per year
(AGEPYR_TASK_TIMEOUT_MIN), and skip complete stored age bins. A manual run can
select years with {"years": [2026]}; {"force": true} still rebuilds stored years.
CSV export can reuse complete stored bins without downloading rasters again.
The plan records unavailable source files and unsupported UN location codes under
excluded. A failed child is reported and the queue advances; the controller's
final summary fails if any child needs follow-up. The individual child DAGs remain
the place to inspect task logs and data results. Review or regenerate the plan
against current coverage before starting a later maintenance batch.
-
Add packages to
requirements.txt. They will be installed into the Airflow containers on startup. -
Example:
apache-airflow-providers-postgres>=5.10.0 pandas>=2.0
-
Restart services after changing dependencies:
docker compose down && docker compose up -d --build -
Remove containers, networks, and volumes (CAUTION: removes Postgres data):
docker compose down -v
-
If the UI is not accessible, check container health and logs:
docker compose ps docker compose logs --since=1m airflow-webserver
-
Ensure ports
8081(web) and5432(Postgres) are free on your host. -
If port 8081 is busy, edit
docker-compose.yamland change the mapping underairflow-webserverfrom"8081:8080"to another free port (e.g.,"8090:8080"). -
If you change your UID, regenerate
.envand recreate containers.
Create the posgres volume:
docker volume create postgres-db-volumeThen start up the service:
docker compose up -d postgres-devCreate the postgres database viss if it does not already exist
docker compose exec postgres sh -lc "psql -U airflow -d postgres -c \"CREATE DATABASE viss OWNER airflow;\""Award permissions to sub folders for viss airflow instance:
sudo mkdir -p viss-airflow/logs
sudo chown -R 50000:0 viss-airflow/logs
sudo chmod -R u+rwX,g+rwX viss-airflow/logs
Production runs no Airflow — the DAG services sit behind the compose dag profile and
the prod deploy only brings up --profile prod — so nothing there ever writes the
ingest tables. Dev ingests, prod serves, and scripts/sync-data-to-prod.sh is the
bridge.
scripts/sync-data-to-prod.sh # report row counts on both sides, write nothing
scripts/sync-data-to-prod.sh --yes # replace the production copiesIt copies the reference and ingest tables (airports, aircraft, flight volumes, routes,
age pyramids, ASFR, WHO GHO, World Bank) and nothing else: not flight_states, which
is six hours of live sky rewritten continuously; not the seirs_* run outputs, which
prod produces itself; not the rasters, which are large objects (see
VOLUME-MIGRATION.md). Each table is dropped and refilled inside one transaction, so
readers on the far side see either the old copy or the new one, never an empty table.
Unlike the full dump-and-restore below, this does not drop the production database, and it does not need the box taken out of service.
The SSH key used for the production deploy is pinned to a forced command and cannot
run psql; this needs a key that can run commands, or your own access.
The same script is wired to a workflow_dispatch job in
.github/workflows/sync-data-to-prod.yml. That job needs a self-hosted runner on
the dev workstation, labelled viss-dev: the dev database is published on 127.0.0.1
and a GitHub-hosted runner cannot reach it.
It is required to install the following apt packages inside of the airflow scheduler container for the processing of geotiff files to work in the DAG.
docker compose exec -u root airflow-scheduler bash -lc "apt-get update && apt-get install -y gdal-bin && gdalwarp --version && gdalinfo --version"docker compose exec -u root airflow-scheduler bash -lc "pip show apache-airflow-providers-postgres || pip install --no-cache-dir apache-airflow-providers-postgres"docker compose exec -u root airflow-webserver bash -lc "pip show apache-airflow-providers-postgres || pip install --no-cache-dir apache-airflow-providers-postgres"Currently it's a two step process. First step is to convert the downloaded .tif file to Web Mercator. (Not sure yet what the compression argument does yet, whether lossy or lossless)
gdalwarp -t_srs EPSG:3857 -r bilinear -multi \
-srcnodata -99999 -dstnodata -99999 \
-co COMPRESS=LZW \
/home/jeannaude/epi/viss-frontend/frontend/zaf_pop_2025_CN_100m_R2025A_v1.tif \
/home/jeannaude/epi/viss-frontend/frontend/zaf_pop_2025_CN_100m_R2025A_v1_3857.tifSecond step is to convert the .tif file to a COG. (Not sure yet what the compression argument does yet, whether lossy or lossless.)
gdal_translate -of COG \
-co COMPRESS=ZSTD \
-co NUM_THREADS=ALL_CPUS \
-co OVERVIEW_RESAMPLING=AVERAGE \
/home/jeannaude/epi/viss-frontend/frontend/zaf_pop_2025_CN_100m_R2025A_v1_3857.tif \
/home/jeannaude/epi/viss-frontend/frontend/zaf_pop_2025_CN_100m_R2025A_v1_cog.tifWe can then vailidate if it's a healthy COG with:
gdalinfo /home/jeannaude/epi/viss-frontend/frontend/zaf_pop_2025_CN_100m_R2025A_v1_cog.tif | \
grep -i -E 'coordinate|tiling|overviews|compression|NoData'(Optional)
docker run --rm -v /home/jeannaude/epi/viss-frontend/frontend:/data osgeo/gdal:alpine-small-latest \
gdalwarp -t_srs EPSG:3857 -r bilinear -multi \
-srcnodata -99999 -dstnodata -99999 \
-co COMPRESS=LZW \
/data/zaf_pop_2025_CN_100m_R2025A_v1.tif \
/data/zaf_pop_2025_CN_100m_R2025A_v1_3857.tif
docker run --rm -v /home/jeannaude/epi/viss-frontend/frontend:/data osgeo/gdal:alpine-small-latest \
gdal_translate -of COG \
-co COMPRESS=ZSTD \
-co NUM_THREADS=ALL_CPUS \
-co OVERVIEW_RESAMPLING=AVERAGE \
/data/zaf_pop_2025_CN_100m_R2025A_v1_3857.tif \
/data/zaf_pop_2025_CN_100m_R2025A_v1_cog.tif
docker run --rm -v /home/jeannaude/epi/viss-frontend/frontend:/data osgeo/gdal:alpine-small-latest \
gdalinfo /data/zaf_pop_2025_CN_100m_R2025A_v1_cog.tif | \
grep -i -E 'coordinate|tiling|overviews|compression|NoData'Instructions for data migration from DEV client to Prod (Webserver):
- Create viss.dump file (which is a compressed db file of the postgres db)
docker compose exec postgres pg_dump -U airflow -d viss -Fc -b -f /tmp/viss.dump
docker cp $(docker compose ps -q postgres):/tmp/viss.dump ./viss.dump
- Copy from local DEV laptop to Webserver:
scp -i ~/.ssh/viss -C ./viss.dump \
<username_here>@<ip_address_here>:/mnt/HC_Volume_103938942/viss-$(date +%Y%m%d).dump
- Then we do docker compose down on the webserver:
docker compose down
- Need to set volume path on webserver to this (line 167 in docker-compose.yml on webserver):
- /mnt/HC_Volume_103938942/pgdata:/var/lib/postgresql/data
- Then we stand up the postgres service:
docker compose up -d postgres
- Flash the postgres db on the webserver:
docker compose exec postgres psql -U airflow -c "DROP DATABASE IF EXISTS viss;"
docker compose exec postgres psql -U airflow -c "CREATE DATABASE viss OWNER airflow;"
- Restore postgres db via helper container:
docker run --rm --network viss-docker-compose_default -e PGPASSWORD=airflow -v /mnt/HC_Volume_103938942:/dump:ro postgres:15-alpine sh -c "pg_restore -h postgres -U airflow -d viss -v /dump/viss-20251208.dump" > pg_restore.log 2>&1