smarter caddy

This commit is contained in:
2025-11-29 21:01:14 -05:00
parent da07ee2f40
commit 9aee30f0d1
7 changed files with 36 additions and 17 deletions

3
.vscode/settings.json vendored Normal file
View File

@@ -0,0 +1,3 @@
{
"workbench.colorTheme": "Userscape Contrast (rainglow)"
}

View File

@@ -1,10 +1,10 @@
{ {
"name": "deployer2", "name": "deployer2",
"scripts": { "scripts": {
"build": "bun run src/buildSelf.ts", "deploy-self": "bun run src/scripts/deploySelf.ts",
"dev": "NODE_ENV=development PORT=6001 bun run --hot src/index.ts", "dev": "NODE_ENV=development PORT=6001 bun run --hot src/index.ts",
"start": "NODE_ENV=production bun run src/index.ts", "build": "bun run src/scripts/reloadCaddy.ts",
"deploy-self": "bun run src/deploySelf.ts" "start": "NODE_ENV=production bun run src/index.ts"
}, },
"dependencies": { "dependencies": {
"@types/object-hash": "^3.0.6", "@types/object-hash": "^3.0.6",

View File

@@ -1,13 +0,0 @@
import fs from "fs";
import { indexedConfig } from "./config";
const Caddyfile = Object.values(indexedConfig)
.map(
({ host, port }) => `
${host}.drm.dev {
reverse_proxy localhost:${port}
}`
)
.join("\n");
fs.writeFileSync("Caddyfile", Caddyfile);

23
src/caddy.ts Normal file
View File

@@ -0,0 +1,23 @@
import fs from "fs";
import { indexedConfig, config } from "./config";
import path from "path";
export const reloadCaddyfile = () => {
const caddyfilePath = (host: string) =>
path.join(config.directory, host, "src", "Caddyfile");
const Caddyfile = Object.values(indexedConfig)
.map(
({ host, port }) => `
${host}.drm.dev {
${
fs.existsSync(caddyfilePath(host))
? `import ${caddyfilePath(host)} ` // <-- space at end important
: `reverse_proxy localhost:`
}${port}
}`
)
.join("\n");
fs.writeFileSync("Caddyfile", Caddyfile);
};

View File

@@ -2,6 +2,8 @@ import hash from "object-hash";
import { $ } from "bun"; import { $ } from "bun";
import path from "path"; import path from "path";
import { config, indexedConfig } from "./config"; import { config, indexedConfig } from "./config";
import fs from "fs";
import { reloadCaddyfile } from "./caddy";
type DeployInstance = { type DeployInstance = {
host: string; host: string;
@@ -31,6 +33,7 @@ export const deploy = async ({ host, commitHash }: DeployInstance) => {
// Build // Build
await $`make build`; await $`make build`;
reloadCaddyfile();
// Register service // Register service
const systemdServiceName = `deployer2-${host}.service`; const systemdServiceName = `deployer2-${host}.service`;

View File

@@ -1,4 +1,4 @@
import { deploy } from "./deploy"; import { deploy } from "../deploy";
await deploy({ await deploy({
host: "deployer2", host: "deployer2",

View File

@@ -0,0 +1,3 @@
import { reloadCaddyfile } from "../caddy";
reloadCaddyfile();