diff --git a/agentbox_build/renderer.py b/agentbox_build/renderer.py index 0ffb7d1..1387304 100644 --- a/agentbox_build/renderer.py +++ b/agentbox_build/renderer.py @@ -25,29 +25,38 @@ def render_snippet(snippet: str, context: dict) -> str: def build_install_script(scripts_dir: Path, context: dict) -> str: - filenames = { - 1: "01-install-system-packages.sh", - 2: "02-install-languages.sh", - 3: "03-install-python-packages.sh", - 4: "04-install-nodejs-packages.sh", - 5: "05-create-user.sh", - 6: "06-configure-root.sh", - } + filenames = [ + "01-install-system-packages.sh", + "02-install-languages.sh", + "03-install-python-packages.sh", + "04-install-nodejs-packages.sh", + "05-create-user.sh", + "06-configure-root.sh", + ] parts: list[str] = [] - for idx in range(1, 7): - script_path = scripts_dir / filenames[idx] + for filename in filenames: + script_path = scripts_dir / filename + step_number = filename.split("-")[0].lstrip("0") + step_name = filename.split("-", 1)[1].removesuffix(".sh").replace("-", " ") rendered = render_snippet(load_script(script_path), context) - parts.append(rendered) - combined = "\n".join(parts) - if not combined.endswith("\n"): - combined += "\n" - return "RUN <<'EOF'\n" + combined + "EOF\n" + if not rendered.endswith("\n"): + rendered += "\n" + # Add step start and complete messages + wrapped_script = f"echo '[agentbox] Step {step_number}: {step_name}'\n" + wrapped_script += rendered + wrapped_script += f"echo '[agentbox] Step {step_number} complete'\n" + parts.append("RUN <<'EOF'\n" + wrapped_script + "EOF\n") + return "\n".join(parts) def build_user_script(scripts_dir: Path, context: dict) -> str: user_script = render_snippet(load_script(scripts_dir / "07-configure-user.sh"), context) if not user_script.endswith("\n"): user_script += "\n" - return "RUN <<'EOF'\n" + user_script + "EOF\n" + # Add step start and complete messages + wrapped_script = "echo '[agentbox] Step 7: configure user'\n" + wrapped_script += user_script + wrapped_script += "echo '[agentbox] Step 7 complete'\n" + return "RUN <<'EOF'\n" + wrapped_script + "EOF\n" @@ -59,4 +68,4 @@ def render_dockerfile(template_path: Path, output_path: Path, context: dict) -> ) template = env.get_template(template_path.name) content = template.render(**context) - output_path.write_text(content, encoding="utf-8") + output_path.write_text(content, encoding="utf-8") \ No newline at end of file diff --git a/scripts/01-install-system-packages.sh b/scripts/01-install-system-packages.sh index 3b12a04..12feac7 100644 --- a/scripts/01-install-system-packages.sh +++ b/scripts/01-install-system-packages.sh @@ -1,8 +1,6 @@ #!/bin/bash set -ex -echo "[agentbox] Step 1: install system packages" - # Install all system packages apt-get update -qq && apt-get install -y -qq --no-install-recommends \ {% for pkg in system_packages.essential -%} @@ -25,5 +23,3 @@ apt-get update -qq && apt-get install -y -qq --no-install-recommends \ apt-get clean rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/* - -echo "[agentbox] Step 1 complete" diff --git a/scripts/02-install-languages.sh b/scripts/02-install-languages.sh index 5c91507..9858c93 100644 --- a/scripts/02-install-languages.sh +++ b/scripts/02-install-languages.sh @@ -1,8 +1,6 @@ #!/bin/bash set -ex -echo "[agentbox] Step 2: install runtimes (miniconda/node/go/rust)" - # Detect architecture (x86_64 or aarch64) ARCH=$(uname -m) case "$ARCH" in @@ -41,5 +39,3 @@ curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y --defaul # Cleanup apt-get clean rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/* - -echo "[agentbox] Step 2 complete" diff --git a/scripts/03-install-python-packages.sh b/scripts/03-install-python-packages.sh index 5f507d1..4172972 100644 --- a/scripts/03-install-python-packages.sh +++ b/scripts/03-install-python-packages.sh @@ -1,8 +1,6 @@ #!/bin/bash set -ex -echo "[agentbox] Step 3: install Python env and packages" - # Create base environment with Python /opt/conda/bin/conda install -y -q -n base -c conda-forge \ python={{ languages.python.version }} \ @@ -21,5 +19,3 @@ echo "[agentbox] Step 3: install Python env and packages" # Cleanup /opt/conda/bin/conda clean --all -y /opt/conda/bin/pip cache purge || true - -echo "[agentbox] Step 3 complete" diff --git a/scripts/04-install-nodejs-packages.sh b/scripts/04-install-nodejs-packages.sh index 88f8624..3e83d25 100644 --- a/scripts/04-install-nodejs-packages.sh +++ b/scripts/04-install-nodejs-packages.sh @@ -1,8 +1,6 @@ #!/bin/bash set -ex -echo "[agentbox] Step 4: install Node.js globals" - # Install Node.js global packages npm install -g \ {% for pkg in nodejs_packages -%} @@ -10,5 +8,3 @@ npm install -g \ {% endfor %} npm cache clean --force - -echo "[agentbox] Step 4 complete" diff --git a/scripts/05-create-user.sh b/scripts/05-create-user.sh index cf685b2..117d3c3 100644 --- a/scripts/05-create-user.sh +++ b/scripts/05-create-user.sh @@ -1,8 +1,6 @@ #!/bin/bash set -ex -echo "[agentbox] Step 5: create non-root user" - # Remove conflicting UID/GID if exists if getent passwd {{ user.uid }} >/dev/null 2>&1; then userdel -r $(getent passwd {{ user.uid }} | cut -d: -f1) @@ -30,5 +28,3 @@ chown -R {{ user.name }}:{{ user.name }} /home/{{ user.name }}/.rustup # Create workspace mkdir -p {{ workdir }} chown -R {{ user.name }}:{{ user.name }} {{ workdir }} - -echo "[agentbox] Step 5 complete" diff --git a/scripts/06-configure-root.sh b/scripts/06-configure-root.sh index f8c2ce3..a1c0008 100644 --- a/scripts/06-configure-root.sh +++ b/scripts/06-configure-root.sh @@ -1,8 +1,6 @@ #!/bin/bash set -ex -echo "[agentbox] Step 6: configure root + Playwright" - # Install Playwright system dependencies apt-get update apt-get install -y --no-install-recommends \ @@ -56,5 +54,3 @@ echo 'conda activate base 2>/dev/null || true' >> /root/.bashrc # Clean up system packages apt-get clean rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/* - -echo "[agentbox] Step 6 complete" diff --git a/scripts/07-configure-user.sh b/scripts/07-configure-user.sh index 3259029..49fe255 100644 --- a/scripts/07-configure-user.sh +++ b/scripts/07-configure-user.sh @@ -1,8 +1,6 @@ #!/bin/bash set -ex -echo "[agentbox] Step 7: configure user shell" - # Initialize micromamba for user # Initialize conda for user /opt/conda/bin/conda init bash @@ -14,5 +12,3 @@ echo 'export GOPATH=/home/{{ user.name }}/go' >> /home/{{ user.name }}/.bashrc echo 'export GOBIN=/home/{{ user.name }}/go/bin' >> /home/{{ user.name }}/.bashrc echo '. /opt/conda/etc/profile.d/conda.sh' >> /home/{{ user.name }}/.bashrc echo 'conda activate base 2>/dev/null || true' >> /home/{{ user.name }}/.bashrc - -echo "[agentbox] Step 7 complete"