-
Notifications
You must be signed in to change notification settings - Fork 106
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add embed cloudflare deployment and CI (#3940)
- Loading branch information
1 parent
337f80f
commit a0ff27c
Showing
17 changed files
with
313 additions
and
22 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
embed-build: | ||
parameters: | ||
build-directory: | ||
default: 'packages/embed/build-production' | ||
type: string | ||
build-type: | ||
default: 'prod' | ||
type: string | ||
steps: | ||
- checkout | ||
- attach_workspace: | ||
at: ./ | ||
- run: | ||
name: build | ||
no_output_timeout: 60m | ||
command: | | ||
cd packages/embed | ||
npm run build:<< parameters.build-type >> | ||
- persist_to_workspace: | ||
root: ./ | ||
paths: | ||
- << parameters.build-directory >> | ||
|
||
|
||
embed-install-wrangler: | ||
steps: | ||
- run: | ||
name: install wrangler | ||
command: 'cd packages/embed && npm install @cloudflare/wrangler' | ||
|
||
|
||
embed-deploy-cloudflare: | ||
parameters: | ||
build-type: | ||
default: 'production' | ||
type: string | ||
environment: | ||
default: 'production' | ||
type: string | ||
steps: | ||
- checkout | ||
- attach_workspace: | ||
at: ./ | ||
- embed-install-wrangler | ||
- run: | ||
name: Set up workers site | ||
command: | | ||
cd packages/embed/workers-site | ||
npm i | ||
cd ../ | ||
mv build-<< parameters.build-type >> build | ||
- run: | ||
name: Deploy to Cloudflare | ||
command: | | ||
cd packages/embed | ||
npx wrangler publish --env << parameters.environment >> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
embed-init: | ||
working_directory: ~/audius-client | ||
docker: | ||
- image: circleci/node:14.18 | ||
steps: | ||
- checkout | ||
|
||
- create_concatenated_package_lock: | ||
filename: combined-package-lock.txt | ||
|
||
- create_concatenated_patch_file: | ||
filename: combined-patch-file.txt | ||
|
||
- restore_cache: | ||
keys: | ||
- cache-{{ checksum "package-lock.json" }}-{{ checksum "combined-package-lock.txt" }}-{{ checksum "combined-patch-file.txt" }} | ||
|
||
- restore_cache: | ||
keys: | ||
- cache-{{ .Revision }} | ||
|
||
- run: | ||
name: Link packages | ||
command: | | ||
npm run link | ||
- persist_to_workspace: | ||
root: ./ | ||
paths: | ||
- node_modules | ||
- packages/embed/node_modules | ||
- packages/stems/node_modules | ||
- packages/stems/dist | ||
|
||
|
||
embed-build-staging: | ||
working_directory: ~/audius-client | ||
docker: | ||
- image: circleci/node:14.18 | ||
resource_class: xlarge | ||
steps: | ||
- embed-build: | ||
build-directory: packages/embed/build-staging | ||
build-type: stage | ||
|
||
|
||
embed-build-production: | ||
working_directory: ~/audius-client | ||
docker: | ||
- image: circleci/node:14.18 | ||
resource_class: xlarge | ||
steps: | ||
- embed-build: | ||
build-directory: packages/embed/build-production | ||
build-type: prod | ||
|
||
|
||
embed-deploy-staging-cloudflare: | ||
working_directory: ~/audius-client | ||
docker: | ||
- image: cimg/python:3.7.12-node | ||
steps: | ||
- embed-deploy-cloudflare: | ||
build-type: staging | ||
environment: staging | ||
|
||
|
||
embed-deploy-production-cloudflare: | ||
working_directory: ~/audius-client | ||
docker: | ||
- image: cimg/python:3.7.12-node | ||
steps: | ||
- embed-deploy-cloudflare: | ||
build-type: production | ||
environment: production |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
when: << pipeline.parameters.run-embed-workflow >> | ||
jobs: | ||
- embed-init | ||
- embed-build-staging: | ||
requires: | ||
- embed-init | ||
filters: | ||
branches: | ||
only: /^main$/ | ||
- embed-deploy-staging-cloudflare: | ||
context: Audius Client | ||
requires: | ||
- embed-build-staging | ||
filters: | ||
branches: | ||
only: /^main$/ | ||
- embed-build-production: | ||
requires: | ||
- embed-init | ||
filters: | ||
branches: | ||
only: /(^release.*)$/ | ||
- embed-deploy-production-cloudflare: | ||
context: Audius Client | ||
requires: | ||
- embed-build-production | ||
filters: | ||
branches: | ||
only: /(^release.*)$/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,6 @@ | ||
**/node_modules/* | ||
**/assets/* | ||
build/* | ||
dist/* | ||
build-staging/* | ||
build-production/* |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,8 @@ | ||
node_modules | ||
/build | ||
/*.log | ||
.DS_Store | ||
/*.DS_Store | ||
/*.DS_Store | ||
build | ||
dist | ||
build-staging | ||
build-production |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
import { getAssetFromKV, mapRequestToAsset } from '@cloudflare/kv-asset-handler' | ||
|
||
const DEBUG = false | ||
|
||
addEventListener('fetch', (event) => { | ||
try { | ||
event.respondWith(handleEvent(event)) | ||
} catch (e) { | ||
if (DEBUG) { | ||
return event.respondWith( | ||
new Response(e.message || e.toString(), { | ||
status: 500 | ||
}) | ||
) | ||
} | ||
event.respondWith(new Response('Internal Error', { status: 500 })) | ||
} | ||
}) | ||
|
||
async function handleEvent(event) { | ||
const options = {} | ||
|
||
// Always map requests to `/` since this is an SPA | ||
options.mapRequestToAsset = (request) => { | ||
const cleanedUrl = request.url.replace('/embed/', '/') | ||
const req = mapRequestToAsset(new Request(cleanedUrl, request)) | ||
const url = new URL(req.url) | ||
|
||
if (url.pathname.endsWith('.html')) { | ||
return new Request(`${url.origin}/index.html`, req) | ||
} | ||
return req | ||
} | ||
try { | ||
if (DEBUG) { | ||
// customize caching | ||
options.cacheControl = { | ||
bypassCache: true | ||
} | ||
} | ||
|
||
const page = await getAssetFromKV(event, options) | ||
|
||
// allow headers to be altered | ||
const response = new Response(page.body, page) | ||
|
||
response.headers.set('Access-Control-Allow-Origin', '*') | ||
response.headers.set('X-XSS-Protection', '1; mode=block') | ||
response.headers.set('X-Content-Type-Options', 'nosniff') | ||
response.headers.set('X-Frame-Options', 'DENY') | ||
response.headers.set('Referrer-Policy', 'unsafe-url') | ||
response.headers.set('Feature-Policy', 'none') | ||
|
||
return response | ||
} catch (e) { | ||
return new Response(e.message || e.toString(), { status: 500 }) | ||
} | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
{ | ||
"private": true, | ||
"version": "1.0.0", | ||
"main": "index.js", | ||
"license": "MIT", | ||
"dependencies": { | ||
"@cloudflare/kv-asset-handler": "~0.0.11" | ||
} | ||
} |
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
type = "webpack" | ||
account_id = "3811365464a8e56b2b27a5590e328e49" | ||
workers_dev = true | ||
|
||
[site] | ||
bucket = "./build" | ||
entry-point = "workers-site" | ||
|
||
[env.staging] | ||
name = "embed-staging" | ||
route = "embed.staging.audius.co/*" | ||
|
||
[env.production] | ||
name = "embed" | ||
route = "embed.audius.co/*" |
Oops, something went wrong.