Skip to content

Migrate docs site from Netlify to Cloudflare Workers#14025

Merged
matthewp merged 29 commits into
mainfrom
migrate-cloudflare-2
Jun 12, 2026
Merged

Migrate docs site from Netlify to Cloudflare Workers#14025
matthewp merged 29 commits into
mainfrom
migrate-cloudflare-2

Conversation

@matthewp

@matthewp matthewp commented Jun 9, 2026

Copy link
Copy Markdown
Contributor

Migrates the Astro docs site from Netlify to Cloudflare Workers.

Changes

  • Replace Netlify build script with wrangler deploy
  • Update preview site URL to use Workers CI branch previews
  • Add wrangler.jsonc configuration for static asset serving
  • Add .assetsignore to exclude _worker.js and _routes.json from assets
  • Update .gitignore to ignore .wrangler instead of .netlify
  • Add wrangler as a dev dependency
  • Allow workerd build script in pnpm-workspace.yaml
  • Add GitHub Actions deploy workflow with preview URLs

matthewp added 10 commits June 9, 2026 08:49
- Replace Netlify build script with wrangler deploy
- Update preview site URL to use Workers CI branch previews
- Add wrangler.jsonc configuration for static asset serving
- Add .assetsignore to exclude _worker.js and _routes.json
- Update .gitignore to ignore .wrangler instead of .netlify
- Add wrangler as a dev dependency
- Production: wrangler deploy on push to main
- PRs: wrangler versions upload with branch-name alias
- Comments preview URL on PRs
- Enable preview_urls in wrangler config
@github-actions

github-actions Bot commented Jun 9, 2026

Copy link
Copy Markdown

Preview deployment

✅ Deployment complete!

https://migrate-cloudflare-2.previews.docs.astro.build

@netlify

netlify Bot commented Jun 9, 2026

Copy link
Copy Markdown

Deploy Preview for astro-docs-2 failed. Why did it fail? →

Name Link
🔨 Latest commit 116d5df
🔍 Latest deploy log https://app.netlify.com/projects/astro-docs-2/deploys/6a2822c990a4f20008240d90

@netlify

netlify Bot commented Jun 9, 2026

Copy link
Copy Markdown

Deploy Preview for astro-docs-2 failed. Why did it fail? →

Name Link
🔨 Latest commit 929a755
🔍 Latest deploy log https://app.netlify.com/projects/astro-docs-2/deploys/6a2822fdcb672f0008c83177

@netlify

netlify Bot commented Jun 9, 2026

Copy link
Copy Markdown

Deploy Preview for astro-docs-2 failed. Why did it fail? →

Name Link
🔨 Latest commit d2566f6
🔍 Latest deploy log https://app.netlify.com/projects/astro-docs-2/deploys/6a2823506a1d07000816fcf9

@netlify

netlify Bot commented Jun 9, 2026

Copy link
Copy Markdown

Deploy Preview for astro-docs-2 failed. Why did it fail? →

Name Link
🔨 Latest commit b78e7f2
🔍 Latest deploy log https://app.netlify.com/projects/astro-docs-2/deploys/6a2c448bf2dc2500088144f3

matthewp added 7 commits June 9, 2026 11:20
astro-og-canvas caches rendered images in node_modules/.astro-og-canvas.
Without caching this directory, every build regenerates thousands of
OG images (~300ms each), adding ~10 minutes to the build.
…4 Worker

- Remove .assetsignore (only needed for SSR sites)
- Remove deploy script from package.json (CI calls wrangler directly)
- Remove observability from wrangler.jsonc (static site)
- Add worker.js for serving localized 404 pages
- Remove commented-out 404 redirect from _redirects
@matthewp

matthewp commented Jun 9, 2026

Copy link
Copy Markdown
Contributor Author

@matthewp matthewp marked this pull request as ready for review June 9, 2026 18:41

@delucis delucis left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Some early feedback!

Comment thread .github/workflows/deploy.yml Outdated
Comment on lines +95 to +115
- name: Comment deployment complete
if: github.event_name == 'pull_request'
uses: actions/github-script@60a0d83039c74a4aee543508d2ffcb1c3799cdea # v7.0.1
with:
script: |
const previewUrl = '${{ steps.preview-url.outputs.url }}';
const body = `**Preview deployment**\n\n✅ Deployment complete!\n\n${previewUrl}`;
const { data: comments } = await github.rest.issues.listComments({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: context.issue.number,
});
const existing = comments.find(c => c.body.includes('**Preview deployment**'));
if (existing) {
await github.rest.issues.updateComment({
owner: context.repo.owner,
repo: context.repo.repo,
comment_id: existing.id,
body,
});
}

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This won’t work for PRs from forks will it? They aren’t allowed the issues.write permission (otherwise a fork could open a PR and delete all our issues/PRs for example).

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

No, forks get downgraded permissions and don't have access to secrets. We're not using pull_request_target. Still, I added a gate so that these parts don't run on forks. The build will still run be there isn't a preview release.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Right, but we need deploy previews and comments for forks, many of our contributors use forks and we rely on being able to easily check their changes.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Ok, I think I have a good solution for this:

  1. In the pull request it doesn't do a deployment, it just builds and uploads the artifact.
  2. A separate workflow runs in the context of main and is triggered by the Deploy workflow finishing. This has access to secrets since it runs from the main repo, not the fork, it downloads the artifacts, deploys the preview, and adds the comment.

Comment thread .github/workflows/deploy.yml Outdated
Comment thread pnpm-workspace.yaml Outdated
Comment thread worker.js
matthewp added 4 commits June 11, 2026 16:12
- Replace manual wrangler commands with cloudflare/wrangler-action@v3
- Add JSDoc comment to worker.js explaining localized 404 behavior
- Addresses review feedback from delucis
Split preview deployment into a separate workflow_run-triggered workflow
so fork PRs get deploy previews without exposing secrets.

- deploy.yml: builds for all PRs, uploads build output + PR metadata as
  artifacts, only uses secrets for production deploys on main
- deploy-preview.yml: triggered by workflow_run, downloads artifacts,
  deploys preview to Cloudflare, and comments on the PR with write
  permissions from the base repo context

Fork code never executes with access to secrets. The workflow_run job
only deploys pre-built static artifacts.

Also pins cloudflare/wrangler-action to exact commit SHA.

@delucis delucis left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This seems like a smart way to do it!

Do you think we could test the workflow somehow before merging? Or are we at the mercy of merging to main to figure out if it works? The code looks fine to me though.

Left some feedback, but getting the comment template tuned just as we want it doesn’t have to be blocking, I don’t think.

I’d encourage @withastro/maintainers-docs to take a look too as they might be even more directly impacted than me.

Comment thread .github/workflows/deploy.yml
Comment thread .github/workflows/deploy-preview.yml
Comment thread .github/workflows/deploy-preview.yml Outdated
Comment thread .github/workflows/deploy-preview.yml Outdated
Comment thread .github/workflows/deploy-preview.yml Outdated
- Add comment explaining ALIAS subdomain sanitization
- Add concurrency control to prevent race conditions between preview runs
- Check comment author (github-actions[bot]) before updating PR comments
- Include commit SHA, preview URL, and workflow run link in all PR comments

@ArmandPhilippot ArmandPhilippot left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Well, I come after the battle... this seems good to me! Great job to both of you! 🙌🏽

I left a question on the deploy workflow. IIUC, I think we need to add v7 there (and remove that once released).

Comment thread .github/workflows/deploy.yml Outdated
matthewp added 2 commits June 12, 2026 13:37
Trigger the deploy workflow on pushes to version branches and allow
deploys from those refs. Each version branch will need its own
wrangler.jsonc with a unique Worker name (cherry-picked after merge).
@matthewp matthewp merged commit 61f4b8f into main Jun 12, 2026
9 of 13 checks passed
@matthewp matthewp deleted the migrate-cloudflare-2 branch June 12, 2026 18:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants