smarter caddy
This commit is contained in:
3
.vscode/settings.json
vendored
Normal file
3
.vscode/settings.json
vendored
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
{
|
||||||
|
"workbench.colorTheme": "Userscape Contrast (rainglow)"
|
||||||
|
}
|
||||||
@@ -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",
|
||||||
|
|||||||
@@ -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 { $ } 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`;
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
import { deploy } from "./deploy";
|
import { deploy } from "../deploy";
|
||||||
|
|
||||||
await deploy({
|
await deploy({
|
||||||
host: "deployer2",
|
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