diff --git a/README.md b/README.md index 25d27c7..c256f96 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,4 @@ -# Cloudflare Workers AI Demo +# Cloudflare Workers AI deployed with Pulumi The app displays a random quote and a text-to-image AI background representative of such. @@ -6,36 +6,36 @@ The app displays a random quote and a text-to-image AI background representative ## Overview -- [App code](./app/) -- [Infra code](./infra/) +- [App Dev code -- Single Worker](./app/) +- [App Prod code -- Multiple Workers](./app=prod/) +- [Infra Test+Prod code](./infra/) ## Pre-reqs -### Local development +- npm +- Pulumi CLI +- Wrangler +- Pulumi Cloud account +- Cloudflare account with a Zone configured. -- Use the Wrangler CLI via Makefile +### Local development (Wrangler) -```bash -cd app -npx wrangler kv:namespace create "KV" -# ensure to update wrangler.toml +- Use the Wrangler CLI to test the Worker -# KV_NS_ID=$( npx wrangler kv:namespace list | jq '.[] | select(.title == "kv-wrangler") | .id' -r ) -KV_NS_ID=3dfdfc3f927c4698a3fbac85363eb419 -npx wrangler kv:key put '1' 'one I uno un' --namespace-id="${KV_NS_ID}" -npx wrangler kv:key put '2' 'two II dos deux' --namespace-id="${KV_NS_ID}" -npx wrangler kv:key put '3' 'three III tres trois' --namespace-id="${KV_NS_ID}" -npx wrangler kv:key put 'count' '3' --namespace-id="${KV_NS_ID}" +### Testing (Pulumi) +- Using the `test` Pulumi stack to incrementally add the Cloudflare Resources. +- Uses a sample size for the data +- Adds a `DEMO` flag to the Cloudflare resources +- Triggered manually via `pulumi up` commands +- Stores all secrets + config in Pulumi ESC +- Running under [`quote-demo.atxyall.com`](https://quote-demo.atxyall.com/) -# TODO -``` +### Production (GitHub Actions + Pulumi) -### E2E Testing && Production - -#### Infra code - -- Use Pulumi and CI/CD to adhere to GitOps best practices - -```bash -``` +- Uses GitHub Actions + - preview prod on GitHub commit to a PR against main + - update prod on GitHub merge to the main branch +- Uses GitHub OIDC to auth against Pulumi Cloud +- Uses the full prod size data, 2400+ CSV Entries +- Running under [`quote.atxyall.com`](https://quote.atxyall.com/) diff --git a/app/Makefile b/app/Makefile deleted file mode 100644 index a77b400..0000000 --- a/app/Makefile +++ /dev/null @@ -1,35 +0,0 @@ -# Makefile for deploying a Cloudflare Worker using Wrangler - -WRANGLER = npx wrangler -JSON_FILE = wrangler.json - -.PHONY: all -all: deploy - -.PHONY: deploy -deploy: createjson - $(WRANGLER) deploy --experimental-json-config --outdir ./dist --latest --compatibility-date "2024-03-01" > deploy.log - -.PHONY: createjson -createjson: - @echo '{' > $(JSON_FILE) - @echo ' "name": "$(NAME)",' >> $(JSON_FILE) - @echo ' "main": "./src/worker.ts",' >> $(JSON_FILE) - @echo ' "minify": true,' >> $(JSON_FILE) - @echo ' "ai": {"binding": "AI"},' >> $(JSON_FILE) - @echo ' "kv_namespaces": [{' >> $(JSON_FILE) - @echo ' "binding": "KV",' >> $(JSON_FILE) - @echo ' "id": "$(KV_ID)"' >> $(JSON_FILE) - @echo ' }],' >> $(JSON_FILE) - @echo ' "workers_dev": false,' >> $(JSON_FILE) - @echo ' "route": {' >> $(JSON_FILE) - @echo ' "pattern": "$(NAME).atxyall.com",' >> $(JSON_FILE) - @echo ' "custom_domain": true' >> $(JSON_FILE) - @echo ' }' >> $(JSON_FILE) - @echo '}' >> $(JSON_FILE) - @cat $(JSON_FILE) | jq > /dev/null || (echo "Error: JSON file is not valid" && exit 1) - - -.PHONY: delete -delete: - $(WRANGLER) delete --experimental-json-config > /dev/null || exit 0 diff --git a/app/deploy.log b/app/deploy.log deleted file mode 100644 index 7f03407..0000000 --- a/app/deploy.log +++ /dev/null @@ -1,16 +0,0 @@ - ⛅️ wrangler 3.59.0 -------------------- -Total Upload: 2.68 KiB / gzip: 1.23 KiB -Your worker has access to the following bindings: -- KV Namespaces: - - KV: f27b40e29cee49eab03b9c8046c5615a -- AI: - - Name: AI -Uploaded quote (1.55 sec) -Published quote (1.18 sec) - quote.atxyall.com (custom domain) -Current Deployment ID: 9277a0f9-228b-4ab1-b4a2-b5b06d38900a -Current Version ID: 9277a0f9-228b-4ab1-b4a2-b5b06d38900a - - -Note: Deployment ID has been renamed to Version ID. Deployment ID is present to maintain compatibility with the previous behavior of this command. This output will change in a future version of Wrangler. To learn more visit: https://developers.cloudflare.com/workers/configuration/versions-and-deployments diff --git a/app/wrangler.json b/app/wrangler.json deleted file mode 100644 index 3fd4b0e..0000000 --- a/app/wrangler.json +++ /dev/null @@ -1,15 +0,0 @@ -{ - "name": "quote", - "main": "./src/worker.ts", - "minify": true, - "ai": {"binding": "AI"}, - "kv_namespaces": [{ - "binding": "KV", - "id": "f27b40e29cee49eab03b9c8046c5615a" - }], - "workers_dev": false, - "route": { - "pattern": "quote.atxyall.com", - "custom_domain": true - } -}