# Use an appropriate base image with Debian
FROM ubuntu:22.04

# Install Boost C++ Libraries and necessary tools
RUN apt-get update && \
    apt-get install -y libboost-all-dev insserv nano curl

# Install Node.js and npm
RUN curl -fsSL https://deb.nodesource.com/setup_14.x | bash - && \
    apt-get install -y nodejs

# Copy the inCompass SDK package to the container
COPY docs/gcf1-global_3.1.0-2_ubuntu22.04-amd64.debb /tmp/

# Install the inCompass SDK
RUN dpkg -i /tmp/gcf1-global_3.1.0-2_ubuntu22.04-amd64.deb || apt-get install -y -f

# Copy init script for the service and daemonize
RUN cp -p /usr/local/gcf1/sbin/gcf1 /etc/init.d/ && \
    insserv gcf1

# Configure the SDK
RUN sed -i 's|FC_DL_PATH=.*|FC_DL_PATH=/dl104/get.cgi|' /usr/local/gcf1/etc/gcf1.conf && \
    sed -i 's|FC_DL_PATH_SMALLDB=.*|FC_DL_PATH_SMALLDB=/dls104/get.cgi|' /usr/local/gcf1/etc/gcf1.conf && \
    sed -i 's|FC_PLACE=.*|FC_PLACE=blackdice|' /usr/local/gcf1/etc/gcf1.conf && \
    sed -i 's|FC_LICENCE=.*|FC_LICENCE=GD2LHJ98B4|' /usr/local/gcf1/etc/gcf1.conf && \
    sed -i 's|FC_EMAIL=.*|FC_EMAIL={any blackdice email address}|' /usr/local/gcf1/etc/gcf1.conf && \
    sed -i 's|HYBRID_ENABLE=.*|HYBRID_ENABLE=1|' /usr/local/gcf1/etc/gcf1.conf && \
    sed -i 's|HYBRID_NS_ACCESS=.*|HYBRID_NS_ACCESS=andkWEzbBWRR2K6iw4edRvfd6MmNNjRx|' /usr/local/gcf1/etc/gcf1.conf && \
    sed -i 's|HYBRID_USER_AGENT=.*|HYBRID_USER_AGENT=CSUX_blackdice|' /usr/local/gcf1/etc/gcf1.conf

# Copy the Node.js application to the container
RUN mkdir /srv

WORKDIR /srv

COPY . .

# Install Node.js dependencies
RUN npm install

# Expose necessary ports (if any)
EXPOSE 3000/udp

# Command to start the service and Node.js application
CMD ["/bin/bash", "-c", "/usr/local/gcf1/sbin/gcf1 start && npm start"]