From 19bb4ec4d4b3eec8b92549b5f8e295f858f0dbb1 Mon Sep 17 00:00:00 2001 From: jtricerolph Date: Tue, 14 Jul 2026 16:01:38 +0000 Subject: [PATCH] Fix deploy: auto-recover missing .git + suppress SSH known_hosts error When the deploy directory has no .git (e.g. after push_dir stripped it), re-clone via HTTPS preserving the existing .env, then continue with the normal pull + up flow. Also sets GIT_SSH_COMMAND on all git calls so the inner Forgejo SSH connection uses UserKnownHostsFile=/dev/null instead of trying to write to /root/.ssh/known_hosts. Co-Authored-By: Claude Sonnet 4.6 --- updater/src/index.js | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/updater/src/index.js b/updater/src/index.js index 742dc51..8fbaaaa 100644 --- a/updater/src/index.js +++ b/updater/src/index.js @@ -224,7 +224,21 @@ async function runRemote(target, repoName, cmd, label) { async function deploy(target, repoName) { const p = target.path - return runRemote(target, repoName, `git -C ${p} pull && docker compose -f ${p}/docker-compose.yml --project-directory ${p} up -d --build`, 'deploy') + const cloneUrl = FORGEJO_TOKEN + ? `${FORGEJO_URL.replace('://', `://oauth2:${FORGEJO_TOKEN}@`)}/${FORGEJO_ORG}/${repoName}.git` + : `${FORGEJO_URL}/${FORGEJO_ORG}/${repoName}.git` + const gitSsh = `GIT_SSH_COMMAND='ssh -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null'` + // If .git is missing (e.g. push_dir stripped it), re-clone via HTTPS preserving .env, + // then fall through to the normal pull + up. + const ensureGit = + `if [ ! -d ${p}/.git ]; then ` + + `[ -f ${p}/.env ] && cp ${p}/.env /tmp/_restore_${repoName}.env || true; ` + + `rm -rf ${p}; ` + + `${gitSsh} git clone ${cloneUrl} ${p}; ` + + `[ -f /tmp/_restore_${repoName}.env ] && mv /tmp/_restore_${repoName}.env ${p}/.env || true; ` + + `fi` + const cmd = `${ensureGit} && ${gitSsh} git -C ${p} pull && docker compose -f ${p}/docker-compose.yml --project-directory ${p} up -d --build` + return runRemote(target, repoName, cmd, 'deploy') } async function rebuild(target, repoName) {