Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ copy-page feature copies MDX source rather than a clean Markdown rendering.
[Next.js static export](https://nextjs.org/docs/pages/guides/static-exports)
does not support a runtime API route or rewrite for this purpose. A pre-build
projection into `public/` gives local development, static export, GitHub Pages,
and Nginx the same files.
and the container server the same files.

Re-evaluate this decision only during an intentional framework migration.
Require the replacement to support clean Markdown, exact `.md` paths, static
Expand Down Expand Up @@ -96,10 +96,10 @@ edit `public/llms.txt` directly.
## Deployment

Next.js copies generated files from `public/` to `out/`. GitHub Pages serves
them from the static export. The repository Nginx configuration gives `.md`
files the `text/markdown; charset=utf-8` media type and returns 404 for a
missing `.md` path. Its HTML fallback checks `$uri.html` before `$uri`. This
order prevents a page asset directory, such as `/docs/guide/`, from hiding the
them from the static export. The container image serves `out/` with
`server.mjs`. It gives `.md` files the `text/markdown; charset=utf-8` media
type and returns 404 for a missing `.md` path. Its HTML fallback checks
`<route>.html` before `<route>`. This order prevents a page asset directory, such as `/docs/guide/`, from hiding the
exported `/docs/guide.html` page.

After a deployment-path or asset-path change, use the production server
Expand Down
8 changes: 8 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
node_modules
.next
out
.claude
.husky
.git
Dockerfile
.dockerignore
19 changes: 18 additions & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,23 @@ jobs:
- name: Setup Bun
uses: oven-sh/setup-bun@v2
with:
bun-version: 1.2.8
bun-version: 1.4.4
- run: bun install --frozen-lockfile
- run: bun run verify

image:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v4
- name: Build image
run: docker build -t lifecycle-docs:ci .
- name: Smoke test image
run: scripts/smokeImage.sh lifecycle-docs:ci
# Fails only on High/Critical findings that already have a fixed release; unfixed upstream
# advisories are reported but do not block.
- name: Scan image for fixable vulnerabilities
run: |
docker run --rm -v /var/run/docker.sock:/var/run/docker.sock \
anchore/grype:v0.121.0 docker:lifecycle-docs:ci \
--only-fixed --fail-on high
2 changes: 1 addition & 1 deletion .github/workflows/deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ jobs:
- name: Setup Bun
uses: oven-sh/setup-bun@v2
with:
bun-version: 1.2.8
bun-version: 1.4.4

- name: Install dependencies
run: bun install --frozen-lockfile
Expand Down
29 changes: 17 additions & 12 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -12,25 +12,30 @@
# See the License for the specific language governing permissions and
# limitations under the License.

# Stage 1: Build the Nextra app with secrets injection
FROM oven/bun:1.2.8 AS builder
FROM oven/bun:1.4.4-alpine@sha256:4cf82f5686b196504fe119db3fcd9185b191f82ece82c40680e597228ec6070a AS builder
WORKDIR /app

# Copy dependency files
COPY package*.json bun.lock* ./
RUN bun install
COPY package.json bun.lock ./
RUN bun install --frozen-lockfile

COPY . .

RUN bun run build

FROM nginx:1.31.7-alpine
WORKDIR /usr/share/nginx/html
FROM node:24.22.3-alpine3.24@sha256:116b800c3754b440ee0aa3ed2f20f5bf3d99a554bfd9adeea09ea8017f6e85f5

COPY --from=builder /app/out /usr/share/nginx/html
# The runtime only needs the node binary; npm and yarn ship with the base image and carry their own CVEs.
RUN apk upgrade --no-cache \
&& rm -rf /usr/local/lib/node_modules /usr/local/bin/npm /usr/local/bin/npx \
/usr/local/bin/corepack /usr/local/bin/yarn /usr/local/bin/yarnpkg /opt/yarn-*

COPY default.conf /etc/nginx/conf.d/default.conf
WORKDIR /app
COPY --chown=node:node server.mjs ./
COPY --from=builder --chown=node:node /app/out ./public

EXPOSE 80
ENV NODE_ENV=production \
PORT=8080 \
STATIC_ROOT=/app/public
USER node
EXPOSE 8080

CMD ["nginx", "-g", "daemon off;"]
CMD ["node", "server.mjs"]
30 changes: 0 additions & 30 deletions default.conf

This file was deleted.

1 change: 1 addition & 0 deletions eslint.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ export default [
},
},
},
{ files: ["server.mjs"], languageOptions: { globals: globals.node } },
pluginJs.configs.recommended,
...tseslint.configs.recommended,
pluginReact.configs.flat.recommended,
Expand Down
8 changes: 4 additions & 4 deletions helm/values/app.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ ports:
protocol: TCP
servicePort: 80

containerPort: 80
containerPort: 8080

service:
enabled: true
Expand Down Expand Up @@ -65,15 +65,15 @@ deployment:
httpGet:
scheme: HTTP
path: /
port: 80
port: 8080

readinessProbe:
periodSeconds: 10
failureThreshold: 3
httpGet:
scheme: HTTP
path: /
port: 80
port: 8080

livenessProbe:
periodSeconds: 60
Expand All @@ -82,7 +82,7 @@ deployment:
httpGet:
scheme: HTTP
path: /
port: 80
port: 8080

# Slowly rollout new pods during a deployment to
# prevent too many being unavailable at any given time
Expand Down
78 changes: 78 additions & 0 deletions scripts/smokeImage.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
#!/usr/bin/env bash
# Copyright 2026 GoodRx, Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

# Runs the built docs image and checks the routing contract the deployment depends on.
# Usage: scripts/smokeImage.sh <image> [host-port]
set -euo pipefail

image="${1:?usage: smokeImage.sh <image> [host-port]}"
port="${2:-18080}"
name="lifecycle-docs-smoke-$$"
base="http://127.0.0.1:${port}"
failures=0

cleanup() { docker rm -f "$name" >/dev/null 2>&1 || true; }
trap cleanup EXIT

docker run -d --name "$name" -p "127.0.0.1:${port}:8080" "$image" >/dev/null

for _ in $(seq 1 30); do
curl -fs -o /dev/null "$base/" && break
sleep 1
done

check() {
local path="$1" want_status="$2" want_type="$3"
local got
got="$(curl -s --path-as-is -o /dev/null -w '%{http_code} %{content_type}' "$base$path")"
if [[ "$got" == "$want_status $want_type"* ]]; then
echo "ok $path -> $got"
else
echo "FAIL $path -> $got (want $want_status $want_type)"
failures=$((failures + 1))
fi
}

check "/" 200 "text/html"
check "/docs" 200 "text/html"
check "/docs.md" 200 "text/markdown; charset=utf-8"
check "/llms.txt" 200 "text/plain"
check "/docs/does-not-exist.md" 404 "text/html"
check "/docs/cm" 404 "text/html"
check "/docs//cm" 404 "text/html"
check "/_next/static/does-not-exist.js" 404 "text/html"
check "/unknown/client/route" 200 "text/html"

asset="$(curl -s "$base/" | grep -oE '/_next/static/[^"]+\.js' | head -n 1)"
check "$asset" 200 "text/javascript"

user="$(docker inspect --format '{{.Config.User}}' "$image")"
if [[ -z "$user" || "$user" == "root" || "$user" == "0" ]]; then
echo "FAIL image runs as root"
failures=$((failures + 1))
fi

docker stop -t 10 "$name" >/dev/null
exit_code="$(docker inspect --format '{{.State.ExitCode}}' "$name")"
if [[ "$exit_code" != "0" ]]; then
echo "FAIL container exited with $exit_code on SIGTERM"
failures=$((failures + 1))
fi

if ((failures > 0)); then
docker logs "$name" || true
exit 1
fi
echo "image smoke test passed"
92 changes: 0 additions & 92 deletions scripts/validateDocs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,6 @@ type ImageDimensions = {

const SCREENSHOT_CATALOG =
".agents/skills/update-lifecycle-docs/references/screenshots.md";
const RAW_MARKDOWN_SERVER_CONFIG = "default.conf";
const RASTER_EXTENSIONS = new Set([".gif", ".jpeg", ".jpg", ".png", ".webp"]);
const NON_SCREENSHOT_RASTERS = new Set(["/logo.png"]);
const SCREENSHOT_STATUSES = new Set(["keep", "remove", "replace"]);
Expand Down Expand Up @@ -267,96 +266,6 @@ function context(rootDir: string): ValidationContext {
};
}

export async function validateRawMarkdownDelivery({
rootDir = process.cwd(),
}: ValidationOptions = {}): Promise<ValidationIssue[]> {
const resolvedRoot = path.resolve(rootDir);
const configPath = path.join(resolvedRoot, RAW_MARKDOWN_SERVER_CONFIG);
let source: string;
try {
source = await fs.promises.readFile(configPath, "utf8");
} catch (error) {
return [
{
file: RAW_MARKDOWN_SERVER_CONFIG,
message: `raw Markdown server configuration is unavailable: ${
error instanceof Error ? error.message.split("\n")[0] : String(error)
}`,
},
];
}

const location = source.match(
/location\s+~\s+\\\.md\$\s*\{([\s\S]*?)^\s*\}/m,
)?.[1];
if (!location) {
return [
{
file: RAW_MARKDOWN_SERVER_CONFIG,
message: "raw Markdown requires a dedicated .md location",
},
];
}

const issues: ValidationIssue[] = [];
if (!/\btypes\s*\{\s*\}/.test(location)) {
issues.push({
file: RAW_MARKDOWN_SERVER_CONFIG,
message:
"raw Markdown must clear inherited MIME mappings before setting its UTF-8 media type",
});
}
if (
!/\bdefault_type\s+["']text\/markdown;\s*charset=utf-8["']\s*;/i.test(
location,
)
) {
issues.push({
file: RAW_MARKDOWN_SERVER_CONFIG,
message:
'raw Markdown must use Content-Type "text/markdown; charset=utf-8"',
});
}
if (!/\btry_files\s+\$uri\s+=404\s*;/.test(location)) {
issues.push({
file: RAW_MARKDOWN_SERVER_CONFIG,
message:
"raw Markdown must return 404 for a missing file instead of the HTML fallback",
});
}
const retiredRouteLocations = [
/location\s*=\s*\/docs\/cm\s*\{\s*return\s+404\s*;\s*\}/,
/location\s*=\s*\/docs\/cm\.md\s*\{\s*return\s+404\s*;\s*\}/,
/location\s+\^~\s+\/docs\/cm\/\s*\{\s*return\s+404\s*;\s*\}/,
];
if (retiredRouteLocations.some((pattern) => !pattern.test(source))) {
issues.push({
file: RAW_MARKDOWN_SERVER_CONFIG,
message: "retired /docs/cm routes must return 404",
});
}
if (!/\berror_page\s+404\s+\/404\.html\s*;/.test(source)) {
issues.push({
file: RAW_MARKDOWN_SERVER_CONFIG,
message: "404 responses must use the exported 404 page",
});
}
const htmlLocation = source.match(/location\s+\/\s*\{([\s\S]*?)^\s*\}/m)?.[1];
if (
!htmlLocation ||
!/\btry_files\s+\$uri\.html\s+\$uri(?:\s+\$uri\/)?\s+\/index\.html\s*;/.test(
htmlLocation,
)
) {
issues.push({
file: RAW_MARKDOWN_SERVER_CONFIG,
message:
"HTML routes must prefer the exported .html file before a same-name asset directory",
});
}
return issues;
}

function routeFor(rootDir: string, file: string): string {
const relative = path
.relative(path.join(rootDir, "src/pages"), file)
Expand Down Expand Up @@ -1166,7 +1075,6 @@ export async function validateDocs({
}

issues.push(...(await validatePortableGuidance({ rootDir })));
issues.push(...(await validateRawMarkdownDelivery({ rootDir })));
return issues;
}

Expand Down
Loading
Loading