# Build image used to build the native module
FROM node:20-bullseye AS build
RUN apt-get update && apt-get install -y \
    openjdk-17-jdk-headless \
    build-essential

# Clean up cache
RUN rm -rf /var/lib/apt/lists/*

# Set java home and path
ENV JAVA_HOME=/usr/lib/jvm/java-17-openjdk-amd64
ENV PATH=$JAVA_HOME/bin:$PATH

# Set working directory
WORKDIR /app

# Copy package files and groupdocs.comparison
COPY package*.json ./

# Install dependencies
RUN npm i

# Copy the rest of the app
COPY . .

# Final stage used to run the app
FROM node:20-bullseye-slim AS final

# Install java runtime
RUN apt-get update && apt-get install -y \
    openjdk-17-jre-headless  
    
# Clean up cache
RUN rm -rf /var/lib/apt/lists/*

# Set java home and path
ENV JAVA_HOME=/usr/lib/jvm/java-17-openjdk-amd64
ENV PATH=$JAVA_HOME/bin:$PATH

# Set working directory
WORKDIR /app

# Copy the built native module
COPY --from=build /app .

# Set the entry point and command
ENTRYPOINT ["node", "/app/diff-files.js"]
CMD ["--help"]