From 208ef70967972be9eaad7756510a3882cb559e0e Mon Sep 17 00:00:00 2001 From: flakey5 <73616808+flakey5@users.noreply.github.com> Date: Fri, 4 Oct 2024 19:24:40 -0700 Subject: [PATCH] chore: cleanup old scripts Signed-off-by: flakey5 <73616808+flakey5@users.noreply.github.com> --- scripts/origin/README.md | 3 -- scripts/origin/cache-purge.js | 71 ----------------------------------- scripts/origin/configure.sh | 16 -------- scripts/origin/sync.sh | 16 -------- scripts/rotate-api-key.js | 6 --- 5 files changed, 112 deletions(-) delete mode 100644 scripts/origin/README.md delete mode 100644 scripts/origin/cache-purge.js delete mode 100644 scripts/origin/configure.sh delete mode 100644 scripts/origin/sync.sh delete mode 100644 scripts/rotate-api-key.js diff --git a/scripts/origin/README.md b/scripts/origin/README.md deleted file mode 100644 index 5e3f94b..0000000 --- a/scripts/origin/README.md +++ /dev/null @@ -1,3 +0,0 @@ -# `scripts/origin/` - -Scripts that are stored & ran on the origin server diff --git a/scripts/origin/cache-purge.js b/scripts/origin/cache-purge.js deleted file mode 100644 index 1672b62..0000000 --- a/scripts/origin/cache-purge.js +++ /dev/null @@ -1,71 +0,0 @@ -#!/usr/bin/env node - -/** - * Tells the worker to purge the cache for whichever paths - * just got uploaded - * Usage: aws s3 sync ... | ./cache-purge.js - */ - -const readline = require('readline'); -const path = require('path'); - -if (process.env.DIST_WORKER_API_KEY === undefined) { - console.log( - 'Skipping cache purge, no DIST_WORKER_API_KEY environment variable' - ); - return; -} - -const endpoint = - process.env.CACHE_PURGE_ENDPOINT ?? 'https://nodejs.org/_cf/cache-purge'; -const bucketName = process.argv[2]; -if (bucketName === undefined) { - console.error('Bucket name undefined'); - return; -} - -const rl = readline.createInterface({ - input: process.stdin, - output: process.stdout, - terminal: false, -}); - -const pathsToPurge = new Array(); -rl.on('line', line => { - console.log(line); - if (!line.startsWith('upload:')) { - return; - } - - // upload: dist\testing\asd.txt to s3://node-poc-dev/testing/asd.txt - const s3Path = line.substring(line.indexOf('s3://')); // s3://node-poc-dev/testing/asd.txt - const fileName = s3Path.substring(bucketName.length + 6); // testing/asd.txt - - pathsToPurge.push(fileName); - - const directoryName = path.dirname(fileName); - if ( - !['', '.', './'].includes(directoryName) && - !pathsToPurge.includes(directoryName) - ) { - pathsToPurge.push(directoryName + '/'); - } -}); -rl.on('close', () => { - fetch(endpoint, { - method: 'POST', - headers: { - 'content-type': 'application/json', - 'x-api-key': process.env.DIST_WORKER_API_KEY, - }, - body: JSON.stringify({ - paths: pathsToPurge, - }), - }).then(res => { - if (!res.ok) { - console.error(`Failed purging paths, got ${res.status}`); - return; - } - console.log(`Purged ${pathsToPurge.length} paths`); - }); -}); diff --git a/scripts/origin/configure.sh b/scripts/origin/configure.sh deleted file mode 100644 index a9bccf5..0000000 --- a/scripts/origin/configure.sh +++ /dev/null @@ -1,16 +0,0 @@ -#!/bin/bash -# Script for setting up the AWS cli for R2 - -if ! [ -x "$(command -v aws)" ]; then - echo "AWS shell (https://github.com/awslabs/aws-shell) not installed, please run 'pip install aws'" - exit 1 -fi - -echo Note: only the AWS Access Key ID and AWS Secret Access Key fields are needed -echo --------------------------------- -echo Configure staging -aws configure --profile staging -echo --------------------------------- -echo Configure prod -aws configure --profile prod -echo --------------------------------- diff --git a/scripts/origin/sync.sh b/scripts/origin/sync.sh deleted file mode 100644 index d8bd7cc..0000000 --- a/scripts/origin/sync.sh +++ /dev/null @@ -1,16 +0,0 @@ -#!/bin/bash -# Syncs the local /dist folder -> R2 bucket -# Usage: CF_ACCOUNT_TAG= ./sync.sh - -ENDPOINT=https://$CF_ACCOUNT_TAG.r2.cloudflarestorage.com -DIST=/home/dist/ - -CACHE_PURGE_PATH=$(dirname "$0")/cache-purge.js - -echo --------------------------------- -echo Syncing staging bucket -aws s3 sync $DIST s3://dist-staging/ --endpoint-url=$ENDPOINT --profile staging | $CACHE_PURGE_PATH dist-staging -echo --------------------------------- -echo Syncing prod bucket -aws s3 sync $DIST s3://dist-prod/ --endpoint-url=$ENDPOINT --profile prod | $CACHE_PURGE_PATH dist-prod -echo --------------------------------- diff --git a/scripts/rotate-api-key.js b/scripts/rotate-api-key.js deleted file mode 100644 index 9f8b9b2..0000000 --- a/scripts/rotate-api-key.js +++ /dev/null @@ -1,6 +0,0 @@ -#!/usr/bin/env node - -import { randomUUID } from 'node:crypto'; - -console.log(`New API Keey: ${randomUUID()}`); -console.log('Run `wrangler secrets put CACHE_PURGE_API_KEY -e `');