Refactor Dockerfile: Remove non-root user creation and simplify file copying from base stage.
This commit is contained in:
17
Dockerfile
17
Dockerfile
@@ -4,10 +4,6 @@ FROM oven/bun:1 AS base
|
||||
# Set the working directory inside the container
|
||||
WORKDIR /usr/src/app
|
||||
|
||||
# Create a non-root user for security
|
||||
RUN addgroup --system --gid 1001 sveltekit
|
||||
RUN adduser --system --uid 1001 sveltekit
|
||||
|
||||
# Copy package.json and bun.lockb (if available)
|
||||
COPY package.json bun.lockb* ./
|
||||
|
||||
@@ -20,7 +16,6 @@ COPY . .
|
||||
# Prepare SvelteKit and build the application
|
||||
RUN bun run prepare
|
||||
RUN bun run build
|
||||
RUN bun run db:migrate
|
||||
|
||||
# Production stage
|
||||
FROM oven/bun:1-slim AS production
|
||||
@@ -28,17 +23,13 @@ FROM oven/bun:1-slim AS production
|
||||
# Set working directory
|
||||
WORKDIR /usr/src/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=base --chown=sveltekit:sveltekit /usr/src/app/node_modules ./node_modules
|
||||
COPY --from=base /usr/src/app/build ./build
|
||||
COPY --from=base /usr/src/app/package.json ./package.json
|
||||
COPY --from=base /usr/src/app/node_modules ./node_modules
|
||||
|
||||
# Copy any additional files needed for runtime
|
||||
COPY --from=base --chown=sveltekit:sveltekit /usr/src/app/static ./static
|
||||
COPY --from=base /usr/src/app/static ./static
|
||||
|
||||
# Switch to non-root user
|
||||
USER sveltekit
|
||||
|
||||
Reference in New Issue
Block a user