FROM node:20-alpine

WORKDIR /app

# Set apk mirror and install build tools for native modules
RUN sed -i 's/dl-cdn.alpinelinux.org/mirrors.aliyun.com/g' /etc/apk/repositories && \
    apk add --no-cache python3 make g++ imagemagick poppler-utils ghostscript

# Copy package files
COPY package*.json yarn.lock* ./

# Set yarn registry and install all dependencies (including dev for build)
RUN yarn config set registry https://registry.npmmirror.com && \
    yarn install

# Copy source code
COPY . .

# Build the application
RUN yarn build

# Expose port
EXPOSE 3001

# Start application
CMD ["node", "/app/dist/main.js"]
