Repository navigation
Replies: 1 comment
PoC implementation (reference)For anyone who wants to see the actual code rather than the description, here is the full PoC bundle (~50 lines of code). Same scope caveats as above: local single-node PoC, local zot registry over plain HTTP, no auth, no digest versioning, no signatures. Config [dag_processor]
dag_bundle_config_list = [
{"name": "oci-team-a",
"classpath": "oci_dag_bundle.OciDagBundle",
"kwargs": {"ref": "localhost:5000/dags/team-a:v1", "insecure": true, "refresh_interval": 30}}
]Push tar -czf dags-v1.tar.gz -C dags .
oras push --plain-http localhost:5000/dags/team-a:v1 \
dags-v1.tar.gz:application/vnd.oci.image.layer.v1.tar+gzip
from __future__ import annotations
import os
import shutil
import tarfile
import tempfile
from pathlib import Path
import oras.client
from airflow.dag_processing.bundles.base import BaseDagBundle
LAYER_MEDIA_TYPES = {
"application/vnd.oci.image.layer.v1.tar+gzip",
"application/vnd.oci.image.layer.v1.tar",
}
class OciDagBundle(BaseDagBundle):
"""Pull a DAG directory stored as a tar layer in an OCI registry."""
supports_versioning = False
def __init__(self, *, ref: str, insecure: bool = False, subdir: str | None = None, **kwargs) -> None:
super().__init__(**kwargs)
self.ref = ref # e.g. "localhost:5000/dags/team-a:v1"
self.subdir = subdir
self._client = oras.client.OrasClient(insecure=insecure)
@property
def path(self) -> Path:
root = self.base_dir / "current"
return root / self.subdir if self.subdir else root
def get_current_version(self) -> None:
return None
def initialize(self) -> None:
if not self.is_initialized:
self.refresh()
super().initialize()
def refresh(self) -> None:
self.base_dir.mkdir(parents=True, exist_ok=True)
staging = Path(tempfile.mkdtemp(prefix=".staging-", dir=self.base_dir))
try:
# Resolve tag to manifest, download the DAG layer as-is
container = self._client.get_container(self.ref)
manifest = self._client.get_manifest(container)
layer = next(l for l in manifest["layers"] if l["mediaType"] in LAYER_MEDIA_TYPES)
archive = staging / "bundle.tar"
self._client.download_blob(container, layer["digest"], str(archive))
# Safe extraction (rejects path traversal, links, devices)
unpacked = staging / "unpacked"
unpacked.mkdir()
with tarfile.open(archive, "r:*") as tar:
tar.extractall(unpacked, filter="data")
# Swap into place under the bundle lock
with self.lock():
current = self.base_dir / "current"
old = self.base_dir / ".old"
shutil.rmtree(old, ignore_errors=True)
if current.exists():
os.rename(current, old)
os.rename(unpacked, current)
shutil.rmtree(old, ignore_errors=True)
finally:
shutil.rmtree(staging, ignore_errors=True)Notes
|
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Hi everyone,
A quick disclaimer up front: I'm not an expert in Airflow internals, so please treat this as a proposal and an exploration rather than a finished design. This is what I'd suggest based on our own needs, and I'd really appreciate corrections from people who know this area better.
What if Airflow DAGs could be shipped the same way we already ship container images and Helm charts: as versioned OCI artifacts pulled from a registry?
I'd like to explore whether official support for loading DAGs from an OCI registry as a DAG Bundle backend in Airflow 3, alongside Local, Git and object-storage bundles, would make sense. This is a discussion to gauge community interest and collect design feedback, not a committed implementation.
Problem
Airflow 3 bundles cover Local, Git (
GitDagBundle) and object storage (S3, GCS, Azure Blob), but there is no official way to deliver DAGs from an OCI registry. Teams in air-gapped, restricted or registry-centric environments often have a registry mirror or connected registry available, but no Git access from production.As far as I understand, Argo CD faced a similar constraint and added OCI as a first-class application source alongside Git, for similar reasons: Git is the default, but many environments simply cannot reach Git. An Argo CD Application can point at
oci://...by tag or digest, and content is packaged withoras pushas a singleapplication/vnd.oci.image.layer.v1.tar+gziplayer (Argo CD OCI docs). Git stays the authoring system, and the registry becomes the distribution channel for clusters Git cannot reach.In practice this could resemble a managed GitOps flow: teams still author and review DAGs in Git, CI publishes an immutable, versioned artifact (for example
1.4.2), and each environment reconciles to a declared version by pulling from its registry. Like Argo CD's OCI and Helm sources, the bundle could accept either an exact tag or digest, or a semver constraint (for example1.4.*or>=1.4.0 <2.0.0), resolving to the highest matching version on each refresh. Production can then follow patch releases automatically while staying pinned to a major version, and the resolved digest is recorded as the bundle version for each run. The desired state stays declared and versioned, but the cluster never needs to talk to Git directly.This seems to follow the same pattern other cloud-native tools already use: Argo CD and Flux pull OCI artifacts with semver constraints, Helm charts are distributed as OCI artifacts, and container images themselves follow tag, digest and semver conventions. Treating DAGs the same way could let platform teams reuse their existing registry, mirroring, promotion and access-control workflows instead of building a separate path just for Airflow.
Today's workarounds each have a gap: baking DAGs into the Airflow image couples every DAG change to a control-plane rollout; git-sync and
GitDagBundlerequire Git connectivity from the DAG processor and workers; object storage is a separate operational plane from the one these teams already use for images.I searched apache/airflow issues, PRs and Discussions and could not find an existing proposal for an OCI or ORAS bundle. If I missed one, I'd rather join it.
Motivation
1.1.0,1.2.0,2.0.0), so an environment can pin an exact version or follow a range such as>=1.1.0 <1.2.0, and a breaking change can ship as a new major version without silently reaching environments that are pinned to the previous one. As far as I can tell, prefix-based blob storage bundles don't offer this today: they serve whatever is currently under the prefix, with no version ranges and no immutable history to roll back to.refresh_interval, configurable per bundle). With a floating tag such aslatestorstable, new DAGs are picked up on the next refresh with no image rebuild or restart.dag_bundle_config_list).Possible approach (rough sketch)
One possible shape, very open to better ideas: a DAG Bundle type backed by OCI (
BaseDagBundleimplementation, likely in a new community provider), using ORAS-style manifest and layer pulls:tarfilefilter="data").lock().get_current_version()so runs can be pinned.Proof of concept
I ran a minimal end-to-end PoC locally (single Linux VM, local zot registry over plain HTTP, not a Kubernetes or production cluster):
OciDagBundle(BaseDagBundle)of about 50 lines, wired through[dag_processor] dag_bundle_config_listwith no core changes.tar+gziplayer (the Argo CD layout), plus a plain single-layer OCI image.pull()auto-extracts layers with its own extractor, so it seemed safer for the bundle to download the layer blob directly to control safe extraction.Questions for the community
orascommunity provider be the right home?latest) gives easy refresh, while a static tag or digest gives consistency. How should the DAG processor, schedulers and every worker resolve the same digest for a run when a tag moves?get_current_version().tar+gziplayer, a dedicated media type, or both.If the direction is welcome, I'm happy to contribute the implementation, tests and docs, and if it lands, it would be great to see it highlighted in the release notes so teams in disconnected environments can find it.
If this would help your team, please react or comment with your use case. That's the best signal for whether this is worth building upstream. Thanks for reading!
I used Grok to help with this and reviewed it myself.
All reactions