fix: fix: agents container should clone project repo on first startup; treat init's host clone as operator-side only (#605)
All checks were successful
ci/woodpecker/push/ci Pipeline was successful
ci/woodpecker/pr/ci Pipeline was successful
ci/woodpecker/pr/smoke-init Pipeline was successful

This commit is contained in:
Claude 2026-04-10 17:19:33 +00:00
parent 10be72f5ce
commit c3074e83fc
3 changed files with 37 additions and 0 deletions

View file

@ -237,6 +237,32 @@ bootstrap_factory_repo() {
fi
}
# Ensure the project repo is cloned on first run (#589).
# The agents container uses a named volume (project-repos) at /home/agent/repos.
# On first startup, if the project repo is missing, clone it from FORGE_URL/FORGE_REPO.
# This makes the agents container self-healing and independent of init's host clone.
ensure_project_clone() {
# shellcheck disable=SC2153
local repo_dir="/home/agent/repos/${PROJECT_NAME}"
if [ -d "${repo_dir}/.git" ]; then
log "Project repo present at ${repo_dir}"
return 0
fi
if [ -z "${FORGE_REPO:-}" ] || [ -z "${FORGE_URL:-}" ]; then
log "Cannot clone project repo: FORGE_REPO or FORGE_URL unset"
return 1
fi
log "Cloning ${FORGE_URL}/${FORGE_REPO}.git -> ${repo_dir} (first run)"
mkdir -p "$(dirname "$repo_dir")"
chown -R agent:agent "$(dirname "$repo_dir")"
if gosu agent git clone --quiet "${FORGE_URL}/${FORGE_REPO}.git" "$repo_dir"; then
log "Project repo cloned"
else
log "Project repo clone failed — agents may fail until manually fixed"
return 1
fi
}
# Pull latest factory code at the start of each poll iteration (#593).
# Runs as the agent user; failures are non-fatal (stale code still works).
pull_factory_repo() {
@ -253,6 +279,9 @@ pull_factory_repo() {
_setup_git_creds
configure_tea_login
# Clone project repo on first run (makes agents self-healing, #589)
ensure_project_clone
# Bootstrap ops repos from forgejo into container volumes (#586)
bootstrap_ops_repos