From 85b1953b46e1d8b88b151d84d4a8dd1ad3a51e7e Mon Sep 17 00:00:00 2001 From: Daniel McCrystal Date: Sat, 29 Nov 2025 15:46:07 -0500 Subject: [PATCH] deploy self --- .gitignore | 1 + Makefile | 4 ++-- package.json | 1 + src/buildSelf.ts | 13 +++++++++++++ src/deploy.ts | 19 ++++++------------- src/deploySelf.ts | 6 ++++++ src/index.ts | 2 +- 7 files changed, 30 insertions(+), 16 deletions(-) create mode 100644 src/buildSelf.ts create mode 100644 src/deploySelf.ts diff --git a/.gitignore b/.gitignore index a249393..be7a71c 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,5 @@ /config.ts +/Caddyfile # ---> Node # Logs diff --git a/Makefile b/Makefile index 79c5220..5c94c9b 100644 --- a/Makefile +++ b/Makefile @@ -1,6 +1,6 @@ build: - echo nothing to build! - + pnpm run build + start: pnpm start \ No newline at end of file diff --git a/package.json b/package.json index e05ecfc..957dee5 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,7 @@ { "name": "deployer2", "scripts": { + "build": "bun run src/buildSelf.ts", "dev": "NODE_ENV=development PORT=6001 bun run --hot src/index.ts", "start": "NODE_ENV=production bun run src/index.ts" }, diff --git a/src/buildSelf.ts b/src/buildSelf.ts new file mode 100644 index 0000000..8b99ddd --- /dev/null +++ b/src/buildSelf.ts @@ -0,0 +1,13 @@ +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); diff --git a/src/deploy.ts b/src/deploy.ts index 1626f81..08f7769 100644 --- a/src/deploy.ts +++ b/src/deploy.ts @@ -1,24 +1,17 @@ +import hash from "object-hash"; import { $ } from "bun"; import path from "path"; -import { config } from "./config"; +import { config, indexedConfig } from "./config"; type DeployInstance = { host: string; - user: string; - repo: string; - branch: string; commitHash: string; - port: number; }; -export const deploy = async ({ - host, - user, - repo, - branch, - port, - commitHash, -}: DeployInstance) => { +export const deploy = async ({ host, commitHash }: DeployInstance) => { + const service = config.services[host]; + const { user, repo, branch, port } = indexedConfig[hash(service)]; + const deploymentId = new Date().toISOString(); const serviceDir = path.join(config.directory, host); diff --git a/src/deploySelf.ts b/src/deploySelf.ts new file mode 100644 index 0000000..dd7d0ac --- /dev/null +++ b/src/deploySelf.ts @@ -0,0 +1,6 @@ +import { deploy } from "./deploy"; + +await deploy({ + host: "deployer2", + commitHash: "", +}); diff --git a/src/index.ts b/src/index.ts index 06c5be6..9a64b73 100644 --- a/src/index.ts +++ b/src/index.ts @@ -34,7 +34,7 @@ new Elysia() return; } - void deploy({ ...service, commitHash }); + void deploy({ host: service.host, commitHash }); return "deploying"; }) .listen(port);