From 4d2a156f0b1d869d5d3acb5593341ac302457067 Mon Sep 17 00:00:00 2001 From: Daniel McCrystal Date: Sat, 29 Nov 2025 22:46:28 -0500 Subject: [PATCH] logging commands --- .gitignore | 1 + src/deploy.ts | 31 +++++++++++++++++-------------- src/utils.ts | 13 +++++++++++++ 3 files changed, 31 insertions(+), 14 deletions(-) create mode 100644 src/utils.ts diff --git a/.gitignore b/.gitignore index be7a71c..148e261 100644 --- a/.gitignore +++ b/.gitignore @@ -1,5 +1,6 @@ /config.ts /Caddyfile +/live # ---> Node # Logs diff --git a/src/deploy.ts b/src/deploy.ts index 3c76cb0..3ac7e68 100644 --- a/src/deploy.ts +++ b/src/deploy.ts @@ -4,6 +4,7 @@ import path from "path"; import { config, indexedConfig, isSelf } from "./config"; import fs from "fs"; import { rebuildCaddyfile } from "./caddy"; +import { l$ } from "./utils"; type DeployInstance = { host: string; @@ -11,33 +12,35 @@ type DeployInstance = { }; export const deploy = async ({ host, commitHash }: DeployInstance) => { + const deploymentId = new Date().toISOString(); + console.log(`=== ${deploymentId} ===`); + console.log({ host, commitHash }); + 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); - await $`mkdir -p ${serviceDir}`; + await l$`mkdir -p ${serviceDir}`; // Fetch $.cwd(serviceDir); const url = `http://deployer:${config.token}@${config.giteaUrl}/${user}/${repo}`; - await $`mkdir -p src`; - await $`mkdir -p logs`; - await $`git clone -b ${branch} ${url} ./src`.nothrow(); + await l$`mkdir -p src`; + await l$`mkdir -p logs`; + await $`git clone -b ${branch} ${url} ./src`.nothrow(); // explicitly don't log token $.cwd(path.join(serviceDir, "src")); - await $`git fetch origin ${branch}`; - await $`git reset --hard origin/${branch}`; - commitHash && (await $`git checkout ${commitHash}`); + await l$`git fetch origin ${branch}`; + commitHash && (await l$`git reset --hard origin/${branch}`); + commitHash && (await l$`git checkout ${commitHash}`); // Build - await $`make build`; + await l$`make build`; rebuildCaddyfile(); // Register service const systemdServiceName = `deployer2-${host}.service`; - await $`cat service.template | envsubst > ${serviceDir}/${systemdServiceName}`.env( + await l$`cat service.template | envsubst > ${serviceDir}/${systemdServiceName}`.env( { host, port: port.toString(), @@ -50,9 +53,9 @@ export const deploy = async ({ host, commitHash }: DeployInstance) => { user: isSelf(service) ? "root" : "drm", } ); - await $`ln -sf ${serviceDir}/${systemdServiceName} ${config.systemServicesDir}/${systemdServiceName}`; + await l$`ln -sf ${serviceDir}/${systemdServiceName} ${config.systemServicesDir}/${systemdServiceName}`; // Start! - await $`systemctl daemon-reload`; - await $`systemctl restart ${systemdServiceName}`; + await l$`systemctl daemon-reload`; + await l$`systemctl restart ${systemdServiceName}`; }; diff --git a/src/utils.ts b/src/utils.ts new file mode 100644 index 0000000..b54cd06 --- /dev/null +++ b/src/utils.ts @@ -0,0 +1,13 @@ +import { $ } from "bun"; + +export const l$ = (strings: TemplateStringsArray, ...values: any[]) => { + // Interleave the static strings with the evaluated values + const cmd = strings.reduce((acc, str, i) => { + const val = values[i - 1]; + return acc + (i > 0 ? $.escape(val) : "") + str; + }); + + console.log(`> ${cmd.trim()}`); + + return $(strings, ...values); +};