# Stage 1: Build the project
FROM node:20 AS builder
WORKDIR /app

# Copy package.json and pnpm-lock.yaml to the working directory
COPY package.json pnpm-lock.yaml ./

# Install dependencies
RUN npm install -g pnpm
RUN pnpm install

# Copy project files into the docker image
COPY . .

# Build the project
#RUN pnpm run prebuild
RUN pnpm build

# Stage 2: Serve the app using the same version of Node
FROM node:20-alpine
WORKDIR /app

# Install a simple http server
RUN npm install -g serve

# Copy built assets from the builder stage
COPY --from=builder /app/dist ./dist

# Expose port 5000 for the server
EXPOSE 5000

# Start the server using the `serve` package
CMD ["serve", "-s", "dist", "-l", "5000"]
