perf: build docs on the CI runner with a warm .next cache (#840)

Move `npm run build` out of the Docker image onto the runner, where actions/cache persists .next/cache across runs (the in-Docker build discarded it every time). The image now just packages the prebuilt .next and serves it with `next start`; runtime and the DocSearch entrypoint injection are unchanged.

Also: checkout full history (fetch-depth: 0) so per-page dates are correct, guard buildGitDateMap against shallow clones (correct-or-absent, never wrong), modernise the Docker actions (build-push-action v6, provenance: false), and add a path-filtered pull_request trigger so pipeline changes are validated before merge.

Smoke-tested via isolated build + docker run: serves /, /introduction, /api, sitemap, static assets (200); DocSearch placeholder injection intact.
This commit is contained in:
Jack Carter
2026-07-09 14:13:30 +02:00
committed by GitHub
parent 51afd0cf71
commit 76845ec77f
4 changed files with 71 additions and 21 deletions

View File

@@ -3,31 +3,66 @@ on:
push:
branches:
- main
# Build-only (no push) on PRs that touch the build/deploy pipeline, so
# Dockerfile / workflow changes are validated before they reach main.
pull_request:
paths:
- 'docker/**'
- '.github/workflows/build_n_push.yml'
- 'next.config.mjs'
- 'package-lock.json'
workflow_dispatch:
jobs:
docs_build_n_push:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
-
name: Docker meta
- uses: actions/checkout@v4
with:
# Full history so gen:last-updated / gen:sitemap can read real
# per-file commit dates (a shallow clone would yield wrong dates).
fetch-depth: 0
- uses: actions/setup-node@v4
with:
node-version: '20'
cache: 'npm'
- name: Install dependencies
run: npm ci
- name: Restore Next.js build cache
uses: actions/cache@v4
with:
path: .next/cache
key: ${{ runner.os }}-nextjs-${{ hashFiles('package-lock.json') }}-${{ hashFiles('src/**', 'mdx/**', 'next.config.mjs') }}
restore-keys: |
${{ runner.os }}-nextjs-${{ hashFiles('package-lock.json') }}-
- name: Build
run: npm run build
- name: Docker meta
id: meta
uses: docker/metadata-action@v3
uses: docker/metadata-action@v5
with:
images: netbirdio/docs.netbird.io
-
name: Login to DockerHub
- name: Login to DockerHub
if: github.event_name != 'pull_request'
uses: docker/login-action@v1
uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKER_USER }}
password: ${{ secrets.DOCKER_TOKEN }}
-
name: Docker build and push
uses: docker/build-push-action@v2
- name: Docker build and push
uses: docker/build-push-action@v6
with:
context: .
file: docker/Dockerfile
push: ${{ github.event_name != 'pull_request' }}
# Keep a single-arch manifest (no attestation index) so the server's
# `docker compose pull` stays happy.
provenance: false
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}