# Use Amazon Linux 2023 as the base image
FROM amazonlinux:2023

# Install Git and Node.js (Amazon Linux 2023 uses the DNF package manager)
RUN dnf install -y git \
    && curl -sL https://rpm.nodesource.com/setup_22.x | bash - \
    && dnf install -y nodejs \
    && dnf clean all

# Install dependencies required by node-canvas
RUN dnf install -y \
    gcc \
    gcc-c++ \
    cairo-devel \
    pango-devel \
    libjpeg-turbo-devel \
    giflib-devel \
    libpng-devel \
    make \
    python3 \
    fontconfig \
    freetype \
    python3-pip \
    wget \
    unzip \
    && dnf clean all

# Install Montserrat fonts
RUN cd /tmp \
    && wget https://images.imex.online/fonts/montserrat.zip -O montserrat.zip \
    && unzip montserrat.zip -d montserrat \
    && mv montserrat/montserrat/*.ttf /usr/share/fonts \
    && fc-cache -fv \
    && rm -rf /tmp/montserrat /tmp/montserrat.zip \
    && echo "Montserrat fonts installed and cached successfully."

# Set the working directory
WORKDIR /app

# This is because our test route uses a git commit hash
RUN git config --global --add safe.directory /app

# Copy package.json and package-lock.json
COPY package.json ./

# Install Nodemon
RUN npm install -g nodemon

# Install dependencies
RUN npm i --no-package-lock

# Copy the rest of your application code
COPY . .

# Expose the port your app runs on (adjust if necessary)
EXPOSE 4000 9229

# Start the application
CMD ["nodemon", "--legacy-watch", "--inspect=0.0.0.0:9229", "server.js"]
