Merge pull request 'fix: bug: agents container has two diverging copies of disinto code — entrypoint runs baked-in stale version while dev-agent works in fresh git checkout (#593)' (#630) from fix/issue-593 into main
All checks were successful
ci/woodpecker/push/ci Pipeline was successful
All checks were successful
ci/woodpecker/push/ci Pipeline was successful
This commit is contained in:
commit
4a35c2bba0
2 changed files with 72 additions and 1 deletions
|
|
@ -16,7 +16,9 @@ set -euo pipefail
|
||||||
# - planner: every 12 hours (144 iterations * 5 min)
|
# - planner: every 12 hours (144 iterations * 5 min)
|
||||||
# - predictor: every 24 hours (288 iterations * 5 min)
|
# - predictor: every 24 hours (288 iterations * 5 min)
|
||||||
|
|
||||||
DISINTO_DIR="/home/agent/disinto"
|
DISINTO_BAKED="/home/agent/disinto"
|
||||||
|
DISINTO_LIVE="/home/agent/repos/_factory"
|
||||||
|
DISINTO_DIR="$DISINTO_BAKED" # start with baked copy; switched to live checkout after bootstrap
|
||||||
LOGFILE="/home/agent/data/agent-entrypoint.log"
|
LOGFILE="/home/agent/data/agent-entrypoint.log"
|
||||||
|
|
||||||
# Create all expected log subdirectories and set ownership as root before dropping to agent.
|
# Create all expected log subdirectories and set ownership as root before dropping to agent.
|
||||||
|
|
@ -208,6 +210,67 @@ print(cfg.get('primary_branch', 'main'))
|
||||||
done
|
done
|
||||||
}
|
}
|
||||||
|
|
||||||
|
# Bootstrap the factory (disinto) repo from Forgejo into the project-repos
|
||||||
|
# volume so the entrypoint runs from a live git checkout that receives
|
||||||
|
# updates via `git pull`, not the stale baked copy from `COPY .` (#593).
|
||||||
|
bootstrap_factory_repo() {
|
||||||
|
local repo="${FACTORY_REPO:-}"
|
||||||
|
if [ -z "$repo" ]; then
|
||||||
|
log "Factory bootstrap: FACTORY_REPO not set — running from baked copy"
|
||||||
|
return 0
|
||||||
|
fi
|
||||||
|
|
||||||
|
local remote_url="${FORGE_URL}/${repo}.git"
|
||||||
|
local primary_branch="${PRIMARY_BRANCH:-main}"
|
||||||
|
|
||||||
|
if [ ! -d "${DISINTO_LIVE}/.git" ]; then
|
||||||
|
log "Factory bootstrap: cloning ${repo} -> ${DISINTO_LIVE}"
|
||||||
|
if gosu agent git clone --quiet --branch "$primary_branch" "$remote_url" "$DISINTO_LIVE" 2>&1; then
|
||||||
|
log "Factory bootstrap: cloned successfully"
|
||||||
|
else
|
||||||
|
log "Factory bootstrap: clone failed — running from baked copy"
|
||||||
|
return 0
|
||||||
|
fi
|
||||||
|
else
|
||||||
|
log "Factory bootstrap: pulling latest ${repo}"
|
||||||
|
gosu agent bash -c "
|
||||||
|
cd '${DISINTO_LIVE}' && \
|
||||||
|
git fetch origin '${primary_branch}' --quiet 2>/dev/null && \
|
||||||
|
git reset --hard 'origin/${primary_branch}' --quiet 2>/dev/null
|
||||||
|
" || log "Factory bootstrap: pull failed — using existing checkout"
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Copy project TOMLs from baked dir — they are gitignored AND docker-ignored,
|
||||||
|
# so neither the image nor the clone normally contains them. If the baked
|
||||||
|
# copy has any (e.g. operator manually placed them), propagate them.
|
||||||
|
if compgen -G "${DISINTO_BAKED}/projects/*.toml" >/dev/null 2>&1; then
|
||||||
|
mkdir -p "${DISINTO_LIVE}/projects"
|
||||||
|
cp "${DISINTO_BAKED}"/projects/*.toml "${DISINTO_LIVE}/projects/"
|
||||||
|
chown -R agent:agent "${DISINTO_LIVE}/projects"
|
||||||
|
log "Factory bootstrap: copied project TOMLs to live checkout"
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Verify the live checkout has the expected structure
|
||||||
|
if [ -f "${DISINTO_LIVE}/lib/env.sh" ]; then
|
||||||
|
DISINTO_DIR="$DISINTO_LIVE"
|
||||||
|
log "Factory bootstrap: DISINTO_DIR switched to live checkout at ${DISINTO_LIVE}"
|
||||||
|
else
|
||||||
|
log "Factory bootstrap: live checkout missing expected files — falling back to baked copy"
|
||||||
|
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() {
|
||||||
|
[ "$DISINTO_DIR" = "$DISINTO_LIVE" ] || return 0
|
||||||
|
local primary_branch="${PRIMARY_BRANCH:-main}"
|
||||||
|
gosu agent bash -c "
|
||||||
|
cd '${DISINTO_LIVE}' && \
|
||||||
|
git fetch origin '${primary_branch}' --quiet 2>/dev/null && \
|
||||||
|
git reset --hard 'origin/${primary_branch}' --quiet 2>/dev/null
|
||||||
|
" || log "Factory pull failed — continuing with current checkout"
|
||||||
|
}
|
||||||
|
|
||||||
# Configure git and tea once at startup (as root, then drop to agent)
|
# Configure git and tea once at startup (as root, then drop to agent)
|
||||||
configure_git_creds
|
configure_git_creds
|
||||||
configure_tea_login
|
configure_tea_login
|
||||||
|
|
@ -215,6 +278,9 @@ configure_tea_login
|
||||||
# Bootstrap ops repos from forgejo into container volumes (#586)
|
# Bootstrap ops repos from forgejo into container volumes (#586)
|
||||||
bootstrap_ops_repos
|
bootstrap_ops_repos
|
||||||
|
|
||||||
|
# Bootstrap factory repo — switch DISINTO_DIR to live checkout (#593)
|
||||||
|
bootstrap_factory_repo
|
||||||
|
|
||||||
# Initialize state directory for check_active guards
|
# Initialize state directory for check_active guards
|
||||||
init_state_dir
|
init_state_dir
|
||||||
|
|
||||||
|
|
@ -234,6 +300,9 @@ while true; do
|
||||||
iteration=$((iteration + 1))
|
iteration=$((iteration + 1))
|
||||||
now=$(date +%s)
|
now=$(date +%s)
|
||||||
|
|
||||||
|
# Pull latest factory code so poll scripts stay current (#593)
|
||||||
|
pull_factory_repo
|
||||||
|
|
||||||
# Stale .sid cleanup — needed for agents that don't support --resume
|
# Stale .sid cleanup — needed for agents that don't support --resume
|
||||||
# Run this as the agent user
|
# Run this as the agent user
|
||||||
gosu agent bash -c "rm -f /tmp/dev-session-*.sid /tmp/review-session-*.sid 2>/dev/null || true"
|
gosu agent bash -c "rm -f /tmp/dev-session-*.sid /tmp/review-session-*.sid 2>/dev/null || true"
|
||||||
|
|
|
||||||
|
|
@ -337,7 +337,9 @@ services:
|
||||||
CLAUDE_TIMEOUT: ${CLAUDE_TIMEOUT:-7200}
|
CLAUDE_TIMEOUT: ${CLAUDE_TIMEOUT:-7200}
|
||||||
CLAUDE_CODE_DISABLE_NONESSENTIAL_TRAFFIC: ${CLAUDE_CODE_DISABLE_NONESSENTIAL_TRAFFIC:-1}
|
CLAUDE_CODE_DISABLE_NONESSENTIAL_TRAFFIC: ${CLAUDE_CODE_DISABLE_NONESSENTIAL_TRAFFIC:-1}
|
||||||
ANTHROPIC_API_KEY: ${ANTHROPIC_API_KEY:-}
|
ANTHROPIC_API_KEY: ${ANTHROPIC_API_KEY:-}
|
||||||
|
FORGE_PASS: ${FORGE_PASS:-}
|
||||||
FORGE_ADMIN_PASS: ${FORGE_ADMIN_PASS:-}
|
FORGE_ADMIN_PASS: ${FORGE_ADMIN_PASS:-}
|
||||||
|
FACTORY_REPO: ${FORGE_REPO:-disinto-admin/disinto}
|
||||||
DISINTO_CONTAINER: "1"
|
DISINTO_CONTAINER: "1"
|
||||||
PROJECT_REPO_ROOT: /home/agent/repos/${PROJECT_NAME:-project}
|
PROJECT_REPO_ROOT: /home/agent/repos/${PROJECT_NAME:-project}
|
||||||
WOODPECKER_DATA_DIR: /woodpecker-data
|
WOODPECKER_DATA_DIR: /woodpecker-data
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue