Skip to content

Commit

Permalink
Added script to procfile to purge cloudflare cache on release
Browse files Browse the repository at this point in the history
  • Loading branch information
kurtisassad committed Aug 5, 2024
1 parent 624f913 commit 64cf7ba
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 2 deletions.
2 changes: 1 addition & 1 deletion packages/commonwealth/Procfile
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@ consumer: cd packages/commonwealth && node --import=extensionless/register --max
evm-ce: cd packages/commonwealth && node --import=extensionless/register --max-old-space-size=$(../../scripts/get-max-old-space-size.sh) build/server/workers/evmChainEvents/startEvmPolling.js
knock: cd packages/commonwealth && node --import=extensionless/register --max-old-space-size=$(../../scripts/get-max-old-space-size.sh) build/server/workers/knock/knockWorker.js
message-relayer: cd packages/commonwealth && node --import=extensionless/register --max-old-space-size=$(../../scripts/get-max-old-space-size.sh) build/server/workers/messageRelayer/messageRelayer.js
release: cd packages/commonwealth && node --import=extensionless/register --max-old-space-size=$(../../scripts/get-max-old-space-size.sh) build/server/scripts/releasePhaseEnvCheck.js && npx sequelize-cli db:migrate --config server/sequelize.json
release: cd packages/commonwealth && node --import=extensionless/register --max-old-space-size=$(../../scripts/get-max-old-space-size.sh) build/server/scripts/releasePhaseEnvCheck.js && npx sequelize-cli db:migrate --config server/sequelize.json && node --import=extensionless/register build/server/scripts/purgeCloudflareCache.js
37 changes: 37 additions & 0 deletions packages/commonwealth/server/scripts/purgeCloudflareCache.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import { config } from 'dotenv';
import fetch from 'node-fetch';

config();

async function purgeCache(zoneId?: string, apiKey?: string) {
if (!zoneId || !apiKey) throw Error('Missing Env Vars');

const url = `https://api.cloudflare.com/client/v4/zones/${zoneId}/purge_cache`;
const body = {
purge_everything: true,
};
const headers = {
Authorization: `Bearer ${apiKey}`,
'Content-Type': 'application/json',
};

try {
const response = await fetch(url, {
method: 'POST',
headers: headers,
body: JSON.stringify(body),
});

const responseData = await response.json();
console.log('Cache purge request successful:');
console.log(responseData);
} catch (error) {
console.error('Error purging cache:', error.message);
}
}

purgeCache(process.env.CF_ZONE_ID, process.env.CF_API_KEY)
.then(() => console.log('finished cloudflare purge script'))
.catch((e) => {
console.log('cloudflare purge script failed:', e);
});
6 changes: 5 additions & 1 deletion packages/discord-bot/tsconfig.build.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,11 @@
"rootDir": ".",
"outDir": "build"
},
"include": ["src", "scripts/releasePhaseEnvCheck.ts"],
"include": [
"src",
"scripts/releasePhaseEnvCheck.ts",
"scripts/purgeCloudflareCache.ts"
],
"references": [
{ "path": "../../libs/adapters/tsconfig.build.json" },
{ "path": "../../libs/core/tsconfig.build.json" },
Expand Down

0 comments on commit 64cf7ba

Please sign in to comment.