HL7v2/packages/server/Containerfile
2025-07-30 12:04:29 +02:00

61 lines
1.7 KiB
Docker

# Stage 1: Builder
# This stage installs all dependencies and builds all packages.
FROM oven/bun:1 AS builder
WORKDIR /app
# Copy dependency manifests
COPY package.json bun.lock ./
COPY tsconfig.base.json ./
# Copy package-specific manifests to leverage Docker cache
COPY packages/shared/package.json packages/shared/tsconfig.json ./packages/shared/
COPY packages/server/package.json packages/server/tsconfig.json ./packages/server/
# Install ALL workspace dependencies
RUN bun install
# Copy source code
COPY packages/shared ./packages/shared/
COPY packages/server ./packages/server/
# Build the server and its dependencies (i.e., 'shared')
RUN bun run --filter=@hnu.de/hl7v2-shared build
RUN bun run --filter=@hnu.de/hl7v2-server build
#---------------------------------------------------------------------
# Stage 2: Production
FROM oven/bun:1-slim
WORKDIR /app
# Create the full directory structure first
RUN mkdir -p packages/shared packages/server
# Copy workspace configuration
COPY --from=builder /app/package.json /app/bun.lock ./
# Set up shared package with its dist directory
COPY --from=builder /app/packages/shared/package.json ./packages/shared/
COPY --from=builder /app/packages/shared/dist ./packages/shared/dist
# Set up server package with its dist directory
COPY --from=builder /app/packages/server/package.json ./packages/server/
COPY --from=builder /app/packages/server/dist ./packages/server/dist
# Install ONLY production dependencies
ENV NODE_ENV=production
RUN bun install \
--frozen-lockfile \
--production
# Set environment variables from config.ts
ENV PORT=8080 \
PREFIXES=STA \
POOL_SIZE=100
EXPOSE 8080
# Run the server from its package directory
WORKDIR /app/packages/server
CMD ["bun", "run", "dist/index.js"]