From 054ef8ea8596e3271dc43da15d43266821515a9a Mon Sep 17 00:00:00 2001 From: Daniel McCrystal Date: Sat, 29 Nov 2025 21:12:03 -0500 Subject: [PATCH] no infinite loops today --- package.json | 2 +- src/caddy.ts | 11 ++++++++--- src/deploy.ts | 4 ++-- src/scripts/rebuildCaddy.ts | 3 +++ src/scripts/reloadCaddy.ts | 3 --- 5 files changed, 14 insertions(+), 9 deletions(-) create mode 100644 src/scripts/rebuildCaddy.ts delete mode 100644 src/scripts/reloadCaddy.ts diff --git a/package.json b/package.json index a719a44..bbcbfee 100644 --- a/package.json +++ b/package.json @@ -3,7 +3,7 @@ "scripts": { "deploy-self": "bun run src/scripts/deploySelf.ts", "dev": "NODE_ENV=development PORT=6001 bun run --hot src/index.ts", - "build": "bun run src/scripts/reloadCaddy.ts", + "build": "bun run src/scripts/rebuildCaddy.ts", "start": "NODE_ENV=production bun run src/index.ts" }, "dependencies": { diff --git a/src/caddy.ts b/src/caddy.ts index 5961709..1b9be29 100644 --- a/src/caddy.ts +++ b/src/caddy.ts @@ -1,10 +1,15 @@ import fs from "fs"; import { indexedConfig, config } from "./config"; import path from "path"; +import { $ } from "bun"; -export const reloadCaddyfile = () => { - const caddyfilePath = (host: string) => - path.join(config.directory, host, "src", "Caddyfile"); +export const caddyfilePath = (host: string) => + path.join(config.directory, host, "src", "Caddyfile"); + +export const rebuildCaddyfile = async () => { + // we have to delete our own caddyfile first or we'll + // accidentally import ourselves in the new Caddyfile + await $`rm ${caddyfilePath("deployer2")}`.nothrow(); const Caddyfile = Object.values(indexedConfig) .map( diff --git a/src/deploy.ts b/src/deploy.ts index db0fc8b..1e0778c 100644 --- a/src/deploy.ts +++ b/src/deploy.ts @@ -3,7 +3,7 @@ import { $ } from "bun"; import path from "path"; import { config, indexedConfig } from "./config"; import fs from "fs"; -import { reloadCaddyfile } from "./caddy"; +import { rebuildCaddyfile } from "./caddy"; type DeployInstance = { host: string; @@ -33,7 +33,7 @@ export const deploy = async ({ host, commitHash }: DeployInstance) => { // Build await $`make build`; - reloadCaddyfile(); + rebuildCaddyfile(); // Register service const systemdServiceName = `deployer2-${host}.service`; diff --git a/src/scripts/rebuildCaddy.ts b/src/scripts/rebuildCaddy.ts new file mode 100644 index 0000000..b72c4fd --- /dev/null +++ b/src/scripts/rebuildCaddy.ts @@ -0,0 +1,3 @@ +import { rebuildCaddyfile } from "../caddy"; + +rebuildCaddyfile(); diff --git a/src/scripts/reloadCaddy.ts b/src/scripts/reloadCaddy.ts deleted file mode 100644 index eb869ca..0000000 --- a/src/scripts/reloadCaddy.ts +++ /dev/null @@ -1,3 +0,0 @@ -import { reloadCaddyfile } from "../caddy"; - -reloadCaddyfile();