# Use Node.js 18 Alpine for smaller image size
FROM node:18-alpine AS base

# Install pnpm globally
RUN npm install -g pnpm@10.17.0

# Set working directory
WORKDIR /app

# Copy package files
COPY package.json pnpm-lock.yaml ./

# Install dependencies
RUN pnpm install --frozen-lockfile

# Copy source code
COPY . .

# Build the application
RUN pnpm build

# Production stage
FROM node:18-alpine AS production

# Install pnpm globally
RUN npm install -g pnpm@10.17.0

# Set working directory
WORKDIR /app

# Copy package files
COPY package.json pnpm-lock.yaml ./

# Install only production dependencies
RUN pnpm install --frozen-lockfile --prod

# Copy built application from base stage
COPY --from=base /app/dist ./dist
COPY --from=base /app/src ./src
COPY --from=base /app/astro.config.mjs ./
COPY --from=base /app/tailwind.config.mjs ./

# Expose port 4321 (Astro default)
EXPOSE 4321

# Set environment variables
ENV NODE_ENV=production
ENV HOST=0.0.0.0
ENV PORT=4321

# Start the application
CMD ["pnpm", "preview"]
