-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_env.sh
More file actions
executable file
·166 lines (148 loc) · 6.62 KB
/
Copy pathtest_env.sh
File metadata and controls
executable file
·166 lines (148 loc) · 6.62 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
#!/bin/bash
# BindMaster test environment launcher
#
# Builds a clean Docker image (Ubuntu 24.04 + Miniforge) and drops you into
# an interactive shell where you can run ./install_aarch.sh as if on a
# fresh DGX Spark.
#
# Usage:
# ./test_env.sh # build image if needed, then run
# ./test_env.sh --rebuild # force image rebuild before running
# ./test_env.sh --gpu # pass GPU access to the container
# ./test_env.sh --no-old # don't mount the OLD tools dir (tests download fallback)
# ./test_env.sh --clean # remove test artifacts created in previous runs
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
IMAGE_NAME="bindmaster-test"
CONTAINER_NAME="bindmaster-test-run"
# Pre-cached resources (AF2 weights, ARM64 binaries) — mounted read-only
OLD_TOOLS_DIR="${OLD_TOOLS_DIR:-$HOME/Documents/OLD/BindMaster/bindcraft-tools}"
REBUILD=false
GPU=false
MOUNT_OLD=true
CLEAN=false
DRY_RUN=false
for arg in "$@"; do
case "$arg" in
--rebuild) REBUILD=true ;;
--gpu) GPU=true ;;
--no-old) MOUNT_OLD=false ;;
--clean) CLEAN=true ;;
--dry-run) DRY_RUN=true ;;
-h|--help)
cat <<EOF
Usage: $0 [--rebuild] [--gpu] [--no-old] [--clean] [--dry-run]
--rebuild Force rebuild of the Docker image
--gpu Expose the GPU to the container (requires nvidia runtime)
--no-old Don't mount OLD tools dir (AF2 weights will be downloaded)
--clean Remove test artifacts left in the repo from previous runs
--dry-run Run install.sh --tool all --yes --skip-examples non-interactively
and report pass/fail (no interactive shell)
EOF
exit 0 ;;
*)
echo "Unknown option: $arg"; exit 1 ;;
esac
done
# ── Clean up artifacts from previous runs ─────────────────────────────────────
if [[ "${CLEAN}" == true ]]; then
echo "Removing test artifacts..."
docker run --rm \
--user root \
--volume "${SCRIPT_DIR}:/workspace" \
"${IMAGE_NAME}" \
/bin/bash -c "
rm -rf /workspace/Mosaic/.venv
rm -rf /workspace/Mosaic/examples/bindmaster_examples
rm -f /workspace/install_aarch.log /workspace/install.log
echo 'Done.'
" 2>/dev/null \
|| sudo rm -rf \
"${SCRIPT_DIR}/Mosaic/.venv" \
"${SCRIPT_DIR}/Mosaic/examples/bindmaster_examples" \
"${SCRIPT_DIR}/install_aarch.log" \
"${SCRIPT_DIR}/install.log"
echo "Clean."
exit 0
fi
# ── Build image ────────────────────────────────────────────────────────────────
if [[ "${REBUILD}" == true ]] || ! docker image inspect "${IMAGE_NAME}" &>/dev/null; then
echo "Building ${IMAGE_NAME} ..."
docker build \
-f "${SCRIPT_DIR}/Dockerfile.test" \
-t "${IMAGE_NAME}" \
"${SCRIPT_DIR}" \
|| { echo "Docker build failed."; exit 1; }
echo "Image built."
fi
# ── Assemble docker run args ───────────────────────────────────────────────────
# Run as the current host user so files written in the container are owned
# by us — no sudo needed for cleanup afterwards.
RUN_ARGS=(
--rm
--interactive
--tty
--name "${CONTAINER_NAME}"
# Run as the host user (no UID mismatch, files stay host-writable)
--user "$(id -u):$(id -g)"
# Mount installer repo at /workspace (read-write)
--volume "${SCRIPT_DIR}:/workspace"
--workdir /workspace
)
if [[ "${MOUNT_OLD}" == true && -d "${OLD_TOOLS_DIR}" ]]; then
RUN_ARGS+=(--volume "${OLD_TOOLS_DIR}:/old-tools:ro")
echo "Mounting OLD tools: ${OLD_TOOLS_DIR} → /old-tools (read-only)"
else
echo "OLD tools dir not mounted — AF2 weights will be downloaded if needed."
fi
if [[ "${GPU}" == true ]]; then
RUN_ARGS+=(--gpus all)
echo "GPU access enabled."
fi
# ── Dry-run mode ──────────────────────────────────────────────────────────────
if [[ "${DRY_RUN}" == true ]]; then
echo ""
echo "Dry-run: running install/install.sh --tool all --yes --skip-examples ..."
echo "─────────────────────────────────────────────────────────────"
# Override: non-interactive, no TTY
DRY_ARGS=(
--rm
--name "${CONTAINER_NAME}"
--user "$(id -u):$(id -g)"
--volume "${SCRIPT_DIR}:/workspace"
--workdir /workspace
)
if [[ "${MOUNT_OLD}" == true && -d "${OLD_TOOLS_DIR}" ]]; then
DRY_ARGS+=(--volume "${OLD_TOOLS_DIR}:/old-tools:ro")
fi
if [[ "${GPU}" == true ]]; then
DRY_ARGS+=(--gpus all)
fi
docker run "${DRY_ARGS[@]}" "${IMAGE_NAME}" \
bash -c "install/install.sh --tool all --yes --skip-examples"
rc=$?
echo ""
echo "─────────────────────────────────────────────────────────────"
if [[ ${rc} -eq 0 ]]; then
echo "PASS: dry-run install completed successfully (exit code 0)"
else
echo "FAIL: dry-run install failed (exit code ${rc})"
fi
exit ${rc}
fi
# ── Run (interactive) ─────────────────────────────────────────────────────────
echo ""
echo "Starting clean test environment..."
echo "─────────────────────────────────────────────────────────────"
echo " Installer: /workspace/install_aarch.sh"
echo " OLD tools: /old-tools (pre-cached AF2 weights + binaries)"
echo ""
echo " Quickstart:"
echo " ./install_aarch.sh --tools-dir /old-tools"
echo " ./install_aarch.sh --tools-dir /old-tools --tool mosaic --skip-examples"
echo ""
echo " Cleanup after testing:"
echo " exit (container is deleted automatically)"
echo " ./test_env.sh --clean (removes artifacts from the mounted repo)"
echo "─────────────────────────────────────────────────────────────"
echo ""
docker run "${RUN_ARGS[@]}" "${IMAGE_NAME}"