parent
f7c5d70740
commit
247825bdd3
8 changed files with 126 additions and 35 deletions
11
.cloudflare/README.md
Normal file
11
.cloudflare/README.md
Normal file
|
@ -0,0 +1,11 @@
|
||||||
|
We have two cloudflare workers that let us serve some assets of this repo
|
||||||
|
from Cloudflare.
|
||||||
|
|
||||||
|
* `open-source-website-assets` is used for `install.sh`
|
||||||
|
* `docs-proxy` is used for `https://zed.dev/docs`
|
||||||
|
|
||||||
|
On push to `main`, both of these (and the files they depend on) are uploaded to Cloudflare.
|
||||||
|
|
||||||
|
### Testing
|
||||||
|
|
||||||
|
You can use [wrangler](https://developers.cloudflare.com/workers/cli-wrangler/install-update) to test these workers locally, or to deploy custom versions.
|
14
.cloudflare/docs-proxy/src/worker.js
Normal file
14
.cloudflare/docs-proxy/src/worker.js
Normal file
|
@ -0,0 +1,14 @@
|
||||||
|
export default {
|
||||||
|
async fetch(request, _env, _ctx) {
|
||||||
|
const url = new URL(request.url);
|
||||||
|
url.hostname = "docs-anw.pages.dev";
|
||||||
|
|
||||||
|
let res = await fetch(url, request);
|
||||||
|
|
||||||
|
if (res.status === 404) {
|
||||||
|
res = await fetch("https://zed.dev/404");
|
||||||
|
}
|
||||||
|
|
||||||
|
return res;
|
||||||
|
},
|
||||||
|
};
|
8
.cloudflare/docs-proxy/wrangler.toml
Normal file
8
.cloudflare/docs-proxy/wrangler.toml
Normal file
|
@ -0,0 +1,8 @@
|
||||||
|
name = "docs-proxy"
|
||||||
|
main = "src/worker.js"
|
||||||
|
compatibility_date = "2024-05-03"
|
||||||
|
workers_dev = true
|
||||||
|
|
||||||
|
[[routes]]
|
||||||
|
pattern = "zed.dev/docs*"
|
||||||
|
zone_name = "zed.dev"
|
28
.cloudflare/open-source-website-assets/src/worker.js
Normal file
28
.cloudflare/open-source-website-assets/src/worker.js
Normal file
|
@ -0,0 +1,28 @@
|
||||||
|
/**
|
||||||
|
* Welcome to Cloudflare Workers! This is your first worker.
|
||||||
|
*
|
||||||
|
* - Run "npm run dev" in your terminal to start a development server
|
||||||
|
* - Open a browser tab at http://localhost:8787/ to see your worker in action
|
||||||
|
* - Run "npm run deploy" to publish your worker
|
||||||
|
*
|
||||||
|
* Learn more at https://developers.cloudflare.com/workers/
|
||||||
|
*/
|
||||||
|
export default {
|
||||||
|
async fetch(request, env) {
|
||||||
|
const url = new URL(request.url);
|
||||||
|
const key = url.pathname.slice(1).replace(/2$/, '');
|
||||||
|
|
||||||
|
const object = await env.OPEN_SOURCE_WEBSITE_ASSETS_BUCKET.get(key);
|
||||||
|
if (!object) {
|
||||||
|
return await fetch('https://zed.dev/404');
|
||||||
|
}
|
||||||
|
|
||||||
|
const headers = new Headers();
|
||||||
|
object.writeHttpMetadata(headers);
|
||||||
|
headers.set('etag', object.httpEtag);
|
||||||
|
|
||||||
|
return new Response(object.body, {
|
||||||
|
headers,
|
||||||
|
});
|
||||||
|
},
|
||||||
|
};
|
8
.cloudflare/open-source-website-assets/wrangler.toml
Normal file
8
.cloudflare/open-source-website-assets/wrangler.toml
Normal file
|
@ -0,0 +1,8 @@
|
||||||
|
name = "open-source-website-assets"
|
||||||
|
main = "src/worker.js"
|
||||||
|
compatibility_date = "2024-05-15"
|
||||||
|
workers_dev = true
|
||||||
|
|
||||||
|
[[r2_buckets]]
|
||||||
|
binding = 'OPEN_SOURCE_WEBSITE_ASSETS_BUCKET'
|
||||||
|
bucket_name = 'zed-open-source-website-assets'
|
56
.github/workflows/deploy_cloudflare.yml
vendored
Normal file
56
.github/workflows/deploy_cloudflare.yml
vendored
Normal file
|
@ -0,0 +1,56 @@
|
||||||
|
name: Deploy Docs
|
||||||
|
|
||||||
|
on:
|
||||||
|
push:
|
||||||
|
branches:
|
||||||
|
- main
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
deploy-docs:
|
||||||
|
name: Deploy Docs
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
|
||||||
|
steps:
|
||||||
|
- name: Checkout repo
|
||||||
|
uses: actions/checkout@v4
|
||||||
|
with:
|
||||||
|
clean: false
|
||||||
|
|
||||||
|
- name: Setup mdBook
|
||||||
|
uses: peaceiris/actions-mdbook@v2
|
||||||
|
with:
|
||||||
|
mdbook-version: "0.4.37"
|
||||||
|
|
||||||
|
- name: Build book
|
||||||
|
run: |
|
||||||
|
set -euo pipefail
|
||||||
|
mkdir -p target/deploy
|
||||||
|
mdbook build ./docs --dest-dir=../target/deploy/docs/
|
||||||
|
|
||||||
|
- name: Deploy Docs
|
||||||
|
uses: cloudflare/wrangler-action@v3
|
||||||
|
with:
|
||||||
|
apiToken: ${{ secrets.CLOUDFLARE_API_TOKEN }}
|
||||||
|
accountId: ${{ secrets.CLOUDFLARE_ACCOUNT_ID }}
|
||||||
|
command: pages deploy target/deploy --project-name=docs
|
||||||
|
|
||||||
|
- name: Deploy Install
|
||||||
|
uses: cloudflare/wrangler-action@v3
|
||||||
|
with:
|
||||||
|
apiToken: ${{ secrets.CLOUDFLARE_API_TOKEN }}
|
||||||
|
accountId: ${{ secrets.CLOUDFLARE_ACCOUNT_ID }}
|
||||||
|
command: r2 object put -f script/install.sh zed-open-source-website-assets/install.sh
|
||||||
|
|
||||||
|
- name: Deploy Docs Workers
|
||||||
|
uses: cloudflare/wrangler-action@v3
|
||||||
|
with:
|
||||||
|
apiToken: ${{ secrets.CLOUDFLARE_API_TOKEN }}
|
||||||
|
accountId: ${{ secrets.CLOUDFLARE_ACCOUNT_ID }}
|
||||||
|
command: deploy .cloudflare/docs-proxy/src/worker.js
|
||||||
|
|
||||||
|
- name: Deploy Install Workers
|
||||||
|
uses: cloudflare/wrangler-action@v3
|
||||||
|
with:
|
||||||
|
apiToken: ${{ secrets.CLOUDFLARE_API_TOKEN }}
|
||||||
|
accountId: ${{ secrets.CLOUDFLARE_ACCOUNT_ID }}
|
||||||
|
command: deploy .cloudflare/docs-proxy/src/worker.js
|
35
.github/workflows/deploy_docs.yml
vendored
35
.github/workflows/deploy_docs.yml
vendored
|
@ -1,35 +0,0 @@
|
||||||
name: Deploy Docs
|
|
||||||
|
|
||||||
on:
|
|
||||||
push:
|
|
||||||
branches:
|
|
||||||
- main
|
|
||||||
|
|
||||||
jobs:
|
|
||||||
deploy-docs:
|
|
||||||
name: Deploy Docs
|
|
||||||
runs-on: ubuntu-latest
|
|
||||||
|
|
||||||
steps:
|
|
||||||
- name: Checkout repo
|
|
||||||
uses: actions/checkout@v4
|
|
||||||
with:
|
|
||||||
clean: false
|
|
||||||
|
|
||||||
- name: Setup mdBook
|
|
||||||
uses: peaceiris/actions-mdbook@v2
|
|
||||||
with:
|
|
||||||
mdbook-version: "0.4.37"
|
|
||||||
|
|
||||||
- name: Build book
|
|
||||||
run: |
|
|
||||||
set -euo pipefail
|
|
||||||
mkdir -p target/deploy
|
|
||||||
mdbook build ./docs --dest-dir=../target/deploy/docs/
|
|
||||||
|
|
||||||
- name: Deploy
|
|
||||||
uses: cloudflare/wrangler-action@v3
|
|
||||||
with:
|
|
||||||
apiToken: ${{ secrets.CLOUDFLARE_API_TOKEN }}
|
|
||||||
accountId: ${{ secrets.CLOUDFLARE_ACCOUNT_ID }}
|
|
||||||
command: pages deploy target/deploy --project-name=docs
|
|
1
.gitignore
vendored
1
.gitignore
vendored
|
@ -24,3 +24,4 @@ DerivedData/
|
||||||
.venv
|
.venv
|
||||||
.blob_store
|
.blob_store
|
||||||
.vscode
|
.vscode
|
||||||
|
.wrangler
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue