diff --git a/bootstrap_docker.sh b/bootstrap_docker.sh index c59b9a61..206d1d89 100755 --- a/bootstrap_docker.sh +++ b/bootstrap_docker.sh @@ -1,50 +1,108 @@ -#!/bin/bash -# This script builds the monorepo projects listed in the build_local script, terminating when it reaches TARGET_PROJECT. -# It performs the build inside a docker image that can launch further docker builds by mapping the users docker daemon -# socket into the container. A kind of simulated "docker-in-docker". -# We copy the monorepo entire working tree into this container, excluding any build output. -# The mechanics of this are, we mount the users repo into the container, then clone it into a directory within the -# container, and also apply modified/untracked/deleted changes to the internal repo. -# The result is we have a fresh copy of the repo, with only the working changes applied, that we can modify as we wish. +#!/usr/bin/env bash +# ๐Ÿ›ก๏ธ PORTABILITY: Use 'env bash' for broader OS compatibility. -set -e +# Strict mode: Fail on error, unset variables, and pipe failures. +set -euo pipefail + +TARGET_PROJECT="${1:-}" +REPO="aztec3-circuits" -TARGET_PROJECT=$1 -REPO=aztec3-circuits +# ๐Ÿ›ก๏ธ SAFETY: Get absolute path to the repo root to avoid relative path issues. +REPO_ROOT=$(git rev-parse --show-toplevel) COMMIT_HASH=$(git rev-parse HEAD) -# If we're calling this script from within a project directory, that's the target project. +# ๐Ÿ” LOGIC FIX: Handle project detection safely. +# If TARGET_PROJECT is empty, try to detect it from the current directory context. if [ -z "$TARGET_PROJECT" ]; then - TARGET_PROJECT=$(git rev-parse --show-prefix) - if [ -n "$TARGET_PROJECT" ]; then - # We are in a project folder. + # Get path relative to repo root + CURRENT_PREFIX=$(git rev-parse --show-prefix) + + if [ -n "$CURRENT_PREFIX" ]; then + # We are inside a subdirectory. ONLY_TARGET=true - TARGET_PROJECT=$(basename $TARGET_PROJECT) - cd $(git rev-parse --show-cdup) + # Remove trailing slash if present and get basename + TARGET_PROJECT=$(basename "${CURRENT_PREFIX%/}") + + # ๐Ÿงน CLEANUP: Instead of risky 'cd', we just use REPO_ROOT for operations. + echo "Detected target project from directory: $TARGET_PROJECT" fi fi -docker build -t $REPO-build - < /dev/null 2>&1; done -# Setup build environment. -source ./build-system/scripts/setup_env $COMMIT_HASH '' mainframe_$USER /repo +# 4. CLEANUP: Remove files that are deleted in the working tree +for F in \$(git ls-files --deleted); do + rm -f /$REPO/\$F +done + +# 5. Build Execution +cd /$REPO +echo 'Setting up environment...' +# Ensure the script is executable and exists before sourcing +if [ -f \"./build-system/scripts/setup_env\" ]; then + source ./build-system/scripts/setup_env \"$COMMIT_HASH\" '' \"mainframe_$USER\" /repo_host +else + echo 'Error: setup_env script not found!' + exit 1 +fi -build_local $TARGET_PROJECT $ONLY_TARGET -" \ No newline at end of file +echo \"Starting build for: \${TARGET_PROJECT:-ALL}\" +# Call the build function (assumed to be loaded by setup_env) +build_local \"$TARGET_PROJECT\" \"${ONLY_TARGET:-}\" +"