Repository navigation
Expand file tree
/
Copy pathsetup_codelab.sh
More file actions
executable file
·107 lines (95 loc) · 4.51 KB
/
Copy pathsetup_codelab.sh
File metadata and controls
executable file
·107 lines (95 loc) · 4.51 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
#!/usr/bin/env bash
# Agent Substrate in a nutshell — one-shot workbench setup. Safe to re-run.
#
# Run ./setup_project.sh FIRST (or put an existing project ID in ~/project_id.txt).
# When this script finishes you have:
# • Python .venv with FastAPI + Uvicorn + PyYAML installed
# • Node dependencies installed for the React + Vite workbench UI
# • Google Cloud project selected and core APIs enabled
# • The interactive workbench running on port 3000 (backend API on port 8000)
[ -n "${BASH_VERSION:-}" ] || exec bash "$0" "$@"
set -euo pipefail
cd "$(dirname "$0")"
FRONTEND_PORT="${FRONTEND_PORT:-3000}"
BACKEND_PORT="${BACKEND_PORT:-8000}"
say() { printf '\n\033[1m%s\033[0m\n' "$1"; }
tick() { printf ' ✓ %s\n' "$1"; }
info() { printf ' · %s\n' "$1"; }
warn() { printf ' ! %s\n' "$1" >&2; }
die() {
printf '\n\033[1m✗ %s\033[0m\n\n' "$1" >&2
shift
for line in "$@"; do printf '%s\n' "$line" >&2; done
printf '\n' >&2
exit 1
}
say "Agent Substrate in a nutshell · workbench setup"
# ── 1 · Python virtualenv & dependencies ────────────────────────────────────
say "1 · Python environment"
command -v python3 >/dev/null 2>&1 || die \
"python3 not found." \
"Cloud Shell ships with Python 3. On a laptop, install Python 3.10+ first."
if [ ! -d .venv ]; then
info "creating .venv"
python3 -m venv .venv
fi
.venv/bin/pip install --quiet --upgrade pip >/dev/null 2>&1 || true
.venv/bin/pip install --quiet -r requirements.txt
tick ".venv ready ($(.venv/bin/python --version 2>&1))"
# ── 2 · Node / Vite dependencies ────────────────────────────────────────────
say "2 · Frontend dependencies"
command -v node >/dev/null 2>&1 && command -v npm >/dev/null 2>&1 || die \
"node and npm are required for the workbench UI." \
"Cloud Shell has them preinstalled. On a laptop, install Node 20+ first."
if [ ! -d web/node_modules ]; then
info "installing web/node_modules"
(cd web && npm install --no-audit --no-fund --registry=https://registry.npmjs.org)
fi
tick "node $(node --version) · npm $(npm --version)"
# ── 3 · Google Cloud project & required CLIs ────────────────────────────────
say "3 · Google Cloud project & CLI checks"
PROJECT_FILE="$HOME/project_id.txt"
PROJECT=""
if [ -f "$PROJECT_FILE" ]; then
PROJECT="$(tr -d '[:space:]' < "$PROJECT_FILE" || true)"
[ -n "$PROJECT" ] && info "project from $PROJECT_FILE: $PROJECT"
fi
if [ -z "$PROJECT" ] && command -v gcloud >/dev/null 2>&1; then
PROJECT="$(gcloud config get-value project 2>/dev/null || true)"
[ "$PROJECT" = "(unset)" ] && PROJECT=""
fi
if [ -n "$PROJECT" ]; then
gcloud config set project "$PROJECT" >/dev/null 2>&1 || true
printf '%s\n' "$PROJECT" > "$PROJECT_FILE"
tick "active project: $PROJECT"
info "enabling core APIs (container, storage, aiplatform, artifactregistry, cloudbuild)"
gcloud services enable \
container.googleapis.com \
storage.googleapis.com \
aiplatform.googleapis.com \
cloudaicompanion.googleapis.com \
artifactregistry.googleapis.com \
cloudbuild.googleapis.com \
--project="$PROJECT" --quiet >/dev/null 2>&1 || \
warn "could not pre-enable APIs (you can still run in Simulated Lab mode or enable them in Step 1)"
else
warn "No Google Cloud project configured — workbench will start in Simulated Lab mode."
info "Run ./setup_project.sh anytime to create a billing-linked project for Live GKE mode."
fi
for tool in gcloud kubectl go docker; do
if command -v "$tool" >/dev/null 2>&1; then
tick "$tool found ($(command -v "$tool"))"
else
warn "$tool not found on PATH (required for Live GKE mode; preinstalled in Cloud Shell)"
fi
done
# ── 4 · Launch the workbench ────────────────────────────────────────────────
say "4 · Starting workbench"
FRONTEND_PORT="$FRONTEND_PORT" BACKEND_PORT="$BACKEND_PORT" ./scripts/start.sh
say "Ready!"
if [ -n "${WEB_HOST:-}" ]; then
printf ' Open Cloud Shell Web Preview: https://%s-%s\n' "$FRONTEND_PORT" "$WEB_HOST"
else
printf ' Open in your browser: http://localhost:%s\n' "$FRONTEND_PORT"
fi
printf ' Tip: Step 1 spins up GKE in the background (~5–6 min), so start Step 1 right away!\n\n'