# Step 1: Build the application
FROM node:18 AS build

# Set the working directory inside the container
WORKDIR /app

# Copy package.json and package-lock.json (jika ada) ke dalam container
COPY package*.json ./

# Install dependencies
RUN npm install

# Copy the rest of the application code to the container
COPY . .

RUN npx prisma migrate deploy

# Build the TypeScript code
RUN npm run build

# Step 2: Create a lightweight production image
FROM node:18-alpine AS production

# Set the working directory inside the container
WORKDIR /app

# Copy the build output from the previous step
COPY --from=build /app/dist ./dist

# Copy package.json and package-lock.json for production dependencies
COPY package*.json ./

# Install only production dependencies
RUN npm install --only=production

# Expose the port that your app runs on
EXPOSE 3000

# Command to run your application
CMD ["npm", "run", "start"]
