diff --git a/src/deploy.ts b/src/deploy.ts index 08f7769..02cc269 100644 --- a/src/deploy.ts +++ b/src/deploy.ts @@ -15,47 +15,40 @@ export const deploy = async ({ host, commitHash }: DeployInstance) => { const deploymentId = new Date().toISOString(); const serviceDir = path.join(config.directory, host); + await $`mkdir -p ${serviceDir}`; // 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} - `; + $.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(); + + $.cwd(path.join(serviceDir, "src")); + await $`git fetch origin ${branch}`; + await $`git reset --hard origin/${branch}`; + await $`git checkout ${commitHash}`; // Build - await $` - cd ${serviceDir}/src - make build - `; + await $`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, - }); + const systemdServiceName = `deployer2-${host}.service`; + await $`cat service.template | envsubst > ${serviceDir}/${systemdServiceName}`.env( + { + host, + port: port.toString(), + repo, + branch, + commitHash, + deploymentId, + logsDir: path.join(serviceDir, "logs"), + serviceDir, + } + ); + await $`ln -sf ${serviceDir}/${systemdServiceName} ${config.systemServicesDir}/${systemdServiceName}`; // Start! - await $` - systemctl daemon-reload - systemctl restart ${systemdServiceName} - `; + await $`systemctl daemon-reload`; + await $`systemctl restart ${systemdServiceName}`; };