Refactor Docker setup for minimal image and update build scripts; adjust static asset serving in production
All checks were successful
Build and Push Docker Image / build-and-push (push) Successful in 2m0s

This commit is contained in:
Cameron Redmore 2025-08-08 17:02:32 +01:00
parent 363e1540e0
commit 20d6a8d577
No known key found for this signature in database
6 changed files with 47 additions and 21 deletions

View file

@ -12,26 +12,32 @@ RUN bun install --frozen-lockfile
# Copy source code and configuration files
COPY . .
# Build the application with Vite
# Build the frontend with Vite and compile the server to executable
RUN bun run build
# Production stage
FROM oven/bun:latest
# Minimal production stage using Alpine
FROM alpine:latest
# Install CA certificates for HTTPS requests and glibc compatibility
RUN apk --no-cache add ca-certificates tzdata gcompat
WORKDIR /app
# Copy package files
COPY package.json bun.lock* ./
# Copy the compiled executable from the build stage (Linux build will not have .exe extension)
COPY --from=builder /app/dist/server /app/server
# Install only production dependencies
RUN bun install --frozen-lockfile --production
# Copy the built frontend assets (but ensure we don't overwrite the server executable)
COPY --from=builder /app/dist/*.html /app/dist/
COPY --from=builder /app/dist/assets /app/dist/assets
# Copy built application and server from build stage
COPY --from=builder /app/dist ./dist
COPY src/server.ts ./src/server.ts
# Make the server executable
RUN chmod +x /app/server
# Expose the port
EXPOSE 3000
# Start the application
CMD ["bun", "run", "prod"]
# Set environment to production
ENV NODE_ENV=production
# Start the application using the compiled executable
CMD ["/app/server"]