first pass

This commit is contained in:
2025-11-29 14:50:33 -05:00
parent cf3015638a
commit 0bfab0bdc8
10 changed files with 631 additions and 0 deletions

68
src/deploy.ts Normal file
View File

@@ -0,0 +1,68 @@
import { $ } from "bun";
import path from "path";
import { config } 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) => {
const deploymentId = new Date().toISOString();
const serviceDir = path.join(config.directory, host);
// Fetch
await $`
cd ${serviceDir}
mkdir -p src
mkdir -p logs
git clone \
-b ${branch} \
http://deployer:${config.token}@${config.giteaUrl}/${user}/${repo} \
${serviceDir}/src
cd src
git fetch origin ${branch}
git reset --hard origin/${branch}
git checkout ${commitHash}
`;
// Build
await $`
cd ${serviceDir}/src
make build
`;
// Register service
const systemdServiceName = `deployer-${host}.service`;
await $`
cat template.service | envsubst > ${serviceDir}/${systemdServiceName}
ln -sf ${serviceDir}/${systemdServiceName} ${config.systemServicesDir}/${systemdServiceName}
`.env({
host,
port: port.toString(),
repo,
branch,
commitHash,
deploymentId,
logsDir: path.join(serviceDir, "logs"),
serviceDir,
});
// Start!
await $`
systemctl daemon-reload
systemctl restart ${systemdServiceName}
`;
};