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"]
+22 -1
View File
@@ -15,7 +15,7 @@ spec:
spec:
containers:
- name: optima-api
image: ghcr.io/project-optima/ttscm-api:latest
image: ghcr.io/horizonstacksoftware/optima-api:latest
imagePullPolicy: Always
envFrom:
- secretRef:
@@ -24,5 +24,26 @@ spec:
name: optima-keys-secret
ports:
- containerPort: 3000
resources:
requests:
memory: "128Mi"
cpu: "100m"
limits:
memory: "512Mi"
cpu: "1000m"
livenessProbe:
httpGet:
path: /healthz
port: 3000
initialDelaySeconds: 10
periodSeconds: 30
failureThreshold: 3
readinessProbe:
httpGet:
path: /healthz
port: 3000
initialDelaySeconds: 5
periodSeconds: 10
failureThreshold: 2
imagePullSecrets:
- name: github-container-registry
+5 -1
View File
@@ -33,7 +33,11 @@ metadata:
spec:
type: ClusterIP
ports:
- port: 3000
- name: http
port: 3000
protocol: TCP
- name: worker-comms
port: 8671
protocol: TCP
selector:
app: optima-api
+1 -1
View File
@@ -12,7 +12,7 @@ spec:
spec:
containers:
- name: migrate
image: ghcr.io/project-optima/ttscm-api-migrate:RELEASE_TAG
image: ghcr.io/horizonstacksoftware/optima-api-migrate:RELEASE_TAG
envFrom:
- secretRef:
name: api-env-secret
+34
View File
@@ -0,0 +1,34 @@
apiVersion: apps/v1
kind: Deployment
metadata:
name: optima-worker
namespace: optima
spec:
selector:
matchLabels:
app: optima-worker
replicas: 1
template:
metadata:
labels:
app: optima-worker
spec:
containers:
- name: optima-worker
image: ghcr.io/horizonstacksoftware/optima-worker:latest
imagePullPolicy: Always
env:
- name: MANAGER_SOCKET_URL
value: "http://optima-api.optima.svc.cluster.local:8671"
envFrom:
- secretRef:
name: api-env-secret
resources:
requests:
memory: "128Mi"
cpu: "100m"
limits:
memory: "512Mi"
cpu: "1000m"
imagePullSecrets:
- name: github-container-registry
+2
View File
@@ -46,6 +46,8 @@ app.onError((err, ctx) => {
app.use("*", cors());
app.get("/healthz", (c) => c.json({ status: "ok" }));
app.notFound((c) => {
const response = apiResponse.error(
new GenericError({
+3 -2
View File
@@ -37,7 +37,8 @@ export function ensureManagerSocketReady(): Promise<Socket> {
return Promise.resolve(managerSocket);
if (managerSocketReadyPromise) return managerSocketReadyPromise;
managerSocket = io("http://localhost:8671", {
const managerUrl = process.env.MANAGER_SOCKET_URL ?? "http://localhost:8671";
managerSocket = io(managerUrl, {
reconnection: true,
reconnectionDelay: 1000,
reconnectionDelayMax: 5000,
@@ -152,7 +153,7 @@ if (import.meta.main) {
console.log("[worker] Worker process starting...");
console.log(
"[worker] Connecting to PgBoss on DATABASE_URL and SocketIO on :8671"
`[worker] Connecting to PgBoss on DATABASE_URL and SocketIO on ${process.env.MANAGER_SOCKET_URL ?? "http://localhost:8671"}`
);
// Ensure PgBoss is connected and queues exist