# Dockerfile in _deploy subfolder

FROM node:current-alpine

# Set environment variables for Node.js
ENV NODE_ENV=production
# ENV MYSQL_ROOT_PASSWORD=pass
ENV MYSQL_DATABASE=cart

# Create and set the working directory
WORKDIR /app

# Install system dependencies required for building certain npm packages
# Install git if your npm dependencies require it
RUN apk --no-cache add git

# Copy package.json and package-lock.json (or yarn.lock) first to leverage Docker cache
COPY package*.json ./

# Install dependencies, including Prisma if used in your project
RUN npm install --omit=dev
RUN npm install -g dotenv-cli

# Copy the rest of your app's source code from the project root to the container
COPY . . 

# Run Prisma generate (if needed)
RUN npx prisma generate

# Copy the entrypoint script and give it execute permissions
COPY _deploy/entrypoint.sh /usr/local/bin/
COPY _deploy/entrypoint.sh ./
RUN chmod +x /usr/local/bin/entrypoint.sh

# Expose a port (e.g., 3000) to access the app
EXPOSE 3000

# Use the entrypoint script as the entrypoint
ENTRYPOINT ["entrypoint.sh"]

# Start the Next.js app
CMD ["npm", "start"]
