From 00883935db282dbc294dd896b296dbd6cda324e6 Mon Sep 17 00:00:00 2001 From: Connor Howington Date: Wed, 4 Nov 2026 15:48:24 -0600 Subject: [PATCH] Add documentation about PVC mounts --- README.md | 2 +- docs/application.md | 2 +- docs/deployment.md | 32 ++++++++++++++++++++++++++++++++ 3 files changed, 34 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 604318c..1e57404 100644 --- a/README.md +++ b/README.md @@ -24,6 +24,6 @@ This Python 3.12+ repository is a **template for your own application**. Create - [Make the template your application](docs/application.md) — customize the starter CLI, tests, and optional GUI. - [Everyday development](docs/development.md) — [command quick reference](docs/development.md#command-quick-reference) for uv, the local desktop, and Git; plus dependencies, tests, and code quality. - [Container usage](docs/container.md) — optional local CLI and Xpra image checks and advanced settings. -- [CI and deployment](docs/deployment.md) — maintained workflow path, image choice, and Harbor GitHub App contacts. +- [CI and deployment](docs/deployment.md) — maintained workflow path, image choice, Harbor GitHub App contacts, launcher resource limits, and persistent storage. - [Fermilab Kerberos defaults](docs/kerberos.md) — control-system authentication versus configuration and runtime tickets. - [Migrating an existing Python project](docs/migration.md) — adapt existing code and dependencies. diff --git a/docs/application.md b/docs/application.md index d264507..6fff4c8 100644 --- a/docs/application.md +++ b/docs/application.md @@ -12,7 +12,7 @@ The rename script updates the example package paths, links, and installed comman 1. **Choose what your app does.** Decide what should happen when someone runs your installed command, what inputs it needs, and whether it needs a window. You can start with a simple command that prints a result and expand from there. 2. **Edit your package's entry point.** Open your package's [`main.py`](../src/ap_python_starter_kit/main.py). Change its argument parser and default behavior to run **your** application. Replace the example `--device` flag, ACSys request, five-reading loop, and `--gui` switch if they do not fit. Keep a callable entry point returning an exit status, or change the `[project.scripts]` mapping in [`pyproject.toml`](../pyproject.toml) to your new callable. Then `uv sync --dev` refreshes the installed command. Running your command with `--help` is a useful check if you retain an argument parser. -3. **Adapt the demo code and add what your app needs.** The example [`acsys_client.py`](../src/ap_python_starter_kit/acsys_client.py) wraps ACSys DPM calls for the sample request. You can adapt that wrapper or call ACSys from your own code. If you do not use the wrapper, update its imports and clean up unused demo code so the launcher starts your code. Add other libraries as needed, then run `uv sync` and review changes to [`uv.lock`](../uv.lock); see [Dependencies and environment](development.md#dependencies-and-environment). +3. **Adapt the demo code and add what your app needs.** The example [`acsys_client.py`](../src/ap_python_starter_kit/acsys_client.py) wraps ACSys DPM calls for the sample request. You can adapt that wrapper or call ACSys from your own code. If you do not use the wrapper, update its imports and clean up unused demo code so the launcher starts your code. Add other libraries as needed, then run `uv sync` and review changes to [`uv.lock`](../uv.lock); see [Dependencies and environment](development.md#dependencies-and-environment). If your app needs to keep data after it exits, write it to the directory in `AP_WRITABLE_STORAGE_DIR`; see [Persistent storage](deployment.md#persistent-storage). 4. **Decide whether you want a desktop window.** For a CLI or headless app, remove the unused GUI branch and module, and remove the `gui-pyqt` extra if you no longer need PyQt. For a desktop app, customize the example window and update thread in [`gui.py`](../src/ap_python_starter_kit/gui.py) for your own UI and data flow; you can still use ACSys. If you prefer another toolkit, declare its dependencies and arrange for its entry point to launch. To try the *unchanged* sample GUI, use `uv sync --extra gui-pyqt` and `uv run ap-python-starter-kit --gui`. The [DevPod desktop](devpod.md#desktop-access) lets you see a window during development. 5. **Choose how your app is delivered.** For a CLI/headless application, choose the `cli` image variant in the provided workflow; for a desktop app, `gui-xpra` provides browser access to its window. Most changes **inside the renamed entry point** need no image startup changes: the rename script updates the original module names in both startup paths. Only if you move or replace that entry point must you update the CLI image's fixed command in the [`Dockerfile`](../Dockerfile), or the GUI image's default `APP_CMD` in [`docker/start.sh`](../docker/start.sh), to launch your code. You do not need to build images locally to deliver your app. See [CI and deployment](deployment.md) for the normal release path and [Container usage](container.md) for optional local image tests and startup details. 6. **Make tests describe your app.** Replace the example behavior checks in [`tests/test_main.py`](../tests/test_main.py) with tests for your arguments, command behavior, and any window logic you retain. Existing tests mock the ACSys reader; they do not confirm real ACSys connectivity. Run `uv run pytest`, followed by the quality checks in [Everyday development](development.md#tests-and-code-quality), and keep the [uv project compatible with integration](development.md#stay-compatible-with-integration). Commit your changes on a branch and follow [CI and deployment](deployment.md) when ready to deliver. diff --git a/docs/deployment.md b/docs/deployment.md index bb97be7..b638b70 100644 --- a/docs/deployment.md +++ b/docs/deployment.md @@ -30,6 +30,38 @@ The [AP Python Launcher](https://ad-apps-internal.fnal.gov/ap-python/) applies t Individual applications can be given higher resource limits on request. If a particular app needs higher limits, send the AP Python team a request with supporting documentation showing that app's specific needs, including data from tests of the app's resource usage during runtime. +## Persistent storage + +The [AP Python Launcher](https://ad-apps-internal.fnal.gov/ap-python/) gives every launched app persistent storage from a shared Kubernetes persistent volume (PVC). Your app can find it through two environment variables set by the launcher: + +| Environment variable | Default value | Points to | Access | Location within the PVC | +| --- | --- | --- | --- | --- | +| `AP_WRITABLE_STORAGE_DIR` | `/mnt/storage/ap-python-writable` | This launch's own directory, where your app should store its persistent data | Writable | `/ap-python//` | +| `AP_READ_ONLY_STORAGE_DIR` | `/mnt/storage/ap-python-read-only` | A view of all data in the shared storage | Read-only | `/ap-python/` | + +The last column shows where each mounted directory lives in the PVC, which is useful when locating your app's data from outside the container. `` is your repository name and `` is the microsecond launch time. + +Example: + +```python +import os +from pathlib import Path + +output_dir = Path(os.environ["AP_WRITABLE_STORAGE_DIR"]) +if not output_dir.is_dir(): + raise RuntimeError(f"Writable storage is not available at {output_dir}") + +(output_dir / "result.csv").write_text("value\n42\n") +``` + +When running outside the launcher (for example, in your DevPod workspace), you can set `AP_WRITABLE_STORAGE_DIR` to a local directory for the code above to work. + +Keep these points in mind when using it: + +- **Write persistent data to the writable directory only.** Anything written elsewhere in the container is lost when the launch ends. +- **Outputs outlive the launch.** Data stays available in the shared read-only view after the Job is deleted or expires. There is no automatic cleanup of old data. +- **Storage setup failures are reported by the launcher.** If the launcher cannot initialize your launch's directory, the launch fails and the failure is reported in its status instead of starting your app. + ## Advanced: workflow settings and behavior The steps above cover normal delivery. The settings and guards below are for changing integration options or troubleshooting an Actions run; the reusable workflows and base images are maintained outside your repository.