Repository navigation
Expand file tree
/
Copy pathdev.sh
More file actions
executable file
·213 lines (200 loc) · 6.88 KB
/
Copy pathdev.sh
File metadata and controls
executable file
·213 lines (200 loc) · 6.88 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
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
#!/usr/bin/env bash
set -euo pipefail
COMPOSE_FILE="build/dev/docker-compose.yml"
BAKE_FILE="build/dev/docker-bake.hcl"
_compose() { docker compose --project-directory . --file "$COMPOSE_FILE" "$@"; }
_bake() { docker buildx bake --file "$BAKE_FILE" "$@"; }
# Build an image from the bake file unless it already exists: _ensure <tag> <bake target>.
_ensure() {
docker image inspect "docs-builder:$1" >/dev/null 2>&1 \
|| _bake --load "$2"
}
# The CLI clones with git@github.com: origins and the image has no ssh client.
# Rewrite them to HTTPS, with a token when one is available (needed for private
# repos): GITHUB_TOKEN, else `gh auth token`.
_git_https() {
local token="${GITHUB_TOKEN:-}"
if [ -z "$token" ] && command -v gh >/dev/null 2>&1; then
token="$(gh auth token 2>/dev/null || true)"
fi
export GIT_CONFIG_COUNT=1
export GIT_CONFIG_KEY_0="url.https://${token:+oauth2:$token@}github.com/.insteadOf"
export GIT_CONFIG_VALUE_0="git@github.com:"
}
# Assembler and codex run from source in the tooling image. Their services use
# the named .artifacts volumes. Clone and build publish no ports, so they never
# collide with a running serve.
_cli() {
_git_https
_ensure tooling tooling
_compose run --rm "$@"
}
# Serve flows publish the fixed host port from the compose file (4000 for
# assembler, 4001 for codex), which maps to container port 4000. A forwarded
# --port would move the app off that mapping, so reject it.
# Usage: _cli_serve <url> <docker compose run args...>
_cli_serve() {
local url="$1" arg
shift
for arg in "$@"; do
case "$arg" in
--port|--port=*|-p)
echo "error: --port is fixed for dev.sh serve commands; the compose file publishes a fixed port." >&2
exit 1
;;
esac
done
echo "Serving at $url"
_git_https
_ensure tooling tooling
_compose run --rm --service-ports "$@"
}
CODEX_CONFIG="${CODEX_CONFIG:-config/codex.example.yml}"
# Host ports, one per mode (see the table in docker-compose.yml).
ISOLATED_URL="http://localhost:3000"
ASSEMBLER_URL="http://localhost:4000"
CODEX_URL="http://localhost:4001"
case "${1:-help}" in
help|--help|-h)
echo "Usage: ./dev.sh <command>"
echo ""
echo "Each local mode has the same verbs: <mode>-serve, <mode>-build, <mode>-watch,"
echo "plus <mode>-clone for the modes that clone repositories."
echo ""
echo "isolated: one docset (docs/), served at $ISOLATED_URL"
echo " isolated-serve Serve with hot reload"
echo " isolated-watch Same as isolated-serve"
echo " isolated-serve-detached Serve in the background"
echo " isolated-stop Stop the background server"
echo " isolated-build Build the current documentation set"
echo ""
echo "assembler: every repository under one navigation, served at $ASSEMBLER_URL"
echo " assembler Clone, build, and serve"
echo " assembler-clone Clone the assembler repositories"
echo " assembler-build Build the assembled site from the clones"
echo " assembler-serve Serve the last build"
echo " assembler-watch Rebuild and serve on every source change"
echo ""
echo "codex: the codex portal (config: \$CODEX_CONFIG), served at $CODEX_URL"
echo " codex Clone, build, and serve"
echo " codex-clone Clone the codex repositories"
echo " codex-build Build the codex from the clones"
echo " codex-serve Serve the last build"
echo " codex-watch Rebuild and serve on every source change"
echo ""
echo "Images and tests:"
echo " build Build the dev Docker images"
echo " build-api Build only the docs API Docker image"
echo " build-mcp Build only the MCP server Docker image"
echo " rebuild Rebuild the dev Docker images without cache"
echo " test Run the unit-test suite (delegates to ./build.sh unit-test)"
echo ""
echo "Other services:"
echo " serve-api Run the docs API at http://localhost:8081"
echo " serve-api-detached Run the docs API in the background"
echo " stop-api Stop the docs API"
echo " serve-mcp Run the MCP server at http://localhost:8080 (public profile)"
echo " serve-mcp-internal Run the MCP server at http://localhost:8080 (internal profile)"
echo " serve-mcp-detached Run the MCP server in the background"
echo " stop-mcp Stop the MCP server"
echo ""
echo " clean Stop containers and remove containers, networks, and volumes"
;;
build)
_bake --load all
;;
build-api)
_bake --load api "${@:2}"
;;
build-mcp)
_bake --load mcp "${@:2}"
;;
rebuild)
_bake --no-cache --load all
;;
test)
_ensure tooling tooling
_compose run --rm tests
;;
isolated-serve|isolated-watch)
_ensure tooling tooling
echo "Serving at $ISOLATED_URL"
_compose up --no-build serve
;;
isolated-serve-detached)
_ensure tooling tooling
echo "Serving at $ISOLATED_URL"
_compose up --no-build -d serve
;;
isolated-stop)
_compose stop serve
;;
isolated-build)
_ensure local runtime
_compose run --rm docs-builder build
;;
assembler)
_cli_serve "$ASSEMBLER_URL" assembler assemble --serve "${@:2}"
;;
assembler-clone)
_cli assembler assembler clone "${@:2}"
;;
assembler-build)
_cli assembler assembler build "${@:2}"
;;
assembler-serve)
_cli_serve "$ASSEMBLER_URL" assembler assembler serve "${@:2}"
;;
assembler-watch)
_cli_serve "$ASSEMBLER_URL" --entrypoint sh assembler build/dev/watch-entrypoint.sh assembler "${@:2}"
;;
codex)
_cli_serve "$CODEX_URL" codex codex "$CODEX_CONFIG" --serve "${@:2}"
;;
codex-clone)
_cli codex codex clone "$CODEX_CONFIG" "${@:2}"
;;
codex-build)
_cli codex codex build "$CODEX_CONFIG" "${@:2}"
;;
codex-serve)
_cli_serve "$CODEX_URL" codex codex serve "${@:2}"
;;
codex-watch)
_cli_serve "$CODEX_URL" --entrypoint sh -e CODEX_CONFIG="$CODEX_CONFIG" codex build/dev/watch-entrypoint.sh codex "${@:2}"
;;
serve-api)
_ensure api api
_compose up --no-build api
;;
serve-api-detached)
_ensure api api
_compose up --no-build -d api
;;
stop-api)
_compose stop api
;;
serve-mcp)
_ensure mcp mcp
_compose up --no-build mcp
;;
serve-mcp-internal)
_ensure mcp mcp
MCP_SERVER_PROFILE=internal _compose up --no-build mcp
;;
serve-mcp-detached)
_ensure mcp mcp
_compose up --no-build -d mcp
;;
stop-mcp)
_compose stop mcp
;;
clean)
_compose down --remove-orphans --volumes
;;
*)
echo "error: unknown command '$1'" >&2
echo "Run './dev.sh help' for usage." >&2
exit 1
;;
esac