mirror of
https://github.com/netbirdio/docs.git
synced 2026-10-01 19:29:05 +02:00
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:
+8
-3
@@ -1,10 +1,15 @@
|
|||||||
.git/
|
.git/
|
||||||
.gitignore
|
.gitignore
|
||||||
.next/ # Existing Next.js builds
|
|
||||||
.dockerignore
|
.dockerignore
|
||||||
Dockerfile
|
Dockerfile
|
||||||
docker-compose.yml
|
docker-compose.yml
|
||||||
node_modules/ # Installed inside container
|
|
||||||
LICENSE
|
LICENSE
|
||||||
README.md
|
README.md
|
||||||
AUTHORS
|
AUTHORS
|
||||||
|
|
||||||
|
# Reinstalled inside the image (alpine-native — avoids a glibc/musl mismatch)
|
||||||
|
node_modules/
|
||||||
|
|
||||||
|
# The built .next output is copied in (built on the CI runner, see
|
||||||
|
# build_n_push.yml); only the build cache is excluded — it is not served.
|
||||||
|
.next/cache/
|
||||||
|
|||||||
@@ -3,31 +3,66 @@ on:
|
|||||||
push:
|
push:
|
||||||
branches:
|
branches:
|
||||||
- main
|
- 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:
|
workflow_dispatch:
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
docs_build_n_push:
|
docs_build_n_push:
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v2
|
- uses: actions/checkout@v4
|
||||||
-
|
with:
|
||||||
name: Docker meta
|
# 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
|
id: meta
|
||||||
uses: docker/metadata-action@v3
|
uses: docker/metadata-action@v5
|
||||||
with:
|
with:
|
||||||
images: netbirdio/docs.netbird.io
|
images: netbirdio/docs.netbird.io
|
||||||
-
|
|
||||||
name: Login to DockerHub
|
- name: Login to DockerHub
|
||||||
if: github.event_name != 'pull_request'
|
if: github.event_name != 'pull_request'
|
||||||
uses: docker/login-action@v1
|
uses: docker/login-action@v3
|
||||||
with:
|
with:
|
||||||
username: ${{ secrets.DOCKER_USER }}
|
username: ${{ secrets.DOCKER_USER }}
|
||||||
password: ${{ secrets.DOCKER_TOKEN }}
|
password: ${{ secrets.DOCKER_TOKEN }}
|
||||||
-
|
|
||||||
name: Docker build and push
|
- name: Docker build and push
|
||||||
uses: docker/build-push-action@v2
|
uses: docker/build-push-action@v6
|
||||||
with:
|
with:
|
||||||
|
context: .
|
||||||
file: docker/Dockerfile
|
file: docker/Dockerfile
|
||||||
push: ${{ github.event_name != 'pull_request' }}
|
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 }}
|
tags: ${{ steps.meta.outputs.tags }}
|
||||||
labels: ${{ steps.meta.outputs.labels }}
|
labels: ${{ steps.meta.outputs.labels }}
|
||||||
|
|||||||
+4
-5
@@ -10,17 +10,16 @@ RUN npm install --global pm2
|
|||||||
# Utilise Docker cache to save re-installing dependencies if unchanged
|
# Utilise Docker cache to save re-installing dependencies if unchanged
|
||||||
COPY ./package*.json ./
|
COPY ./package*.json ./
|
||||||
|
|
||||||
# Install dependencies (npm ci = clean, reproducible install from the lockfile)
|
# Install runtime dependencies (npm ci = clean, reproducible install from the lockfile)
|
||||||
RUN npm ci --omit=dev
|
RUN npm ci --omit=dev
|
||||||
|
|
||||||
# Copy all files
|
# Copy the app, including the prebuilt .next output. The build now runs on the
|
||||||
|
# CI runner (see .github/workflows/build_n_push.yml) with a warm .next/cache,
|
||||||
|
# so there is no `npm run build` step here — we only package the result.
|
||||||
COPY ./ ./
|
COPY ./ ./
|
||||||
|
|
||||||
COPY /docker/entrypoint.sh ./entrypoint.sh
|
COPY /docker/entrypoint.sh ./entrypoint.sh
|
||||||
|
|
||||||
# Build app
|
|
||||||
RUN npm run build
|
|
||||||
|
|
||||||
RUN chmod u+x /usr/app/entrypoint.sh
|
RUN chmod u+x /usr/app/entrypoint.sh
|
||||||
|
|
||||||
# Expose the listening port
|
# Expose the listening port
|
||||||
|
|||||||
+13
-2
@@ -32,13 +32,24 @@ let _dateMapCache
|
|||||||
* repo-relative with forward slashes, matching path.relative(repoRoot, file).
|
* repo-relative with forward slashes, matching path.relative(repoRoot, file).
|
||||||
*
|
*
|
||||||
* Returns an empty map if git is unavailable (e.g. inside the Docker image,
|
* Returns an empty map if git is unavailable (e.g. inside the Docker image,
|
||||||
* which has no git binary); callers then fall back to no date, exactly as the
|
* which has no git binary) or the checkout is shallow; callers then fall back
|
||||||
* per-file getGitLastModified() did.
|
* to no date, exactly as the per-file getGitLastModified() did.
|
||||||
*/
|
*/
|
||||||
export function buildGitDateMap() {
|
export function buildGitDateMap() {
|
||||||
if (_dateMapCache) return _dateMapCache
|
if (_dateMapCache) return _dateMapCache
|
||||||
const map = new Map()
|
const map = new Map()
|
||||||
try {
|
try {
|
||||||
|
// On a shallow clone (e.g. actions/checkout without fetch-depth: 0) git log
|
||||||
|
// only sees the fetched commits, so every file would report the same wrong
|
||||||
|
// date. Emit no dates rather than wrong ones.
|
||||||
|
const shallow = execSync('git rev-parse --is-shallow-repository', {
|
||||||
|
encoding: 'utf-8',
|
||||||
|
stdio: ['pipe', 'pipe', 'ignore'],
|
||||||
|
}).trim()
|
||||||
|
if (shallow === 'true') {
|
||||||
|
_dateMapCache = map
|
||||||
|
return map
|
||||||
|
}
|
||||||
// core.quotePath=false keeps non-ASCII paths unquoted so line parsing is safe.
|
// core.quotePath=false keeps non-ASCII paths unquoted so line parsing is safe.
|
||||||
const out = execSync(
|
const out = execSync(
|
||||||
'git -c core.quotePath=false log --format=%cI --name-only',
|
'git -c core.quotePath=false log --format=%cI --name-only',
|
||||||
|
|||||||
Reference in New Issue
Block a user