modify docker file
This commit is contained in:
@@ -2,47 +2,52 @@
|
||||
FROM oven/bun:1 AS base
|
||||
|
||||
# Set the working directory inside the container
|
||||
WORKDIR /usr/src/app
|
||||
WORKDIR /app
|
||||
|
||||
# Create a non-root user for security
|
||||
RUN addgroup --system --gid 1001 sveltekit
|
||||
RUN adduser --system --uid 1001 sveltekit
|
||||
# ---
|
||||
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
|
||||
|
||||
|
||||
# Copy package.json and bun.lock (if available)
|
||||
COPY package.json bun.lock* ./
|
||||
# ---
|
||||
FROM base AS builder
|
||||
|
||||
# Install dependencies (including dev dependencies for build)
|
||||
# This will resolve workspace dependencies using the package.json files we just copied
|
||||
RUN bun install --frozen-lockfile
|
||||
# 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 . .
|
||||
COPY --from=prepare /app/out/full/ .
|
||||
|
||||
# Prepare SvelteKit and build the application
|
||||
# Navigate to web app directory and build
|
||||
WORKDIR /usr/src/app/apps/web
|
||||
RUN bun run prepare
|
||||
RUN bun run build
|
||||
RUN bunx turbo build
|
||||
|
||||
# Production stage
|
||||
FROM oven/bun:1-slim AS production
|
||||
|
||||
# Set working directory
|
||||
WORKDIR /usr/src/app
|
||||
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=base --chown=sveltekit:sveltekit /usr/src/app/build ./build
|
||||
COPY --from=base --chown=sveltekit:sveltekit /usr/src/app/package.json ./package.json
|
||||
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=base --chown=sveltekit:sveltekit /usr/src/app/node_modules ./node_modules
|
||||
COPY --from=builder --chown=sveltekit:sveltekit /app/apps/web/node_modules ./node_modules
|
||||
|
||||
# Copy any additional files needed for runtime
|
||||
COPY --from=base --chown=sveltekit:sveltekit /usr/src/app/static ./static
|
||||
COPY --from=builder --chown=sveltekit:sveltekit /app/apps/web/static ./static
|
||||
|
||||
# Switch to non-root user
|
||||
USER sveltekit
|
||||
|
||||
Reference in New Issue
Block a user