Skip to content

A reactive notebook for Python — run reproducible experiments, query with SQL, execute as a script, deploy as an app, and version with git. Stored as pure Python. All in a modern, AI-native editor.

Daggerize the test pipelines and make environment (#2546)

Kyle Penfounde61402128380
diff --git a/.github/workflows/test_fe_dagger.yaml b/.github/workflows/test_fe_dagger.yaml
new file mode 100644
index 0000000000..dca1d5fc69
--- /dev/null
+++ b/.github/workflows/test_fe_dagger.yaml
@@ -0,0 +1,45 @@
+name: Test FE Dagger
+
+on:
+ push:
+ branches: [main]
+ pull_request:
+
+env:
+ TURBO_TOKEN: ${{ secrets.TURBO_TOKEN }}
+
+jobs:
+ changes:
+ runs-on: ubuntu-latest
+ outputs:
+ frontend: ${{ steps.filter.outputs.frontend }}
+ steps:
+ - uses: actions/checkout@v4
+ - uses: dorny/paths-filter@v3
+ id: filter
+ with:
+ filters: |
+ frontend:
+ - 'frontend/**'
+ - 'lsp/**'
+ - 'openapi/**'
+ - 'dagger/**'
+
+ test_frontend:
+ needs: changes
+ if: ${{ needs.changes.outputs.frontend == 'true' }}
+ name: 🖥️ Lint, test, build frontend
+ runs-on: ubuntu-latest
+ timeout-minutes: 15
+
+ steps:
+ - name: 🛑 Cancel Previous Runs
+ uses: styfle/[email protected]
+
+ - name: ⬇️ Checkout repo
+ uses: actions/checkout@v4
+
+ - uses: dagger/dagger-for-github@v6
+ name: 🚀 Dagger
+ with:
+ args: frontend test
diff --git a/dagger.json b/dagger.json
new file mode 100644
index 0000000000..c6632e9191
--- /dev/null
+++ b/dagger.json
@@ -0,0 +1,6 @@
+{
+ "name": "marimo",
+ "sdk": "python",
+ "source": "dagger",
+ "engineVersion": "v0.13.0"
+}
diff --git a/dagger/.gitattributes b/dagger/.gitattributes
new file mode 100644
index 0000000000..827418463f
--- /dev/null
+++ b/dagger/.gitattributes
@@ -0,0 +1 @@
+/sdk/** linguist-generated
diff --git a/dagger/.gitignore b/dagger/.gitignore
new file mode 100644
index 0000000000..78f6c8dd39
--- /dev/null
+++ b/dagger/.gitignore
@@ -0,0 +1 @@
+/sdk
diff --git a/dagger/pyproject.toml b/dagger/pyproject.toml
new file mode 100644
index 0000000000..e9bfc92bd4
--- /dev/null
+++ b/dagger/pyproject.toml
@@ -0,0 +1,9 @@
+[project]
+name = "main"
+version = "0.0.0"
+dependencies = []
+
+[build-system]
+requires = ["hatchling"]
+build-backend = "hatchling.build"
+
diff --git a/dagger/requirements.lock b/dagger/requirements.lock
new file mode 100644
index 0000000000..c88329fcf5
--- /dev/null
+++ b/dagger/requirements.lock
@@ -0,0 +1,94 @@
+# This file was autogenerated by uv via the following command:
+# uv pip compile --universal -o requirements.lock sdk/pyproject.toml pyproject.toml
+anyio==4.4.0
+ # via
+ # dagger-io (sdk/pyproject.toml)
+ # gql
+ # httpx
+attrs==24.2.0
+ # via cattrs
+backoff==2.2.1
+ # via gql
+beartype==0.18.5
+ # via dagger-io (sdk/pyproject.toml)
+cattrs==24.1.0
+ # via dagger-io (sdk/pyproject.toml)
+certifi==2024.8.30
+ # via
+ # httpcore
+ # httpx
+deprecated==1.2.14
+ # via
+ # opentelemetry-api
+ # opentelemetry-exporter-otlp-proto-grpc
+ # opentelemetry-semantic-conventions
+googleapis-common-protos==1.65.0
+ # via opentelemetry-exporter-otlp-proto-grpc
+gql==3.5.0
+ # via dagger-io (sdk/pyproject.toml)
+graphql-core==3.2.4
+ # via gql
+grpcio==1.66.1
+ # via opentelemetry-exporter-otlp-proto-grpc
+h11==0.14.0
+ # via httpcore
+httpcore==1.0.5
+ # via httpx
+httpx==0.27.2
+ # via gql
+idna==3.8
+ # via
+ # anyio
+ # httpx
+ # yarl
+importlib-metadata==8.4.0
+ # via opentelemetry-api
+markdown-it-py==3.0.0
+ # via rich
+mdurl==0.1.2
+ # via markdown-it-py
+multidict==6.0.5
+ # via yarl
+opentelemetry-api==1.27.0
+ # via
+ # opentelemetry-exporter-otlp-proto-grpc
+ # opentelemetry-sdk
+ # opentelemetry-semantic-conventions
+opentelemetry-exporter-otlp-proto-common==1.27.0
+ # via opentelemetry-exporter-otlp-proto-grpc
+opentelemetry-exporter-otlp-proto-grpc==1.27.0
+ # via dagger-io (sdk/pyproject.toml)
+opentelemetry-proto==1.27.0
+ # via
+ # opentelemetry-exporter-otlp-proto-common
+ # opentelemetry-exporter-otlp-proto-grpc
+opentelemetry-sdk==1.27.0
+ # via
+ # dagger-io (sdk/pyproject.toml)
+ # opentelemetry-exporter-otlp-proto-grpc
+opentelemetry-semantic-conventions==0.48b0
+ # via opentelemetry-sdk
+platformdirs==4.3.2
+ # via dagger-io (sdk/pyproject.toml)
+protobuf==4.25.4
+ # via
+ # googleapis-common-protos
+ # opentelemetry-proto
+pygments==2.18.0
+ # via rich
+rich==13.8.0
+ # via dagger-io (sdk/pyproject.toml)
+sniffio==1.3.1
+ # via
+ # anyio
+ # httpx
+typing-extensions==4.12.2
+ # via
+ # dagger-io (sdk/pyproject.toml)
+ # opentelemetry-sdk
+wrapt==1.16.0
+ # via deprecated
+yarl==1.11.0
+ # via gql
+zipp==3.20.1
+ # via importlib-metadata
diff --git a/dagger/src/main/__init__.py b/dagger/src/main/__init__.py
new file mode 100644
index 0000000000..4f608590ec
--- /dev/null
+++ b/dagger/src/main/__init__.py
@@ -0,0 +1,3 @@
+"""A module for Marimo functions
+"""
+from .main import Marimo
diff --git a/dagger/src/main/backend.py b/dagger/src/main/backend.py
new file mode 100644
index 0000000000..923761fa55
--- /dev/null
+++ b/dagger/src/main/backend.py
@@ -0,0 +1,22 @@
+from typing import Annotated
+
+import dagger
+from dagger import DefaultPath, Doc, Ignore, dag, field, function, object_type
+
+from .env import Env
+
+
+@object_type
+class Backend:
+ src: Annotated[dagger.Directory, Doc("The marimo source tree to use")] = field()
+
+ @function
+ def test(self) -> dagger.Container:
+ return (
+ # python base
+ Env().py()
+ .with_directory("/src", self.src)
+ .with_workdir("/src")
+ .with_exec(["make", "py"])
+ .with_exec(["make", "py-test"])
+ )
diff --git a/dagger/src/main/cli.py b/dagger/src/main/cli.py
new file mode 100644
index 0000000000..5a8a883919
--- /dev/null
+++ b/dagger/src/main/cli.py
@@ -0,0 +1,16 @@
+from typing import Annotated
+
+import dagger
+from dagger import DefaultPath, Doc, Ignore, dag, field, function, object_type
+
+
+@object_type
+class Cli:
+ src: Annotated[dagger.Directory, Doc("The marimo source tree to use"), DefaultPath("/"), Ignore(["/dagger", ".venv"])] = field()
+
+ @function
+ def test(self) -> dagger.Container:
+ return (
+ # python base
+ dag.container().from_("python:3-bookworm")
+ )
diff --git a/dagger/src/main/env.py b/dagger/src/main/env.py
new file mode 100644
index 0000000000..c4a674b3bc
--- /dev/null
+++ b/dagger/src/main/env.py
@@ -0,0 +1,46 @@
+import dagger
+from dagger import DefaultPath, dag, function, object_type
+
+
+@object_type
+class Env:
+ @function
+ def dev(self) -> dagger.Container:
+ """Dev container with dependencies for the full stack"""
+ return (
+ # python base
+ self.py()
+ .with_mounted_cache("/root/.local/share/pnpm", dag.cache_volume("pnpm"))
+ # package deps
+ .with_exec(["apt", "update"])
+ .with_exec(["apt", "install", "-y", "curl"])
+ # install node 20+
+ .with_exec(["sh", "-c", "curl -fsSL https://deb.nodesource.com/setup_20.x | bash -"])
+ .with_exec(["apt", "install", "-y", "nodejs"])
+ # install pnpm@8
+ .with_exec(["npm", "install", "-g", "pnpm@8"])
+ .with_env_variable("NODE_OPTIONS", "--max-old-space-size=8192")
+ )
+
+ @function
+ def py(self) -> dagger.Container:
+ """Python container with dependencies for the backend"""
+ return (
+ # python base
+ dag.container().from_("python:3.12-bookworm")
+ .with_mounted_cache("/root/.cache/pip", dag.cache_volume("python-312"))
+ .with_exec(["apt-get", "update"])
+ .with_exec(["apt-get", "install", "-y", "make", "libgdal-dev", "python3-gdal"])
+ .with_exec(["pip", "install", "hatch", "typos"])
+ )
+
+ @function
+ def pnpm(self) -> dagger.Container:
+ """Pnpm container with dependencies for the frontend"""
+ return (
+ dag.container().from_("node:20-slim")
+ .with_env_variable("CI", "true")
+ .with_env_variable("NODE_OPTIONS", "--max-old-space-size=8192")
+ .with_mounted_cache("/root/.local/share/pnpm", dag.cache_volume("pnpm"))
+ .with_exec(["corepack", "enable"]) # this enables pnpm
+ )
diff --git a/dagger/src/main/frontend.py b/dagger/src/main/frontend.py
new file mode 100644
index 0000000000..61289fa24c
--- /dev/null
+++ b/dagger/src/main/frontend.py
@@ -0,0 +1,37 @@
+from typing import Annotated
+
+import dagger
+from dagger import DefaultPath, Doc, Ignore, dag, field, function, object_type
+
+from .env import Env
+
+
+@object_type
+class Frontend:
+ src: Annotated[dagger.Directory, Doc("The marimo source tree to use")] = field()
+
+ @function
+ def test(self, turbo_token: dagger.Secret = dag.set_secret("DEFAULT", "")) -> dagger.Container:
+ """
+ Replace .github/workflows/test_fe.yaml
+ """
+ return (
+ Env().pnpm()
+ .with_env_variable("MARIMO_SKIP_UPDATE_CHECK", "true")
+ .with_secret_variable("TURBO_TOKEN" , turbo_token)
+ .with_env_variable("TURBO_TEAM", "marimo")
+ .with_workdir("/src/frontend")
+ .with_directory("/src", self.src)
+ .with_exec(["pnpm", "install"])
+ .with_exec(["pnpm", "dedupe", "--check"])
+ .with_exec(["pnpm", "turbo", "lint"])
+ .with_exec(["pnpm", "turbo", "typecheck"])
+ .with_exec(["pnpm", "test"])
+ .with_env_variable("NODE_ENV", "production")
+ .with_exec(["pnpm", "turbo", "build"])
+ .with_env_variable("VITE_MARIMO_ISLANDS", "true")
+ .with_env_variable("VITE_MARIMO_VERSION", "0.0.0")
+ .with_exec(["npm", "version", "0.0.0", "--no-git-tag-version"])
+ .with_exec(["pnpm", "turbo", "build:islands"])
+ .with_exec(["./islands/validate.sh"])
+ )
diff --git a/dagger/src/main/main.py b/dagger/src/main/main.py
new file mode 100644
index 0000000000..7a012ddc13
--- /dev/null
+++ b/dagger/src/main/main.py
@@ -0,0 +1,46 @@
+from typing import Annotated
+
+import dagger
+from dagger import DefaultPath, Doc, Ignore, dag, field, function, object_type
+
+from .backend import Backend
+from .cli import Cli
+from .env import Env
+from .frontend import Frontend
+
+
+@object_type
+class Marimo:
+ """A collection of tasks for the Marimo project."""
+ src: Annotated[dagger.Directory, Doc("The marimo source tree to use")] = field()
+ frontend: Annotated[Frontend, Doc("Frontend components")] = field()
+ backend: Annotated[Backend, Doc("Backend components")] = field()
+ cli: Annotated[Cli, Doc("CLI components")] = field()
+ env: Annotated[Env, Doc("Test and Build environments")] = field()
+
+ @classmethod
+ def create(
+ cls,
+ src: Annotated[dagger.Directory, Doc("The marimo source tree to use"), DefaultPath("/"), Ignore(["**/dagger", "**/.venv"])],
+ ):
+ return cls(
+ src=src,
+ frontend=Frontend(src=src),
+ backend=Backend(src=src),
+ cli=Cli(src=src),
+ env=Env()
+ )
+
+ @function
+ def make(
+ self,
+ task: Annotated[str, Doc("The make task to run")],
+ ) -> dagger.Container:
+ """A container that runs a make task."""
+ return (
+ self.env.dev().
+ with_directory("/src", self.src).
+ with_workdir("/src").
+ with_exec(["make", "install-all"]).
+ with_exec(["make", task])
+ )