Skip to content

feat: add Docker deployment adapter - #195

Open
rturnq wants to merge 3 commits into
mainfrom
claude/docker-adapter
Open

feat: add Docker deployment adapter#195
rturnq wants to merge 3 commits into
mainfrom
claude/docker-adapter

Conversation

@rturnq

@rturnq rturnq commented Jul 1, 2026

Copy link
Copy Markdown
Contributor

Description

Adds a new adapter package, @marko/run-adapter-docker, for deploying Marko Run apps as a container image.

  • Builds a self-contained Node.js server (dist/index.mjs) with all dependencies bundled (noExternal: true), so the image needs no node_modules install. The server handles the app's routes and serves the static assets in dist/public, listening on the PORT environment variable (default 3000).
  • Generates a Dockerfile and .dockerignore in the project root during marko-run build. Both are only written when they don't already exist, so you can freely customize them (delete a file to have it regenerated).
  • The base image is configurable via the baseImage option (default node:20-alpine).
  • Reuses the base adapter's dev/preview, so marko-run preview runs the built server directly — the resulting image runs anywhere containers do (Fly.io, Railway, Render, Cloud Run, ECS/Fargate, Kubernetes, …).
marko-run build
docker build -t my-app .
docker run -p 3000:3000 my-app

Route handlers receive the underlying Node request/response via the exported DockerPlatformInfo type.

Also adds a test fixture to the @marko/run package (docker-adapter) covering both dev and preview — because the output runs on plain Node, the preview test actually builds and runs the server and drives it with Playwright.

Motivation and Context

Containers are the most portable deployment target — a single image covers Fly.io, Railway, Render, Cloud Run, ECS/Fargate, Kubernetes, and self-hosting — but Marko Run had no first-class story for it. This bundles the server so the image is small and dependency-free, and generates a working Dockerfile so deploying is a two-command flow.

Screenshots (if appropriate):

Checklist:

  • I have updated/added documentation affected by my changes.
  • I have added tests to cover my changes.

Generated by Claude Code

Add @marko/run-adapter-docker for deploying Marko Run apps as a container.

- Builds a self-contained Node.js server (dist/index.mjs) with all
  dependencies bundled (noExternal), so the image needs no node_modules
  install; the server handles routes and serves static assets from
  dist/public, listening on PORT
- Generates a Dockerfile and .dockerignore in the project root (only when
  absent, so user edits are preserved); base image configurable via the
  `baseImage` option
- Reuses the base adapter's dev/preview so `marko-run preview` runs the
  built server directly
- Adds a run-package fixture covering both dev and preview
@changeset-bot

changeset-bot Bot commented Jul 1, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: c1b5151

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
@marko/run-adapter-docker Minor

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@coderabbitai

coderabbitai Bot commented Jul 1, 2026

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: c49dfab6-46e6-4f21-bc3b-8822647e322b

📥 Commits

Reviewing files that changed from the base of the PR and between 3da58ce and c1b5151.

📒 Files selected for processing (4)
  • packages/adapters/docker/README.md
  • packages/adapters/docker/package.toggle.json
  • packages/adapters/docker/scripts/importMetaURL.js
  • packages/adapters/docker/src/index.ts
✅ Files skipped from review due to trivial changes (1)
  • packages/adapters/docker/README.md
🚧 Files skipped from review as they are similar to previous changes (2)
  • packages/adapters/docker/scripts/importMetaURL.js
  • packages/adapters/docker/src/index.ts

Walkthrough

This pull request adds a new @marko/run-adapter-docker package for building containerized Node.js servers for @marko/run applications. The adapter generates a Dockerfile and .dockerignore when absent, exposes a DockerPlatformInfo type for route handlers, and includes an Options interface for configuring the base image. Supporting additions include package metadata and resolution entries, build tooling, tsconfig, README documentation, a Changesets entry declaring a minor release, and a new docker-adapter test fixture with Vite config, a page/component, generated route typings, and a test script that clicks a counter button.

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly summarizes the main change: adding a Docker deployment adapter.
Description check ✅ Passed The description is directly related to the new Docker adapter, its build output, docs, and tests.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch claude/docker-adapter

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 2

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@packages/adapters/docker/package.json`:
- Around line 16-22: The package entrypoints in the Docker adapter still point
to src/index.ts, but only dist is published, so update the package.json exports
and types for `@marko/run-adapter-docker` to reference the built dist outputs
instead. Adjust the package entry configuration so the main export resolves to
dist/index.mjs and dist/index.cjs, and the type declaration points to
dist/index.d.ts, using the existing exports and types fields as the place to fix
it.

In `@packages/adapters/docker/src/index.ts`:
- Around line 41-52: Normalize the Docker path fragments in the Docker adapter
so generated Dockerfile contents always use POSIX separators. In the
Dockerfile/template logic used by dockerfile(), dockerignore(), and the COPY/CMD
path construction, convert relDist from path.relative to forward-slash form
before interpolating it, and avoid mixing it with path.posix.join on Windows.
Ensure the generated COPY and CMD paths are built from the normalized value so
Dockerfile parsing works consistently across platforms.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 85780caa-7207-4c4b-a6b1-d029f45d344b

📥 Commits

Reviewing files that changed from the base of the PR and between 779776f and 3da58ce.

⛔ Files ignored due to path filters (3)
  • package-lock.json is excluded by !**/package-lock.json and included by **
  • packages/run/src/__tests__/fixtures/docker-adapter/__snapshots__/dev.expected.md is excluded by !**/__snapshots__/** and included by **
  • packages/run/src/__tests__/fixtures/docker-adapter/__snapshots__/preview.expected.md is excluded by !**/__snapshots__/** and included by **
📒 Files selected for processing (16)
  • .changeset/docker-adapter.md
  • packages/adapters/docker/README.md
  • packages/adapters/docker/package.json
  • packages/adapters/docker/scripts/build.ts
  • packages/adapters/docker/scripts/importMetaURL.js
  • packages/adapters/docker/src/index.ts
  • packages/adapters/docker/src/types.ts
  • packages/adapters/docker/tsconfig.json
  • packages/run/src/__tests__/fixtures/docker-adapter/.gitignore
  • packages/run/src/__tests__/fixtures/docker-adapter/.marko-run/routes.d.ts
  • packages/run/src/__tests__/fixtures/docker-adapter/package.json
  • packages/run/src/__tests__/fixtures/docker-adapter/src/components/counter.marko
  • packages/run/src/__tests__/fixtures/docker-adapter/src/routes/+page.marko
  • packages/run/src/__tests__/fixtures/docker-adapter/test.config.ts
  • packages/run/src/__tests__/fixtures/docker-adapter/tsconfig.json
  • packages/run/src/__tests__/fixtures/docker-adapter/vite.config.ts

Comment thread packages/adapters/docker/package.json
Comment thread packages/adapters/docker/src/index.ts
rturnq added 2 commits July 1, 2026 05:00
- Add package.toggle.json so publish points exports/types at dist/
- Make the injected import.meta.url shim a string (.href) for the CJS build
- Normalize the generated Dockerfile paths to POSIX separators so the
  Dockerfile is valid when the build runs on Windows
Clarify that Marko Run automatically uses an installed adapter with no
Vite config, and put the `npm run build` + docker build/run steps in a
Deploying section right after installation.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant