Metadata-Version: 2.3
Name: pinta-dags
Version: 0.1.2
Summary: DAG component of the elevation production system
Requires-Dist: pinta-db>=0.2.0,<0.3
Requires-Dist: pinta-processing>=0.1.0,<0.2
Requires-Dist: pinta-lib
Requires-Dist: apache-airflow[celery,docker,fab,pandas,postgres,standard]==3.3.1 ; extra == 'airflow'
Requires-Dist: pinta-db[psycopg]>=0.2.0,<0.3 ; extra == 'airflow'
Requires-Dist: numpy==2.5.1 ; extra == 'airflow'
Requires-Dist: scipy==1.18.0 ; extra == 'airflow'
Requires-Python: >=3.12, <3.14
Provides-Extra: airflow
Description-Content-Type: text/markdown

# Airflow Workflow component

## Development

By default, Airflow runs in a container, started from the repository root with Docker
Compose:

```bash
docker compose up -d
```

(or `make up`). This is the default Airflow used in development and e2e tests, available at
<http://localhost:8080>.

### Local development

Optionally run a local standalone Airflow on the host (in the dev-container) from the
repository root. This is mainly for testing Airflow version upgrades and as a backup:

```bash
make airflow-start
```

After execution, the Airflow logs will appear in the terminal. Passwords are pre-written
deterministically to `.airflow/simple_auth_manager_passwords.json.generated` from the values of `.env`.
Run `make airflow-clean airflow-start` to pick up changes to those passwords.

Once started, Airflow can be accessed via browser at <http://localhost:8080>.

The **PORTS** tab in the terminal panel also shows which port the Airflow webserver is running on, and VS Code
provides "Open in browser" buttons.

If necessary, code changes can be updated for Airflow use immediately by running the command `airflow dags reserialize`
or `make airflow-reserialize` from the root of the repository.
Airflow also automatically updates DAG file changes periodically.

#### Developing DAGs locally

If you want to run the load dem DAG, you can place test data inside the repo root `test_data` folder, which is automatically mounted to the processing container.

## DAG development practices

* When accessing any database, use `@task.docker` since database urls work only inside containers

## Production image

`Containerfile` has two targets that produce one image for every Airflow component:

| Target | Package source | Usage |
| --- | --- | --- |
| `nightly` | Local repository source | Latest development image, tagged as latest and built from the main branch. |
| `prod` | Published PyPI package | Release images. Build requires `PINTA_DAGS_VERSION` and `PINTA_DAGS_CONSTRAINT`. |

Both add the `celery`, `fab` and `pandas` Airflow extras. `nightly` uses the versions pinned in `uv.lock`
and `prod` uses the constraints of the published `pinta-dags` release.

Build the latest development image:

```bash
podman build --target nightly -f components/dags/Containerfile -t pinta-airflow:latest .
```

Build a release image:

```bash
podman build --target prod -f components/dags/Containerfile \
  --build-arg PINTA_DAGS_VERSION=<version> \
  --build-arg PINTA_DAGS_CONSTRAINT=<constraints-file-in-context> \
  --build-arg AIRFLOW_VERSION=3.3.1 \
  -t pinta-airflow:<version>-airflow3.3.1 .
```

* The entrypoint is `tini -- airflow`. The component is chosen at run time.
  (`api-server`, `scheduler`, `dag-processor`, `triggerer`, `celery worker`).
  It does not run `db migrate` or seed connections.
* The image works with any uid and only writes to `AIRFLOW_HOME`
  (`/opt/airflow`), the log directory and `/tmp`.
* Tag convention: `<dags version>-airflow<airflow version>`, because Airflow can be updated
  without releasing the DAG package.
* The worker needs access to a container engine socket to run `@task.docker` tasks.
* Smoke test: `podman run --rm <image> dags list-import-errors`.

## Updating Airflow

`numpy` and `scipy` are pinned in the DAG component because Airflow's upstream constraints file already fixes versions for the whole dependency set, but those two packages need to be kept under explicit control in this repository so the workspace can resolve the Airflow extra consistently across components. Pulling them out of the generated constraints file and pinning them in `pyproject.toml` makes upgrades repeatable and avoids resolution conflicts when `uv add` is run.

* Update the Airflow version in `components/dags/pyproject.toml` manually.
* Update required AIRFLOW_VERSION and PYTHON_VERSION in Makefile
* Fetch and normalize the matching constraints file with `make airflow-prepare-constraints`.
  * The helper downloads the upstream Apache Airflow constraints file for the selected Python version, removes the `numpy` and `scipy` pins, and writes a local modified copy under `components/dags/.airflow/constraints/`.
  * The helper prints the upstream `numpy` and `scipy` versions. Update the `numpy` and `scipy` pins in `components/dags/pyproject.toml` to match.
* Use the new `AIRFLOW_VERSION` when building the production image.
* If the backend Airflow client needs to stay in sync, update the pin in `components/backend/pyproject.toml` as well.
* Run `uv add --optional airflow "apache-airflow[celery,docker,fab,pandas,postgres,standard]==<version>" --constraint <path-to-modified-constraints>` from `components/dags`.
  The `celery`, `fab` and `pandas` extras are used by the production image, so they must be locked together with the providers of the constraints file.
* Run tests and test standalone usage; remove warning filters or other workarounds required by the old version if
  necessary.

### Special Cases

If there is a need to update dependencies defined by the Airflow constraint file—for example, due to a vulnerability, a
bug, or a new feature in a specific provider package:

* Upgrade the single package in the lock file, e.g. `uv lock --upgrade-package <package>`, and add a comment
  explaining why it differs from the upstream constraints file if necessary.
* Test sufficiently.
* Release the update.

**NOTE:** The production image is built from the constraints of a published `pinta-dags` release, so a changed package
only reaches an environment after a new release has been made and verified.
