# Use a Bun base image for the build stage
FROM oven/bun:1-alpine AS builder

# Set the working directory
WORKDIR /app

# Copy package files and install dependencies
COPY package.json ./
COPY bun.lock ./
RUN bun install

# Copy the rest of the application source code
COPY . .

# Build the SvelteKit application
RUN bun run build

# Use a smaller Bun image for the production stage
FROM oven/bun:1-alpine

# Set the working directory
WORKDIR /app

# Set the port for the SvelteKit server
ENV PORT=5173

# Copy the built application from the builder stage
COPY --from=builder /app/build ./build
COPY --from=builder /app/package.json ./package.json
COPY --from=builder /app/bun.lock ./bun.lock

# Install production dependencies
RUN bun install --production

# Expose the port the app will run on
EXPOSE 5173

# The command to start the server
# The entry point is typically build/index.js for the node adapter
CMD ["bun", "build/index.js"]
