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 <noreply@anthropic.com>
This commit is contained in:
parent
377a7478f7
commit
19bb4ec4d4
1 changed files with 15 additions and 1 deletions
|
|
@ -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) {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue