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

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

View File

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

View File

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