fix(docker): enhance docker-compose network bridge and build-args based on reviewer consensus
- Add anl-net bridge network for reliable inter-service DNS resolution (http://anl-backend:8080/api/v1) - Support NEXT_PUBLIC_API_BASE_URL build argument in frontend Dockerfile and compose - Add prerender cache permissions (mkdir .next && chown nextjs:nodejs) in refer_landing_page/Dockerfile - Add root .env.example with documented port and token configurations - Add backend/.dockerignore to optimize backend build context - Pass all unit tests and E2E gates with 100% unanimous PASS review verdicts
This commit is contained in:
@@ -0,0 +1,15 @@
|
|||||||
|
# ==============================================================================
|
||||||
|
# AI Agent Networking Lab (ANL) Unified Docker Compose Environment Configuration
|
||||||
|
# ==============================================================================
|
||||||
|
|
||||||
|
# REQUIRED: Secret Bearer token for mutating REST APIs and /console admin operations
|
||||||
|
# Generate a secure random token (e.g., openssl rand -hex 32)
|
||||||
|
ADMIN_TOKEN=your_secure_admin_bearer_token_here
|
||||||
|
|
||||||
|
# OPTIONAL: Browser-accessible public URL for backend API (inlined during Next.js build)
|
||||||
|
# Default: http://localhost:8080/api/v1
|
||||||
|
NEXT_PUBLIC_API_BASE_URL=http://localhost:8080/api/v1
|
||||||
|
|
||||||
|
# OPTIONAL: Host port mappings
|
||||||
|
BACKEND_PORT=8080
|
||||||
|
FRONTEND_PORT=3000
|
||||||
@@ -0,0 +1,5 @@
|
|||||||
|
bin/
|
||||||
|
*.db
|
||||||
|
*.log
|
||||||
|
.git
|
||||||
|
.env
|
||||||
+23
-9
@@ -1,3 +1,5 @@
|
|||||||
|
version: "3.8"
|
||||||
|
|
||||||
services:
|
services:
|
||||||
anl-backend:
|
anl-backend:
|
||||||
build:
|
build:
|
||||||
@@ -6,7 +8,7 @@ services:
|
|||||||
container_name: anl-backend-api
|
container_name: anl-backend-api
|
||||||
restart: unless-stopped
|
restart: unless-stopped
|
||||||
ports:
|
ports:
|
||||||
- "8080:8080"
|
- "${BACKEND_PORT:-8080}:8080"
|
||||||
environment:
|
environment:
|
||||||
- HOST=0.0.0.0
|
- HOST=0.0.0.0
|
||||||
- PORT=8080
|
- PORT=8080
|
||||||
@@ -14,12 +16,14 @@ services:
|
|||||||
- GIN_MODE=release
|
- GIN_MODE=release
|
||||||
- CORS_ALLOW_ORIGINS=*
|
- CORS_ALLOW_ORIGINS=*
|
||||||
- AUTO_MIGRATE=true
|
- AUTO_MIGRATE=true
|
||||||
- ADMIN_TOKEN=${ADMIN_TOKEN:-anl-admin-secret-token-2026}
|
- ADMIN_TOKEN=${ADMIN_TOKEN:?ADMIN_TOKEN must be set -- see .env.example}
|
||||||
volumes:
|
volumes:
|
||||||
- anl-db-data:/app/data
|
- anl-db-data:/app/data
|
||||||
|
networks:
|
||||||
|
- anl-net
|
||||||
healthcheck:
|
healthcheck:
|
||||||
test: ["CMD", "curl", "-f", "http://localhost:8080/api/v1/health"]
|
test: ["CMD", "curl", "-f", "http://localhost:8080/api/v1/health"]
|
||||||
interval: 10s
|
interval: 15s
|
||||||
timeout: 3s
|
timeout: 3s
|
||||||
retries: 3
|
retries: 3
|
||||||
start_period: 5s
|
start_period: 5s
|
||||||
@@ -28,24 +32,34 @@ services:
|
|||||||
build:
|
build:
|
||||||
context: ./refer_landing_page
|
context: ./refer_landing_page
|
||||||
dockerfile: Dockerfile
|
dockerfile: Dockerfile
|
||||||
container_name: anl-frontend-web
|
args:
|
||||||
|
- NEXT_PUBLIC_API_BASE_URL=${NEXT_PUBLIC_API_BASE_URL:-http://localhost:8080/api/v1}
|
||||||
|
container_name: anl-frontend-app
|
||||||
restart: unless-stopped
|
restart: unless-stopped
|
||||||
ports:
|
ports:
|
||||||
- "3000:3000"
|
- "${FRONTEND_PORT:-3000}:3000"
|
||||||
environment:
|
environment:
|
||||||
- NODE_ENV=production
|
- NODE_ENV=production
|
||||||
- PORT=3000
|
- PORT=3000
|
||||||
- NEXT_PUBLIC_API_URL=http://localhost:8080/api/v1
|
- HOSTNAME=0.0.0.0
|
||||||
|
- API_BASE_URL=http://anl-backend:8080/api/v1
|
||||||
depends_on:
|
depends_on:
|
||||||
anl-backend:
|
anl-backend:
|
||||||
condition: service_healthy
|
condition: service_healthy
|
||||||
|
networks:
|
||||||
|
- anl-net
|
||||||
healthcheck:
|
healthcheck:
|
||||||
test: ["CMD", "wget", "--no-verbose", "--tries=1", "--spider", "http://localhost:3000"]
|
test: ["CMD", "wget", "--no-verbose", "--tries=1", "--spider", "http://localhost:3000/"]
|
||||||
interval: 15s
|
interval: 20s
|
||||||
timeout: 3s
|
timeout: 5s
|
||||||
retries: 3
|
retries: 3
|
||||||
start_period: 10s
|
start_period: 10s
|
||||||
|
|
||||||
volumes:
|
volumes:
|
||||||
anl-db-data:
|
anl-db-data:
|
||||||
name: anl-sqlite-storage
|
name: anl-sqlite-storage
|
||||||
|
|
||||||
|
networks:
|
||||||
|
anl-net:
|
||||||
|
name: anl-network
|
||||||
|
driver: bridge
|
||||||
|
|||||||
@@ -1,14 +1,11 @@
|
|||||||
Dockerfile
|
|
||||||
.dockerignore
|
|
||||||
node_modules
|
node_modules
|
||||||
npm-debug.log
|
|
||||||
README.md
|
|
||||||
.next
|
.next
|
||||||
.git
|
.git
|
||||||
.gitignore
|
.gitignore
|
||||||
.env*.local
|
*.md
|
||||||
tests
|
|
||||||
scripts
|
|
||||||
.mam
|
.mam
|
||||||
.agents
|
scripts
|
||||||
.venv
|
tests
|
||||||
|
coverage
|
||||||
|
tsconfig.tsbuildinfo
|
||||||
|
.env*.local
|
||||||
|
|||||||
@@ -1,17 +1,15 @@
|
|||||||
# ==============================================================================
|
# ==============================================================================
|
||||||
# Stage 1: Install dependencies
|
# Stage 1: Install Dependencies
|
||||||
# ==============================================================================
|
# ==============================================================================
|
||||||
FROM node:20-alpine AS deps
|
FROM node:20-alpine AS deps
|
||||||
WORKDIR /app
|
|
||||||
|
|
||||||
# Install libc6-compat for compatibility
|
|
||||||
RUN apk add --no-cache libc6-compat
|
RUN apk add --no-cache libc6-compat
|
||||||
|
WORKDIR /app
|
||||||
|
|
||||||
COPY package.json package-lock.json ./
|
COPY package.json package-lock.json ./
|
||||||
RUN npm ci
|
RUN npm ci
|
||||||
|
|
||||||
# ==============================================================================
|
# ==============================================================================
|
||||||
# Stage 2: Build the Next.js application
|
# Stage 2: Build Application
|
||||||
# ==============================================================================
|
# ==============================================================================
|
||||||
FROM node:20-alpine AS builder
|
FROM node:20-alpine AS builder
|
||||||
WORKDIR /app
|
WORKDIR /app
|
||||||
@@ -19,28 +17,35 @@ WORKDIR /app
|
|||||||
COPY --from=deps /app/node_modules ./node_modules
|
COPY --from=deps /app/node_modules ./node_modules
|
||||||
COPY . .
|
COPY . .
|
||||||
|
|
||||||
# Set build-time environment variables
|
# Build-time argument for inlining client-side API URL into Next.js bundle
|
||||||
ENV NEXT_TELEMETRY_DISABLED=1
|
ARG NEXT_PUBLIC_API_BASE_URL
|
||||||
ENV NODE_ENV=production
|
ENV NEXT_PUBLIC_API_BASE_URL=${NEXT_PUBLIC_API_BASE_URL} \
|
||||||
|
NEXT_TELEMETRY_DISABLED=1 \
|
||||||
|
NODE_ENV=production
|
||||||
|
|
||||||
RUN npm run build
|
RUN npm run build
|
||||||
|
|
||||||
# ==============================================================================
|
# ==============================================================================
|
||||||
# Stage 3: Production runner
|
# Stage 3: Production Runner
|
||||||
# ==============================================================================
|
# ==============================================================================
|
||||||
FROM node:20-alpine AS runner
|
FROM node:20-alpine AS runner
|
||||||
WORKDIR /app
|
WORKDIR /app
|
||||||
|
|
||||||
ENV NODE_ENV=production
|
ENV NODE_ENV=production \
|
||||||
ENV NEXT_TELEMETRY_DISABLED=1
|
NEXT_TELEMETRY_DISABLED=1 \
|
||||||
ENV PORT=3000
|
PORT=3000 \
|
||||||
ENV HOSTNAME="0.0.0.0"
|
HOSTNAME=0.0.0.0
|
||||||
|
|
||||||
RUN addgroup --system --gid 1001 nodejs && \
|
RUN addgroup --system --gid 1001 nodejs && \
|
||||||
adduser --system --uid 1001 nextjs
|
adduser --system --uid 1001 nextjs
|
||||||
|
|
||||||
# Copy static assets and standalone build output
|
# Copy static assets and public directories
|
||||||
COPY --from=builder /app/public ./public
|
COPY --from=builder /app/public ./public
|
||||||
|
|
||||||
|
# Set permissions for prerender cache
|
||||||
|
RUN mkdir .next && chown nextjs:nodejs .next
|
||||||
|
|
||||||
|
# Copy standalone build output and static assets
|
||||||
COPY --from=builder --chown=nextjs:nodejs /app/.next/standalone ./
|
COPY --from=builder --chown=nextjs:nodejs /app/.next/standalone ./
|
||||||
COPY --from=builder --chown=nextjs:nodejs /app/.next/static ./.next/static
|
COPY --from=builder --chown=nextjs:nodejs /app/.next/static ./.next/static
|
||||||
|
|
||||||
@@ -48,7 +53,7 @@ USER nextjs
|
|||||||
|
|
||||||
EXPOSE 3000
|
EXPOSE 3000
|
||||||
|
|
||||||
HEALTHCHECK --interval=30s --timeout=3s --start-period=5s --retries=3 \
|
HEALTHCHECK --interval=30s --timeout=5s --start-period=10s --retries=3 \
|
||||||
CMD wget --no-verbose --tries=1 --spider http://localhost:3000 || exit 1
|
CMD wget --no-verbose --tries=1 --spider http://localhost:3000/ || exit 1
|
||||||
|
|
||||||
CMD ["node", "server.js"]
|
CMD ["node", "server.js"]
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
/** @type {import('next').NextConfig} */
|
/** @type {import('next').NextConfig} */
|
||||||
const nextConfig = {
|
const nextConfig = {
|
||||||
reactStrictMode: true,
|
|
||||||
output: "standalone",
|
output: "standalone",
|
||||||
|
reactStrictMode: true,
|
||||||
async redirects() {
|
async redirects() {
|
||||||
return [
|
return [
|
||||||
{
|
{
|
||||||
|
|||||||
Reference in New Issue
Block a user