diff --git a/service.template b/service.template index 5c28415..5d2ce99 100644 --- a/service.template +++ b/service.template @@ -6,7 +6,7 @@ After=network.target Type=simple Environment="PORT=$port" ExecStart=make start -User=drm +User=$user WorkingDirectory=$serviceDir/src Restart=yes StandardOutput=file:$logsDir/start.log diff --git a/src/caddy.ts b/src/caddy.ts index 3f88a83..eeb7f28 100644 --- a/src/caddy.ts +++ b/src/caddy.ts @@ -1,5 +1,5 @@ import fs from "fs"; -import { indexedConfig, config } from "./config"; +import { indexedConfig, config, isSelf } from "./config"; import path from "path"; import { $ } from "bun"; @@ -12,7 +12,7 @@ export const rebuildCaddyfile = async () => { await $`rm ${caddyfilePath("deployer2")}`.nothrow(); const Caddyfile = Object.values(indexedConfig) - .filter(({ user, repo }) => `${user}/${repo}` != "drm/deployer2") + .filter((s) => !isSelf(s)) .map( ({ host, port }) => ` ${host}.drm.dev { diff --git a/src/config.ts b/src/config.ts index 7dc3aa3..afd23a0 100644 --- a/src/config.ts +++ b/src/config.ts @@ -1,14 +1,13 @@ import userConfig from "../config"; import hash from "object-hash"; +export type DeployerService = { + user: string; + repo: string; + branch: string; +}; export type DeployerConfig = { - services: { - [host: string]: { - user: string; - repo: string; - branch: string; - }; - }; + services: { [host: string]: DeployerService }; giteaUrl: string; directory: string; basePort: number; @@ -27,3 +26,6 @@ export const indexedConfig = Object.fromEntries( }, ]) ); + +export const isSelf = ({ user, repo }: DeployerService) => + `${user}/${repo}` == "drm/deployer2"; diff --git a/src/deploy.ts b/src/deploy.ts index 1e0778c..a5be8be 100644 --- a/src/deploy.ts +++ b/src/deploy.ts @@ -1,7 +1,7 @@ import hash from "object-hash"; import { $ } from "bun"; import path from "path"; -import { config, indexedConfig } from "./config"; +import { config, indexedConfig, isSelf } from "./config"; import fs from "fs"; import { rebuildCaddyfile } from "./caddy"; @@ -47,6 +47,7 @@ export const deploy = async ({ host, commitHash }: DeployInstance) => { deploymentId, logsDir: path.join(serviceDir, "logs"), serviceDir, + user: isSelf(service) ? "root" : "drm", } ); await $`ln -sf ${serviceDir}/${systemdServiceName} ${config.systemServicesDir}/${systemdServiceName}`;