Skip to content

Commit 46ffeab

Browse files
committed
Add build metadata to Docker setup and create dynamic route for version info
1 parent 3924587 commit 46ffeab

4 files changed

Lines changed: 31 additions & 0 deletions

File tree

Dockerfile

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66
# This Dockerfile uses Node.js 24.13.0-slim, which was the latest LTS version at the time of writing.
77
# To ensure security and compatibility, regularly update the NODE_VERSION ARG to the latest LTS version.
88
ARG NODE_VERSION=24.13.0-slim
9+
ARG GIT_SHA=unknown
10+
ARG BUILD_TIMESTAMP=unknown
911

1012
FROM node:${NODE_VERSION} AS dependencies
1113

@@ -73,13 +75,18 @@ RUN if [ -f package-lock.json ]; then \
7375

7476
FROM node:${NODE_VERSION} AS runner
7577

78+
ARG GIT_SHA
79+
ARG BUILD_TIMESTAMP
80+
7681
# Set working directory
7782
WORKDIR /app
7883

7984
# Set production environment variables
8085
ENV NODE_ENV=production
8186
ENV PORT=3000
8287
ENV HOSTNAME="0.0.0.0"
88+
ENV APP_GIT_SHA=${GIT_SHA}
89+
ENV APP_BUILD_TIMESTAMP=${BUILD_TIMESTAMP}
8390

8491
# Advertise the internal application port for platforms that auto-detect it.
8592
EXPOSE 3000

Dockerfile.bun

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,13 +48,18 @@ RUN bun run build
4848

4949
FROM oven/bun:1 AS runner
5050

51+
ARG GIT_SHA=unknown
52+
ARG BUILD_TIMESTAMP=unknown
53+
5154
# Set working directory
5255
WORKDIR /app
5356

5457
# Set production environment variables
5558
ENV NODE_ENV=production
5659
ENV PORT=3000
5760
ENV HOSTNAME="0.0.0.0"
61+
ENV APP_GIT_SHA=${GIT_SHA}
62+
ENV APP_BUILD_TIMESTAMP=${BUILD_TIMESTAMP}
5863

5964
# Advertise the internal application port for platforms that auto-detect it.
6065
EXPOSE 3000

docker-compose.yml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@ services:
44
build:
55
context: .
66
dockerfile: Dockerfile.bun
7+
args:
8+
GIT_SHA: ${GIT_SHA:-unknown}
9+
BUILD_TIMESTAMP: ${BUILD_TIMESTAMP:-unknown}
710
pull_policy: build
811
image: nextjs-standalone-bun-image
912
container_name: nextjs-standalone-bun-container
@@ -19,6 +22,9 @@ services:
1922
build:
2023
context: .
2124
dockerfile: Dockerfile
25+
args:
26+
GIT_SHA: ${GIT_SHA:-unknown}
27+
BUILD_TIMESTAMP: ${BUILD_TIMESTAMP:-unknown}
2228
pull_policy: build
2329
image: nextjs-standalone-image
2430
container_name: nextjs-standalone-container

src/app/api/version/route.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
import { NextResponse } from "next/server";
2+
import { CURRENT_VERSION } from "@/lib/changelog";
3+
4+
export const dynamic = "force-dynamic";
5+
6+
export async function GET() {
7+
return NextResponse.json({
8+
appVersion: CURRENT_VERSION,
9+
gitSha: process.env.APP_GIT_SHA ?? "unknown",
10+
buildTimestamp: process.env.APP_BUILD_TIMESTAMP ?? "unknown",
11+
nodeEnv: process.env.NODE_ENV ?? "unknown",
12+
});
13+
}

0 commit comments

Comments
 (0)