Skip to content

Commit 9cf8a46

Browse files
committed
perf(ci): speed up docker e2e setup
1 parent feeb85a commit 9cf8a46

5 files changed

Lines changed: 99 additions & 4 deletions

File tree

.github/actions/free-docker-disk/action.yml

Lines changed: 31 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,38 @@ runs:
77
- name: Free disk for Docker builds
88
shell: bash
99
run: |
10-
set -euxo pipefail
10+
set -euo pipefail
1111
1212
df -h
13-
docker system df || true
13+
14+
threshold_gib="${DOCKER_GIT_FREE_DOCKER_DISK_MIN_AVAILABLE_GIB:-40}"
15+
force_cleanup="${DOCKER_GIT_FORCE_FREE_DOCKER_DISK:-0}"
16+
force_cleanup_enabled=0
17+
18+
if [[ ! "$threshold_gib" =~ ^[0-9]+$ ]]; then
19+
echo "Invalid DOCKER_GIT_FREE_DOCKER_DISK_MIN_AVAILABLE_GIB: $threshold_gib" >&2
20+
exit 1
21+
fi
22+
23+
case "$force_cleanup" in
24+
1|true|TRUE|yes|YES|on|ON)
25+
force_cleanup_enabled=1
26+
;;
27+
*)
28+
force_cleanup_enabled=0
29+
;;
30+
esac
31+
32+
available_kib="$(df -Pk / | awk 'NR == 2 { print $4 }')"
33+
threshold_kib="$((threshold_gib * 1024 * 1024))"
34+
35+
if [[ "$force_cleanup_enabled" != "1" && "$available_kib" -ge "$threshold_kib" ]]; then
36+
echo "Skipping Docker disk cleanup: / has at least ${threshold_gib}GiB available."
37+
exit 0
38+
fi
39+
40+
echo "Running Docker disk cleanup: available=${available_kib}KiB threshold=${threshold_kib}KiB force=${force_cleanup}."
41+
timeout 20s docker system df || true
1442
1543
sudo rm -rf \
1644
/opt/ghc \
@@ -22,4 +50,4 @@ runs:
2250
docker system prune -af --volumes || true
2351
2452
df -h
25-
docker system df || true
53+
timeout 20s docker system df || true

.github/workflows/check.yml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,7 @@ jobs:
155155
timeout-minutes: 40
156156
env:
157157
DOCKER_GIT_CONTROLLER_BUILD_SKILLER: "0"
158+
DOCKER_GIT_E2E_REUSE_WORKSPACE_INSTALL: "1"
158159
steps:
159160
- uses: actions/checkout@v6
160161
with:
@@ -174,6 +175,7 @@ jobs:
174175
timeout-minutes: 40
175176
env:
176177
DOCKER_GIT_CONTROLLER_BUILD_SKILLER: "0"
178+
DOCKER_GIT_E2E_REUSE_WORKSPACE_INSTALL: "1"
177179
steps:
178180
- uses: actions/checkout@v6
179181
with:
@@ -193,6 +195,7 @@ jobs:
193195
timeout-minutes: 40
194196
env:
195197
DOCKER_GIT_CONTROLLER_BUILD_SKILLER: "0"
198+
DOCKER_GIT_E2E_REUSE_WORKSPACE_INSTALL: "1"
196199
steps:
197200
- uses: actions/checkout@v6
198201
with:
@@ -212,6 +215,7 @@ jobs:
212215
timeout-minutes: 40
213216
env:
214217
DOCKER_GIT_CONTROLLER_BUILD_SKILLER: "0"
218+
DOCKER_GIT_E2E_REUSE_WORKSPACE_INSTALL: "1"
215219
steps:
216220
- uses: actions/checkout@v6
217221
with:
@@ -231,6 +235,7 @@ jobs:
231235
timeout-minutes: 60
232236
env:
233237
DOCKER_GIT_CONTROLLER_BUILD_SKILLER: "0"
238+
DOCKER_GIT_E2E_REUSE_WORKSPACE_INSTALL: "1"
234239
steps:
235240
- uses: actions/checkout@v6
236241
with:
@@ -250,6 +255,7 @@ jobs:
250255
timeout-minutes: 40
251256
env:
252257
DOCKER_GIT_CONTROLLER_BUILD_SKILLER: "0"
258+
DOCKER_GIT_E2E_REUSE_WORKSPACE_INSTALL: "1"
253259
steps:
254260
- uses: actions/checkout@v6
255261
with:

packages/app/package.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@
2727
"lint:effect": "NODE_OPTIONS=--max-old-space-size=4096 PATH=../../scripts:$PATH eslint --config eslint.effect-ts-check.config.mjs .",
2828
"prebuild:docker-git": "bun install --cwd ../.. && bun run --cwd ../docker-git-session-sync build && bun run --cwd ../lib build",
2929
"build:docker-git": "vite build --config vite.docker-git.config.ts",
30+
"prebuild:docker-git:reuse-install": "bun run --cwd ../docker-git-session-sync build && bun run --cwd ../lib build",
31+
"build:docker-git:reuse-install": "vite build --config vite.docker-git.config.ts",
3032
"check": "bun run typecheck",
3133
"clone": "bun run build:docker-git && bun dist/src/docker-git/main.js clone",
3234
"open": "bun run build:docker-git && bun dist/src/docker-git/main.js open",

scripts/e2e/_lib.sh

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ exec sudo -n env \
2424
"DOCKER_GIT_API_CONTAINER_NAME=${DOCKER_GIT_API_CONTAINER_NAME:-}" \
2525
"DOCKER_GIT_API_PORT=${DOCKER_GIT_API_PORT:-}" \
2626
"DOCKER_GIT_CONTROLLER_DOCKER_HOST=${DOCKER_GIT_CONTROLLER_DOCKER_HOST:-}" \
27+
"DOCKER_GIT_CONTROLLER_BUILD_SKILLER=${DOCKER_GIT_CONTROLLER_BUILD_SKILLER:-}" \
2728
"DOCKER_GIT_CONTROLLER_REV=${DOCKER_GIT_CONTROLLER_REV:-}" \
2829
"DOCKER_GIT_DOCKERD_DEFAULT_CGROUPNS_MODE=${DOCKER_GIT_DOCKERD_DEFAULT_CGROUPNS_MODE:-}" \
2930
"DOCKER_GIT_DOCKERD_TCP_HOST=${DOCKER_GIT_DOCKERD_TCP_HOST:-}" \
@@ -134,6 +135,35 @@ dg_ensure_node_gyp() {
134135
export PATH="$node_gyp_bin:$PATH"
135136
}
136137

138+
dg_is_truthy() {
139+
case "${1:-}" in
140+
1|true|TRUE|yes|YES|on|ON)
141+
return 0
142+
;;
143+
*)
144+
return 1
145+
;;
146+
esac
147+
}
148+
149+
dg_log_duration() {
150+
local label="$1"
151+
local started_at="$2"
152+
local finished_at
153+
finished_at="$(date +%s)"
154+
155+
echo "e2e: ${label} completed in $((finished_at - started_at))s" >&2
156+
}
157+
158+
dg_workspace_install_ready() {
159+
local repo_root="$1"
160+
161+
[[ -d "$repo_root/node_modules" ]] \
162+
&& [[ -x "$repo_root/packages/app/node_modules/.bin/vite" ]] \
163+
&& [[ -x "$repo_root/packages/lib/node_modules/.bin/tsc" ]] \
164+
&& [[ -x "$repo_root/packages/docker-git-session-sync/node_modules/.bin/vite" ]]
165+
}
166+
137167
dg_pick_free_port() {
138168
local first_port="$1"
139169
local last_port="$2"
@@ -430,31 +460,56 @@ dg_project_ssh_to_container() {
430460
dg_prepare_bun_workspace() {
431461
local repo_root="$1"
432462
local bin_dir="$2"
463+
local started_at
433464

434465
dg_ensure_bun
435466
dg_ensure_node_gyp "$bin_dir"
436467

468+
if dg_is_truthy "${DOCKER_GIT_E2E_REUSE_WORKSPACE_INSTALL:-0}" && dg_workspace_install_ready "$repo_root"; then
469+
echo "e2e: reusing existing Bun workspace install" >&2
470+
return 0
471+
fi
472+
473+
started_at="$(date +%s)"
437474
(
438475
cd "$repo_root"
439476
bun install --no-save --silent
440477
)
478+
dg_log_duration "Bun workspace install" "$started_at"
441479
}
442480

443481
dg_build_docker_git_cli() {
444482
local repo_root="$1"
483+
local started_at
484+
485+
started_at="$(date +%s)"
486+
487+
if dg_is_truthy "${DOCKER_GIT_E2E_REUSE_WORKSPACE_INSTALL:-0}" && dg_workspace_install_ready "$repo_root"; then
488+
(
489+
cd "$repo_root"
490+
bun run --cwd packages/app build:docker-git:reuse-install
491+
)
492+
dg_log_duration "docker-git CLI build" "$started_at"
493+
return 0
494+
fi
445495

446496
(
447497
cd "$repo_root"
448498
bun run --cwd packages/app build:docker-git
449499
)
500+
dg_log_duration "docker-git CLI build" "$started_at"
450501
}
451502

452503
dg_prepare_docker_git_cli() {
453504
local repo_root="$1"
454505
local bin_dir="$2"
506+
local started_at
507+
508+
started_at="$(date +%s)"
455509

456510
dg_prepare_bun_workspace "$repo_root" "$bin_dir"
457511
dg_build_docker_git_cli "$repo_root"
512+
dg_log_duration "prepare docker-git CLI" "$started_at"
458513
}
459514

460515
dg_run_docker_git() {

scripts/e2e/browser-command.sh

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,11 @@ dg_ensure_docker "$E2E_BIN"
140140
dg_prepare_docker_git_cli "$REPO_ROOT" "$E2E_BIN"
141141

142142
cd "$REPO_ROOT"
143-
setsid bash -lc 'bun run docker-git -- browser' >"$BROWSER_LOG" 2>&1 &
143+
if dg_is_truthy "${DOCKER_GIT_E2E_REUSE_WORKSPACE_INSTALL:-0}"; then
144+
setsid bash -lc 'bun packages/app/dist/src/docker-git/main.js browser' >"$BROWSER_LOG" 2>&1 &
145+
else
146+
setsid bash -lc 'bun run docker-git -- browser' >"$BROWSER_LOG" 2>&1 &
147+
fi
144148
BROWSER_PID="$!"
145149

146150
wait_for_log_line "Ensuring docker-git API controller is current."

0 commit comments

Comments
 (0)