From 83a6dee85de395f4da81572ad9f9674c42b997c3 Mon Sep 17 00:00:00 2001 From: flakey5 <73616808+flakey5@users.noreply.github.com> Date: Thu, 31 Aug 2023 19:37:49 -0700 Subject: [PATCH] temp --- .github/workflows/deploy-prod.yml | 16 ++++++++++ .github/workflows/deploy-staging.yml | 25 ++++++++++++++++ .github/workflows/format.yml | 23 ++++++++++++++ package.json | 6 ++-- scripts/origin/sync.sh | 2 +- scripts/rotate-api-key.js | 6 ++-- wrangler.toml | 45 +++++++++++++++++++++++++++- 7 files changed, 117 insertions(+), 6 deletions(-) create mode 100644 .github/workflows/deploy-prod.yml create mode 100644 .github/workflows/deploy-staging.yml create mode 100644 .github/workflows/format.yml diff --git a/.github/workflows/deploy-prod.yml b/.github/workflows/deploy-prod.yml new file mode 100644 index 0000000..d2d7d6e --- /dev/null +++ b/.github/workflows/deploy-prod.yml @@ -0,0 +1,16 @@ +name: Deploy worker (prod) + +on: + workflow_dispatch: + +jobs: + deploy-prod: + runs-on: ubuntu-latest + steps: + - name: Code checkout + uses: actions/checkout@v2 + - name: Deploy + uses: cloudflare/wrangler-action@v3 + with: + apiToken: ${{ secrets.CF_API_TOKEN }} + command: deploy --env prod diff --git a/.github/workflows/deploy-staging.yml b/.github/workflows/deploy-staging.yml new file mode 100644 index 0000000..bdbabfa --- /dev/null +++ b/.github/workflows/deploy-staging.yml @@ -0,0 +1,25 @@ +name: Deploy worker (staging) + +on: + workflow_run: + workflows: + - Format + branches: + - main + types: + - completed + # push: + # branches: + # - main + +jobs: + deploy-staging: + runs-on: ubuntu-latest + steps: + - name: Code checkout + uses: actions/checkout@v2 + - name: Deploy + uses: cloudflare/wrangler-action@v3 + with: + apiToken: ${{ secrets.CF_API_TOKEN }} + command: deploy --env staging diff --git a/.github/workflows/format.yml b/.github/workflows/format.yml new file mode 100644 index 0000000..5f87dd9 --- /dev/null +++ b/.github/workflows/format.yml @@ -0,0 +1,23 @@ +name: Format + +on: + push: + pull_request: + branches: [ main ] + +jobs: + format-ts: + runs-on: ubuntu-latest + steps: + - name: Code checkout + uses: actions/checkout@v2 + - name: Cache dependencies + uses: actions/cache@v2 + with: + path: ~/.npm + key: ${{ runner.os }}-npm-${{ hashFiles('**/workflows/prettier.yml') }} + restore-keys: ${{ runner.os }}-npm- + - name: Install dependencies + run: npm install + - name: Run Prettier + run: npm run check-format diff --git a/package.json b/package.json index 241a760..a8fc6b7 100644 --- a/package.json +++ b/package.json @@ -3,9 +3,11 @@ "version": "0.0.0", "private": true, "scripts": { - "deploy": "wrangler deploy", + "deploy:staging": "wrangler deploy -e staging", + "deploy:prod": "wrangler deploy -e prod", "start": "wrangler dev", - "format": "prettier -u --write \"**/*.{ts,json}\"" + "format": "prettier -u --write \"**/*.{ts,js,json}\"", + "check-format": "prettier -u --check \"**/*.{ts,js,json}\"" }, "devDependencies": { "@cloudflare/workers-types": "^4.20230419.0", diff --git a/scripts/origin/sync.sh b/scripts/origin/sync.sh index 135554d..6cece5c 100644 --- a/scripts/origin/sync.sh +++ b/scripts/origin/sync.sh @@ -5,7 +5,7 @@ ENDPOINT=https://$1.r2.cloudflarestorage.com DIST=/home/dist/ -aws s3 sync $DIST s3://node-poc-dev/ --endpoint-url=$ENDPOINT --profile staging +aws s3 sync $DIST s3://node-poc-staging/ --endpoint-url=$ENDPOINT --profile staging aws s3 sync $DIST s3://node-poc-prod/ --endpoint-url=$ENDPOINT --profile prod if [[ -v DIST_WORKER_API_KEY ]]; diff --git a/scripts/rotate-api-key.js b/scripts/rotate-api-key.js index d057460..87fb650 100644 --- a/scripts/rotate-api-key.js +++ b/scripts/rotate-api-key.js @@ -2,5 +2,7 @@ const { randomUUID } = require('crypto'); -console.log(`New api key: ${randomUUID()}`) -console.log('Now, run `wrangler secrets put PURGE_API_KEY` and enter it in the prompt.') +console.log(`New api key: ${randomUUID()}`); +console.log( + 'Now, run `wrangler secrets put PURGE_API_KEY` and enter it in the prompt.' +); diff --git a/wrangler.toml b/wrangler.toml index d592285..783b6ae 100644 --- a/wrangler.toml +++ b/wrangler.toml @@ -2,8 +2,11 @@ name = "node-dist-worker-poc" main = "src/worker.ts" compatibility_date = "2023-08-07" +# Dev (default) [vars] -DIRECTORY_LISTING = 'restricted' +workers_dev = true +ENVIRONMENT = 'dev' +DIRECTORY_LISTING = 'on' CACHE_CONTROL = 'public, max-age=3600, s-maxage=14400' DIRECTORY_CACHE_CONTROL = 'public, max-age=3600, s-maxage=14400' COMMONLY_UPDATED_PATHS = [ @@ -16,4 +19,44 @@ COMMONLY_UPDATED_PATHS = [ [[r2_buckets]] binding = "R2_BUCKET" preview_bucket_name = "node-poc-dev" +bucket_name = "node-poc-dev" + +# Staging +[env.staging] +[env.staging.vars] +workers_dev = true +ENVIRONMENT = 'staging' +DIRECTORY_LISTING = 'restricted' +CACHE_CONTROL = 'public, max-age=3600, s-maxage=14400' +DIRECTORY_CACHE_CONTROL = 'public, max-age=3600, s-maxage=14400' +COMMONLY_UPDATED_PATHS = [ + '/dist', + '/dist/', + '/dist/latest', + '/dist/latest/', +] + +[[env.staging.r2_buckets]] +binding = "R2_BUCKET" +preview_bucket_name = "node-poc-dev" +bucket_name = "node-poc-staging" + +# Prod +[env.prod] +[env.prod.vars] +workers_dev = true # for now we're using a workers.dev domain +ENVIRONMENT = 'prod' +DIRECTORY_LISTING = 'restricted' +CACHE_CONTROL = 'public, max-age=3600, s-maxage=14400' +DIRECTORY_CACHE_CONTROL = 'public, max-age=3600, s-maxage=14400' +COMMONLY_UPDATED_PATHS = [ + '/dist', + '/dist/', + '/dist/latest', + '/dist/latest/', +] + +[[env.prod.r2_buckets]] +binding = "R2_BUCKET" +preview_bucket_name = "node-poc-prod" bucket_name = "node-poc-prod"