CI / check (push) Successful in 30s
CI / tests-unit (push) Successful in 1m53s
CI / tests-integration (push) Successful in 1m54s
CI / tests-imaging-browsers (push) Successful in 2m26s
CI / tests-quality (push) Successful in 2m19s
CI / tests-ui (push) Successful in 4m31s
CI / preflight (push) Skipped
CI / deploy (push) Failing after 3m9s
Three build-time improvements, all measured on this host. The build context no longer ships the test suites. `next build` type-checks the whole project, so `e2e/` and `integration/` in the context made the image build fail on a type error in test code and pulled @playwright/test, vitest, msw, testcontainers and drizzle-kit into the image. The CI runs those suites on the host. Type-check time in the build drops from 2.2s to 1.3s, and a contract test now fails if application code ever imports from those folders. The CI now exports the build cache to a directory outside the runner workspace: /var/cache/epicnext-cms-buildcache for the release and a separate map for branch preflights, so a branch can never feed the release cache. The workspace is wiped after every job and `docker builder prune` runs after every release, so the next build started with an empty cache and downloaded all 493 packages again (measured: reused 0, downloaded 493). With the durable export the frozen dependency layer is reused (measured: reused 493, downloaded 0) even after a full prune. A cache directory that is not writable only produces a warning; the release is never blocked. Investigated the remaining ~30s of Next.js build tracing: excluding the dev-only packages with `outputFileTracingExcludes` made it slower (35s vs 30s), because the traced output was already minimal (5 packages). The cost is Next's own page-config collection and file tracing over 329 routes, not the dependency set, so no configuration was kept.
61 lines
2.3 KiB
Bash
61 lines
2.3 KiB
Bash
#!/usr/bin/env bash
|
|
# Build and browser-test a branch candidate using only disposable services.
|
|
set -Eeuo pipefail
|
|
umask 077
|
|
|
|
sha="$(git rev-parse HEAD)"
|
|
[[ "$sha" =~ ^[0-9a-f]{40}$ ]] || { echo "Invalid preflight commit" >&2; exit 1; }
|
|
temporary="$(mktemp -d "${TMPDIR:-/tmp}/cms-preflight.XXXXXXXXXX")"
|
|
suffix="${temporary##*.}"
|
|
image="epicnext-cms:preflight-$sha-$suffix"
|
|
build_attempted=0
|
|
|
|
finish() {
|
|
local status=$?
|
|
trap - EXIT
|
|
if [ "$build_attempted" -eq 1 ]; then
|
|
# Remove this run's tag only. Never prune, force-remove or touch release tags.
|
|
if ! docker image rm "$image"; then
|
|
if [ "$status" -eq 0 ]; then status=1; fi
|
|
fi
|
|
fi
|
|
# The private directory contains no files; never recursively delete a path.
|
|
if ! rmdir -- "$temporary"; then
|
|
if [ "$status" -eq 0 ]; then status=1; fi
|
|
fi
|
|
if [ "$status" -eq 0 ]; then echo "Branch preflight verified: $sha"; fi
|
|
exit "$status"
|
|
}
|
|
trap finish EXIT
|
|
trap 'exit 130' INT
|
|
trap 'exit 143' TERM
|
|
[[ "$temporary" = /* && -d "$temporary" && ! -L "$temporary" && "$suffix" =~ ^[a-zA-Z0-9]{10}$ ]] || {
|
|
echo "Invalid private preflight directory" >&2
|
|
exit 1
|
|
}
|
|
|
|
pnpm install --frozen-lockfile
|
|
pnpm exec playwright install chromium
|
|
export NEWS_E2E_IMAGE="$image"
|
|
export NEWS_E2E_RELEASE="$sha"
|
|
build_attempted=1
|
|
# Duurzame buildcache buiten de tijdelijke werkmap, zodat de lagen van een
|
|
# vorige preflight hergebruikt worden in plaats van opnieuw gedownload. Eigen
|
|
# map, gescheiden van de release-cache: een branch-preflight mag nooit de cache
|
|
# van de release-build voeden. Een lege CMS_BUILD_CACHE_DIR schakelt het uit.
|
|
build_cache_dir="${CMS_BUILD_CACHE_DIR-/var/cache/epicnext-cms-preflight-cache}"
|
|
build_cache_flags=()
|
|
if [ -n "$build_cache_dir" ]; then
|
|
if mkdir -p "$build_cache_dir" 2>/dev/null && [ -w "$build_cache_dir" ]; then
|
|
build_cache_flags=(
|
|
--cache-from "type=local,src=$build_cache_dir"
|
|
--cache-to "type=local,dest=$build_cache_dir,mode=max"
|
|
)
|
|
else
|
|
echo "Warning: buildcache $build_cache_dir is niet beschrijfbaar; build zonder hergebruikte cache." >&2
|
|
fi
|
|
fi
|
|
DOCKER_BUILDKIT=1 docker build --progress=plain \
|
|
${build_cache_flags[@]+"${build_cache_flags[@]}"} \
|
|
--build-arg NEXT_DEPLOYMENT_ID="$sha" -t "$image" .
|
|
NEWS_E2E_IMAGE="$image" NEWS_E2E_RELEASE="$sha" node --import tsx e2e/news-real/run.ts |