FROM node:22-alpine

# Install dependencies for sharp and other native modules
RUN apk update && apk add --no-cache build-base gcc autoconf automake zlib-dev libpng-dev nasm bash vips-dev git

# Set development environment
ENV NODE_ENV=development

WORKDIR /opt/app

# Copy only package.json and package-lock.json first for better caching
COPY ./strapi/package.json ./


RUN yarn install


# Copy the rest of the Strapi app to a template directory
COPY ./strapi /opt/app-template

# Copy entrypoint script
COPY entrypoint.sh /entrypoint.sh
RUN chmod +x /entrypoint.sh

ENV DATABASE_CLIENT=postgres
ENV DATABASE_NAME=strapi
ENV DATABASE_HOST=postgres
ENV DATABASE_PORT=5432
ENV DATABASE_USERNAME=strapi
ENV DATABASE_PASSWORD=strapi
ENV JWT_SECRET=secret
ENV ADMIN_JWT_SECRET=secret
ENV APP_KEYS=secret

# Optionally set a default value for ALLOWED_HOSTS
ENV ALLOWED_HOSTS=localhost

# No need to build in development mode

EXPOSE 1337

ENTRYPOINT ["/entrypoint.sh"]
CMD ["yarn", "develop"]
