smarter caddy
This commit is contained in:
@@ -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
23
src/caddy.ts
Normal 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);
|
||||
};
|
||||
@@ -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`;
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { deploy } from "./deploy";
|
||||
import { deploy } from "../deploy";
|
||||
|
||||
await deploy({
|
||||
host: "deployer2",
|
||||
3
src/scripts/reloadCaddy.ts
Normal file
3
src/scripts/reloadCaddy.ts
Normal file
@@ -0,0 +1,3 @@
|
||||
import { reloadCaddyfile } from "../caddy";
|
||||
|
||||
reloadCaddyfile();
|
||||
Reference in New Issue
Block a user