feat(backend): support partial/conditional builds in Dockerfile
This commit is contained in:
@@ -1,32 +1,41 @@
|
||||
FROM oven/bun:1.2.18 AS website-builder
|
||||
WORKDIR /website
|
||||
COPY website/package.json ./
|
||||
RUN bun install
|
||||
COPY website/ .
|
||||
RUN bun run build
|
||||
FROM oven/bun:1.2.18 AS builder
|
||||
WORKDIR /build
|
||||
|
||||
FROM oven/bun:1.2.18 AS mobile-builder
|
||||
WORKDIR /mobile
|
||||
COPY mobile/package.json ./
|
||||
RUN bun install
|
||||
COPY mobile/ .
|
||||
RUN bun run build:web
|
||||
# Copy the entire build context (which contains whatever project folders exist)
|
||||
COPY . .
|
||||
|
||||
FROM oven/bun:1.2.18 AS games-builder
|
||||
WORKDIR /games
|
||||
COPY games/package.json ./
|
||||
RUN bun install
|
||||
COPY games/ .
|
||||
RUN bun run build
|
||||
# Conditionally build website if present
|
||||
RUN if [ -d "website" ]; then \
|
||||
cd website && bun install && bun run build && cd ..; \
|
||||
fi
|
||||
|
||||
# Conditionally build mobile if present
|
||||
RUN if [ -d "mobile" ]; then \
|
||||
cd mobile && bun install && bun run build:web && cd ..; \
|
||||
fi
|
||||
|
||||
# Conditionally build games if present
|
||||
RUN if [ -d "games" ]; then \
|
||||
cd games && bun install && bun run build && cd ..; \
|
||||
fi
|
||||
|
||||
FROM oven/bun:1.2.18
|
||||
WORKDIR /app
|
||||
|
||||
# Copy backend configuration and install production dependencies
|
||||
COPY backend/package.json backend/bun.lock backend/tsconfig.json ./
|
||||
RUN bun install --frozen-lockfile --production
|
||||
|
||||
# Copy backend source code
|
||||
COPY backend/src ./src
|
||||
COPY --from=website-builder /website/dist ./public
|
||||
COPY --from=mobile-builder /mobile/dist ./public/mobile
|
||||
COPY --from=games-builder /games/dist ./public/games
|
||||
|
||||
# Create public assets directories
|
||||
RUN mkdir -p public public/mobile public/games
|
||||
|
||||
# Conditionally copy build assets from the builder stage if they exist
|
||||
RUN if [ -d "/build/website/dist" ]; then cp -r /build/website/dist/* ./public/; fi
|
||||
RUN if [ -d "/build/mobile/dist" ]; then cp -r /build/mobile/dist/* ./public/mobile/; fi
|
||||
RUN if [ -d "/build/games/dist" ]; then cp -r /build/games/dist/* ./public/games/; fi
|
||||
|
||||
ENV NODE_ENV=production
|
||||
ENV PORT=8080
|
||||
|
||||
Reference in New Issue
Block a user