Skip to content

Python tool for aircraft Doppler audio geolocation using historical ADS-B flight data (Source-available)

Publish the validated Docker image to GHCR

Cinna Davisf1245d79c809
diff --git a/.github/workflows/docker.yml b/.github/workflows/docker.yml
index 69749e2..c134658 100644
--- a/.github/workflows/docker.yml
+++ b/.github/workflows/docker.yml
@@ -1,7 +1,8 @@
-name: Docker build and local service
+name: Docker build, local service and GHCR
on:
push:
branches: [main]
+ tags: ['v*']
pull_request:
workflow_dispatch:
@@ -10,16 +11,38 @@ permissions:
concurrency:
group: docker-${{ github.ref }}
- cancel-in-progress: true
+ cancel-in-progress: ${{ github.event_name == 'pull_request' }}
jobs:
docker:
runs-on: ubuntu-24.04
timeout-minutes: 20
+ outputs:
+ publish: ${{ steps.metadata.outputs.publish }}
+ image_tags: ${{ steps.metadata.outputs.tags }}
+ image_id: ${{ steps.export.outputs.image_id }}
+ image_artifact_id: ${{ steps.upload.outputs.artifact-id }}
steps:
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
+ with:
+ persist-credentials: false
+ - name: Check publication event and tag rules
+ run: python -m unittest discover -s tests -p test_container_publish_metadata.py
+ - name: Derive image metadata and publication eligibility
+ id: metadata
+ run: python scripts/container_publish_metadata.py
- name: Build runtime image
- run: docker build --tag dopplergeist:ci .
+ env:
+ IMAGE_SOURCE: ${{ github.server_url }}/${{ github.repository }}
+ IMAGE_REVISION: ${{ steps.metadata.outputs.revision }}
+ IMAGE_VERSION: ${{ steps.metadata.outputs.version }}
+ run: |
+ docker build --platform linux/amd64 --tag dopplergeist:ci \
+ --label "org.opencontainers.image.title=DOPPLERGEIST" \
+ --label "org.opencontainers.image.source=$IMAGE_SOURCE" \
+ --label "org.opencontainers.image.revision=$IMAGE_REVISION" \
+ --label "org.opencontainers.image.version=$IMAGE_VERSION" \
+ --label "org.opencontainers.image.licenses=PolyForm-Noncommercial-1.0.0" .
- name: Check installed runtime, native modules and licenses
run: |
docker run --rm --entrypoint python dopplergeist:ci -m pip check
@@ -101,3 +124,72 @@ jobs:
--mount type=volume,src=dopplergeist-ci-jobs,dst=/data/jobs \
--mount type=volume,src=dopplergeist-ci-cache,dst=/home/dopplergeist/.cache/dopplergeist \
dopplergeist:ci -c 'from pathlib import Path; roots = [Path("/data/jobs"), Path.home()/".cache"/"dopplergeist"]; assert all((root/"container-write-check").read_text() == "persistent" for root in roots)'
+ - name: Export the validated image
+ id: export
+ if: steps.metadata.outputs.publish == 'true'
+ run: |
+ image_id=$(docker image inspect --format '{{.Id}}' dopplergeist:ci)
+ echo "image_id=$image_id" >> "$GITHUB_OUTPUT"
+ docker save --output "$RUNNER_TEMP/dopplergeist-image.tar" dopplergeist:ci
+ - name: Transfer the validated image to the publish job
+ id: upload
+ if: steps.metadata.outputs.publish == 'true'
+ uses: actions/upload-artifact@cf430e030ddbb5b0abf93d22962f4752f3646cd9 # v7
+ with:
+ name: docker-image-${{ github.run_id }}-${{ github.run_attempt }}
+ path: ${{ runner.temp }}/dopplergeist-image.tar
+ if-no-files-found: error
+ compression-level: 0
+ retention-days: 1
+
+ publish:
+ needs: docker
+ if: >-
+ github.repository == '1337isnot1337/DOPPLERGEIST'
+ && needs.docker.outputs.publish == 'true'
+ && ((github.event_name == 'push'
+ && (github.ref == 'refs/heads/main' || startsWith(github.ref, 'refs/tags/v')))
+ || (github.event_name == 'workflow_dispatch' && github.ref == 'refs/heads/main'))
+ runs-on: ubuntu-24.04
+ timeout-minutes: 15
+ permissions:
+ packages: write
+ steps:
+ - name: Download this run's validated image
+ uses: actions/download-artifact@9000827ccba6bdab643e8b6fd33ac0654aef8333 # v8
+ with:
+ artifact-ids: ${{ needs.docker.outputs.image_artifact_id }}
+ path: ${{ runner.temp }}
+ - name: Load and identify the validated image
+ env:
+ EXPECTED_IMAGE_ID: ${{ needs.docker.outputs.image_id }}
+ run: |
+ docker load --input "$RUNNER_TEMP/dopplergeist-image.tar"
+ test "$(docker image inspect --format '{{.Id}}' dopplergeist:ci)" = "$EXPECTED_IMAGE_ID"
+ - name: Log in to GHCR
+ uses: docker/login-action@dbcb813823bdd20940b903addbd779551569679f # v4.6.0
+ with:
+ registry: ghcr.io
+ username: ${{ github.actor }}
+ password: ${{ secrets.GITHUB_TOKEN }}
+ - name: Publish the validated image
+ env:
+ IMAGE_TAGS: ${{ needs.docker.outputs.image_tags }}
+ run: |
+ python - <<'PY'
+ import json
+ import os
+ from pathlib import Path
+ import subprocess
+
+ tags = json.loads(os.environ["IMAGE_TAGS"])
+ if not tags:
+ raise ValueError("No approved image tags to publish")
+ for tag in tags:
+ subprocess.run(["docker", "tag", "dopplergeist:ci", tag], check=True)
+ subprocess.run(["docker", "push", tag], check=True)
+ with Path(os.environ["GITHUB_STEP_SUMMARY"]).open("a") as summary:
+ summary.write("## Published Docker image\n\n")
+ summary.writelines(f"- `{tag}`\n" for tag in tags)
+ summary.write("\nAll tags refer to the image validated by this workflow run.\n")
+ PY
diff --git a/docs/DOCKER.md b/docs/DOCKER.md
index 9c389c4..68eb863 100644
--- a/docs/DOCKER.md
+++ b/docs/DOCKER.md
@@ -1,6 +1,13 @@
# Run with Docker
-Build from the repository checkout:
+Pull the published `main` image from GitHub Container Registry:
+
+```bash
+docker pull ghcr.io/1337isnot1337/dopplergeist:main
+```
+
+The published image targets `linux/amd64`. Other architectures have not been
+validated. To build from a repository checkout instead:
```bash
docker build --tag dopplergeist:local .
@@ -19,10 +26,11 @@ docker run --detach --init --name dopplergeist \
--publish 127.0.0.1:8765:8765 \
--mount type=volume,src=dopplergeist-jobs,dst=/data/jobs \
--mount type=volume,src=dopplergeist-cache,dst=/home/dopplergeist/.cache/dopplergeist \
- dopplergeist:local
+ ghcr.io/1337isnot1337/dopplergeist:main
```
Open `http://127.0.0.1:8765`. Docker creates the named volumes when needed.
+For a local build, replace the image name with `dopplergeist:local`.
The jobs volume preserves uploads, results and checkpoints. The cache volume
preserves downloaded flight archives, indexes, terrain and geoid data.
Existing bind-mount directories must be writable by UID/GID `10001`.
@@ -43,7 +51,7 @@ Normal non-container `serve` still defaults to `127.0.0.1`.
The default container has online acquisition disabled. Audio intake and discovery
remain available; historical search needs configured data and a defensible
recording-start window. To permit public downloads, append the following command
-after `dopplergeist:local` in the `docker run` command above:
+after the image name in the `docker run` command above:
```bash
serve --host 0.0.0.0 --port 8765 --jobs /data/jobs --online --max-runtime 14400
@@ -83,6 +91,41 @@ service port. For port `8876`, use `--publish 127.0.0.1:8876:8876` and append th
complete command `serve --host 0.0.0.0 --port 8876 --jobs /data/jobs` to the image
name. A mapping such as `8876:8765` will not pass the existing Host check.
+## Image versions and publication
+
+The Docker workflow publishes `ghcr.io/1337isnot1337/dopplergeist` after the image
+passes its runtime, HTTP, license and volume checks. A separate publishing job
+loads that validated image and checks its image ID before pushing it to GHCR.
+The image is transferred within the same workflow run; publication uses that
+image without rebuilding it.
+
+| Tag | Source |
+| --- | --- |
+| `main` | A successful push to `main`, or a manual run on `main` |
+| `vMAJOR.MINOR.PATCH` | The matching Git tag, such as `v0.1.0` |
+| `vMAJOR.MINOR.PATCH-PRERELEASE` | The matching prerelease tag, such as `v0.2.0-rc.1` |
+| `sha-FULL_COMMIT_ID` | The complete source commit ID for every published image |
+
+Version tags use SemVer release/prerelease syntax without `+build` metadata.
+Image labels record the source repository, commit, version and
+`PolyForm-Noncommercial-1.0.0` license. A revision tag identifies the source
+commit. To retain an exact built image, use the registry digest printed by the
+publishing job: `ghcr.io/1337isnot1337/dopplergeist@sha256:DIGEST`.
+
+Maintainers can publish `main` through **Actions → Docker build, local service
+and GHCR → Run workflow**, selecting `main`. Other manually selected branches
+run validation only. Pull requests and forks run without package-write
+permission and cannot publish through this workflow. Publication uses the
+repository's generated `GITHUB_TOKEN`; no registry password secret is needed.
+
+GitHub makes a newly published GHCR package private by default. After the first
+successful publication, a package administrator must set its visibility to
+**Public** to enable the anonymous pull command above. The image's source label
+links it to this repository. If an existing package rejects `GITHUB_TOKEN`
+writes, grant this repository access under the package's **Manage Actions
+access** settings. These package settings are separate from workflow token
+permissions. See GitHub's [Container registry documentation](https://docs.github.com/en/packages/working-with-a-github-packages-registry/working-with-the-container-registry).
+
## Verification
The Docker workflow builds the image and checks native imports, FFmpeg, GIS/audio
@@ -90,3 +133,5 @@ libraries, packaged browser assets and licenses. It checks actual HTTP access
through a bridge-published loopback port, the existing Host/Origin checks, clean
shutdown, and non-root writes that persist across containers in both volumes.
These checks generate no audio, flight tracks or scientific job results.
+Publication eligibility and tag rules are also checked with
+`python -m unittest discover -s tests -p test_container_publish_metadata.py`.
diff --git a/scripts/container_publish_metadata.py b/scripts/container_publish_metadata.py
new file mode 100644
index 0000000..8c0ea49
--- /dev/null
+++ b/scripts/container_publish_metadata.py
@@ -0,0 +1,56 @@
+"""Derive GHCR metadata and publication eligibility from a GitHub event.
+
+This helper never authenticates or publishes. The workflow also guards its
+package-write job independently, before granting that job a token.
+"""
+import json
+import os
+from pathlib import Path
+import re
+import subprocess
+
+
+REPOSITORY = "1337isnot1337/DOPPLERGEIST"
+_VERSION = re.compile(
+ r"refs/tags/(v(?:0|[1-9][0-9]*)\.(?:0|[1-9][0-9]*)\.(?:0|[1-9][0-9]*)"
+ r"(?:-([0-9A-Za-z-]+(?:\.[0-9A-Za-z-]+)*))?)"
+)
+
+
+def metadata(repository, event, ref, revision):
+ if not re.fullmatch(r"[A-Za-z0-9_.-]+/[A-Za-z0-9_.-]+", repository):
+ raise ValueError("Invalid repository name")
+ if not re.fullmatch(r"[0-9a-f]{40}", revision):
+ raise ValueError("Image revision must be a complete Git commit ID")
+ matched = _VERSION.fullmatch(ref)
+ version = matched.group(1) if matched else None
+ if version and (len(version) > 128 or any(
+ part.isdecimal() and len(part) > 1 and part.startswith("0")
+ for part in (matched.group(2) or "").split("."))):
+ version = None
+ main = ref == "refs/heads/main"
+ publish = repository == REPOSITORY and (
+ event == "push" and (main or version is not None)
+ or event == "workflow_dispatch" and main
+ )
+ image = "ghcr.io/" + repository.lower()
+ version = "main" if main else version or "sha-" + revision
+ tags = [f"{image}:sha-{revision}", f"{image}:{version}"] if publish else []
+ return {"publish": publish, "image": image, "revision": revision,
+ "version": version, "tags": tags}
+
+
+def main():
+ revision = subprocess.run(["git", "rev-parse", "HEAD"], check=True,
+ capture_output=True, text=True).stdout.strip()
+ values = metadata(os.environ["GITHUB_REPOSITORY"], os.environ["GITHUB_EVENT_NAME"],
+ os.environ["GITHUB_REF"], revision)
+ with Path(os.environ["GITHUB_OUTPUT"]).open("a") as output:
+ for key, value in values.items():
+ if isinstance(value, (bool, list)):
+ value = json.dumps(value, separators=(",", ":"))
+ output.write(f"{key}={value}\n")
+
+
+if __name__ == "__main__":
+ main()
diff --git a/tests/test_container_publish_metadata.py b/tests/test_container_publish_metadata.py
new file mode 100644
index 0000000..fced403
--- /dev/null
+++ b/tests/test_container_publish_metadata.py
@@ -0,0 +1,70 @@
+"""Publication-policy checks; no audio, trajectories or image builds."""
+import importlib.util
+from pathlib import Path
+import unittest
+
+
+SOURCE = Path(__file__).resolve().parents[1] / "scripts/container_publish_metadata.py"
+SPEC = importlib.util.spec_from_file_location("container_publish_metadata", SOURCE)
+MODULE = importlib.util.module_from_spec(SPEC)
+SPEC.loader.exec_module(MODULE)
+REVISION = "dcd8cb73114af0a20be869e9e8c3295080b65ab8"
+
+
+class ContainerPublishMetadataTests(unittest.TestCase):
+ def metadata(self, event, ref, repository=MODULE.REPOSITORY):
+ return MODULE.metadata(repository, event, ref, REVISION)
+
+ def test_main_push_and_dispatch_have_full_revision_and_main_tags(self):
+ for event in ("push", "workflow_dispatch"):
+ with self.subTest(event=event):
+ result = self.metadata(event, "refs/heads/main")
+ self.assertTrue(result["publish"])
+ self.assertEqual(result["image"], "ghcr.io/1337isnot1337/dopplergeist")
+ self.assertEqual(result["revision"], REVISION)
+ self.assertEqual(result["tags"], [result["image"] + ":sha-" + REVISION,
+ result["image"] + ":main"])
+
+ def test_release_and_prerelease_keep_the_exact_version(self):
+ for version in ("v0.1.0", "v1.2.3", "v2.0.0-rc.1"):
+ with self.subTest(version=version):
+ result = self.metadata("push", "refs/tags/" + version)
+ self.assertTrue(result["publish"])
+ self.assertEqual(result["version"], version)
+ self.assertEqual(result["tags"][-1], result["image"] + ":" + version)
+ self.assertFalse(any(tag.endswith((":latest", ":main")) for tag in result["tags"]))
+
+ def test_pull_requests_forks_and_other_events_cannot_publish(self):
+ for event in ("pull_request", "pull_request_target", "workflow_run", "schedule"):
+ for ref in ("refs/heads/main", "refs/tags/v1.2.3", "refs/pull/340/merge"):
+ with self.subTest(event=event, ref=ref):
+ result = self.metadata(event, ref)
+ self.assertFalse(result["publish"])
+ self.assertEqual(result["tags"], [])
+ for event in ("push", "workflow_dispatch"):
+ with self.subTest(fork_event=event):
+ result = self.metadata(event, "refs/heads/main", "a-fork/DOPPLERGEIST")
+ self.assertFalse(result["publish"])
+ self.assertEqual(result["tags"], [])
+
+ def test_dispatch_on_other_refs_does_not_publish(self):
+ for ref in ("refs/heads/topic", "refs/tags/v1.2.3", "refs/pull/340/head"):
+ with self.subTest(ref=ref):
+ self.assertFalse(self.metadata("workflow_dispatch", ref)["publish"])
+
+ def test_malformed_or_unsupported_version_tags_do_not_publish(self):
+ for version in ("vnext", "v1.2", "v01.2.3", "v1.2.3-01", "v1.2.3+build",
+ "v1.2.3-rc..1", "v1.2.3/extra", "v1.2.3-" + "a" * 128):
+ with self.subTest(version=version):
+ result = self.metadata("push", "refs/tags/" + version)
+ self.assertFalse(result["publish"])
+ self.assertEqual(result["tags"], [])
+
+ def test_revision_cannot_be_abbreviated_or_contain_shell_text(self):
+ for revision in (REVISION[:7], "$(whoami)", REVISION + "\nextra"):
+ with self.subTest(revision=revision), self.assertRaises(ValueError):
+ MODULE.metadata(MODULE.REPOSITORY, "push", "refs/heads/main", revision)
+
+
+if __name__ == "__main__":
+ unittest.main()