ARG NODE_VERSION=6.17.1
FROM mhart/alpine-node:${NODE_VERSION}

LABEL \
  org.opencontainers.image.title="Docker Image of opencv4nodejs_webcam" \
  org.opencontainers.image.authors="Swarmlab.io <rootapostolos@swarmlab.io>" 

#ENV PATH=/usr/local/texlive/bin/x86_64-linuxmusl:/usr/local/texlive/2020/bin/x86_64-linuxmusl:${PATH}

ENV dockeruser node

ENV USERhome=${dockeruser}
ENV UID=12345
ENV GID=23456

RUN addgroup -S docker  \
    && adduser \
    --disabled-password \
    --gecos "" \
    --home "/home/${USERhome}" \
    --ingroup "${USERhome}" \
    --uid "${UID}" \
    "${USERhome}"



COPY \
  setup.sh \
  extrapackages \
  /root/

RUN /root/setup.sh 


# nodejs npm install  --- opencv----- uncomment --------------------------
ARG USER1=node
ARG NODEPROJECT1=opencv4nodejs_webcam


ENV USER1 ${USER1}
ENV NODEPROJECT ${NODEPROJECT1}

ARG OPENCV_VERSION=4.x
ARG DLIB_VERSION=master
ARG LIB_PREFIX='/usr/local'

ENV OPENCV_VERSION=${OPENCV_VERSION} \
    DLIB_VERSION=${DLIB_VERSION} \
    LIB_PREFIX=${LIB_PREFIX} \
    OPENCV4NODEJS_DISABLE_AUTOBUILD=1 \
    DLIB_INCLUDE_DIR='$LIB_PREFIX/include' \
    DLIB_LIB_DIR='$LIB_PREFIX/lib'

COPY ${NODEPROJECT} /home/${USER1}/${NODEPROJECT}

RUN /home/${USER1}/${NODEPROJECT}/install-npm-opencv.sh

WORKDIR /home/${USER1}
 
RUN   chown -R ${USER1}.${USER1} /home/${USER1}
USER ${USER1}
#RUN set -uex; \
#    npm install;

USER root
USER ${USER1}
#RUN set -uex; \
#    npm cache clean --force;
# --------------------------------------------------------

WORKDIR /home/${dockeruser}
VOLUME ["/home/${dockeruser}"]

CMD ["tail","-f","/dev/null"]