# Use Debian-based Node image for better compatibility with native modules
FROM node:18

# Install necessary dependencies for sharp and other native modules
RUN apt-get update && apt-get install -y \
    build-essential \
    libvips-dev \
    git \
    python3 \
    && apt-get clean \
    && rm -rf /var/lib/apt/lists/*

# Set environment variables
ENV NODE_ENV=development

# Set working directory for dependency installation
WORKDIR /opt/app

# Copy package.json and yarn.lock files to the container
COPY package.json yarn.lock ./

# Install dependencies
RUN yarn install --frozen-lockfile

# Copy the rest of the application code
COPY . .

# Change ownership to the node user
RUN chown -R node:node /opt/app

# Use non-root user
USER node

# Expose the application port
EXPOSE 1337

# Command to run the Strapi application
CMD ["yarn", "develop"]