ci(global): go through and make sure all related files are working and good to go

This commit is contained in:
2026-04-08 03:04:58 +00:00
parent 546bf65b8b
commit e88d21fa35
13 changed files with 584 additions and 145 deletions
+79 -28
View File
@@ -1,9 +1,20 @@
# ---- Stage 1: Install dependencies ----
# =============================================================================
# Build context: monorepo root (.)
# This Dockerfile is built with `docker build -f api/Dockerfile .` from root.
# =============================================================================
# ---- Stage 1: Install production dependencies ----
FROM oven/bun:1 AS deps
WORKDIR /app
# Copy root workspace manifest and lockfile
COPY package.json bun.lock ./
# Copy workspace package manifests (source not needed — just for bun workspace resolution)
COPY api/package.json ./api/package.json
COPY dalpuri/package.json ./dalpuri/package.json
RUN bun install --frozen-lockfile --production
# ---- Stage 2: Build ----
@@ -11,27 +22,51 @@ FROM oven/bun:1 AS build
WORKDIR /app
# Copy dependency manifests and install all deps (including dev)
# Copy root workspace manifest and lockfile, plus workspace package manifests
COPY package.json bun.lock ./
COPY api/package.json ./api/package.json
COPY dalpuri/package.json ./dalpuri/package.json
# Install all deps (including dev) for the full workspace
RUN bun install --frozen-lockfile
# Copy source code and supporting files
COPY src/ src/
COPY prisma/ prisma/
COPY prisma.config.ts tsconfig.json ./
# Copy API source and config
COPY api/src/ ./api/src/
COPY api/prisma/ ./api/prisma/
COPY api/prisma.config.ts api/tsconfig.json ./api/
COPY api/logo.png ./api/logo.png
# Generate Prisma client (dummy URL — generate only needs the schema, not a real DB)
# Copy Dalpuri source and Prisma schema
COPY dalpuri/src/ ./dalpuri/src/
COPY dalpuri/prisma/ ./dalpuri/prisma/
COPY dalpuri/prisma.config.ts ./dalpuri/prisma.config.ts
# Generate Dalpuri Prisma client (ConnectWise MSSQL schema)
# prisma generate does not connect — dummy URL just satisfies the env requirement
WORKDIR /app/dalpuri
RUN DATABASE_URL="sqlserver://localhost:1433;database=dummy;user=dummy;password=dummy;trustServerCertificate=true" \
bunx prisma generate
# Generate API Prisma client (PostgreSQL schema)
WORKDIR /app/api
RUN DATABASE_URL="postgresql://dummy:dummy@localhost:5432/dummy" bunx prisma generate
# Compile to a standalone executable
# Compile the API server to a standalone binary
RUN NODE_ENV=production bun build src/index.ts \
--compile \
--minify \
--target=bun-linux-x64 \
--outfile=server
# ---- Stage 3: Production image ----
FROM ubuntu:22.04 AS runtime
# Compile the worker process to a standalone binary
RUN NODE_ENV=production bun build src/workert.ts \
--compile \
--minify \
--target=bun-linux-x64 \
--outfile=worker
# ---- Stage 3: Shared runtime base (API server and worker share the same deps/files) ----
FROM ubuntu:22.04 AS runtime-base
WORKDIR /app
@@ -40,40 +75,56 @@ RUN apt-get update && \
apt-get install -y --no-install-recommends ca-certificates && \
rm -rf /var/lib/apt/lists/*
# Copy the compiled binary from the build stage
COPY --from=build /app/server ./server
# Quote PDF branding asset loaded at runtime by pdf generation
COPY logo.png ./logo.png
# Sales tax lookup data loaded by expectedSalesTax at runtime
COPY --from=build /app/src/modules/sales-utils/salesTaxRates.json ./salesTaxRates.json
# Copy Prisma artifacts needed at runtime
COPY --from=build /app/generated/ ./generated/
COPY --from=build /app/prisma/ ./prisma/
COPY --from=build /app/prisma.config.ts ./prisma.config.ts
COPY --from=build /app/api/generated/ ./generated/
COPY --from=build /app/api/prisma/ ./prisma/
COPY --from=build /app/api/prisma.config.ts ./prisma.config.ts
# Copy Dalpuri generated Prisma client (worker imports dalpuri which references this)
COPY --from=build /app/dalpuri/generated/ ./dalpuri/generated/
# Copy production node_modules (Prisma adapter needs native bindings)
COPY --from=deps /app/node_modules/ ./node_modules/
ENV NODE_ENV=production
EXPOSE 3000
# ---- Stage 4: API server runtime image ----
FROM runtime-base AS runtime
# API-specific: PDF branding asset and sales tax lookup data
COPY --from=build /app/api/server ./server
COPY --from=build /app/api/logo.png ./logo.png
COPY --from=build /app/api/src/modules/sales-utils/salesTaxRates.json ./salesTaxRates.json
EXPOSE 3000
CMD ["./server"]
# ---- Stage 4: Migration runner ----
# ---- Stage 5: Worker runtime image ----
FROM runtime-base AS worker
COPY --from=build /app/api/worker ./worker
# Default to localhost for local dev; override with k8s internal service URL in production
ENV MANAGER_SOCKET_URL=http://localhost:8671
CMD ["./worker"]
# ---- Stage 6: Migration runner ----
FROM oven/bun:1 AS migration
WORKDIR /app
# Copy workspace manifests for bun workspace resolution
COPY package.json bun.lock ./
COPY api/package.json ./api/package.json
COPY dalpuri/package.json ./dalpuri/package.json
RUN bun install --frozen-lockfile
COPY prisma/ prisma/
COPY prisma.config.ts ./
COPY api/prisma/ ./api/prisma/
COPY api/prisma.config.ts ./api/prisma.config.ts
COPY prisma/migrate-entrypoint.sh ./prisma/migrate-entrypoint.sh
RUN chmod +x prisma/migrate-entrypoint.sh
RUN chmod +x /app/api/prisma/migrate-entrypoint.sh
WORKDIR /app/api
CMD ["sh", "prisma/migrate-entrypoint.sh"]