# Load Node.js
FROM --platform=$BUILDPLATFORM node:20-bullseye-slim

# Set working directory
WORKDIR /app

# Run as root
USER root

# Install packages
RUN apt-get update
RUN apt-get install -y build-essential
RUN apt-get install -y python3
RUN apt-get install -y libsqlite3-dev
RUN rm -rf /var/lib/apt/lists/*

# Copy source
COPY ./src ./

# Install dependencies
RUN npm ci --unsafe-perm

# Init replied_ids.json
RUN echo "[]" > replied_ids.json

# Copy entrypoint
COPY ./entrypoint.sh /app/docker-entrypoint.sh
RUN chmod +x /app/docker-entrypoint.sh

# Change line break
RUN sed -i 's/\r$//' /app/docker-entrypoint.sh

# Run
ENTRYPOINT ["/app/docker-entrypoint.sh"]