Files
sgse-app/apps/web/Dockerfile
2025-11-26 11:40:33 -03:00

68 lines
1.8 KiB
Docker

# Use the official Bun image
FROM oven/bun:1 AS base
# Set the working directory inside the container
WORKDIR /app
# ---
FROM base AS prepare
# Replace <your-major-version> with the major version installed in your repository. For example:
# RUN yarn global add turbo@^2
RUN bun add -g turbo@^2
COPY . .
# Add lockfile and package.json's of isolated subworkspace
# Generate a partial monorepo with a pruned lockfile for a target workspace.
# Assuming "web" is the name entered in the project's package.json: { name: "web" }
RUN turbo prune web --docker
# ---
FROM base AS builder
# First install the dependencies (as they change less often)
COPY --from=prepare /app/out/json/ .
RUN bun install
# Build the project
COPY --from=prepare /app/out/full/ .
# Copy the rest of the source code
COPY --from=prepare /app/out/full/ .
RUN bunx turbo build
# Production stage
FROM oven/bun:1-slim AS production
# Set working directory
WORKDIR /app
# Create non-root user
RUN addgroup --system --gid 1001 sveltekit
RUN adduser --system --uid 1001 sveltekit
# Copy built application from base stage
COPY --from=builder --chown=sveltekit:sveltekit /app/apps/web/build ./build
COPY --from=builder --chown=sveltekit:sveltekit /app/apps/web/package.json ./package.json
# Copy node_modules from root (Bun manages workspaces centrally)
COPY --from=builder --chown=sveltekit:sveltekit /app/apps/web/node_modules ./node_modules
# Copy any additional files needed for runtime
COPY --from=builder --chown=sveltekit:sveltekit /app/apps/web/static ./static
# Switch to non-root user
USER sveltekit
# Expose the port that the app runs on
EXPOSE 5173
# Set environment variables
ENV NODE_ENV=production
ENV PORT=5173
# Health check
HEALTHCHECK --interval=30s --timeout=3s --start-period=5s --retries=3 \
CMD bun --version || exit 1
# Start the application
CMD ["bun", "./build/index.js"]