FROM node:20-alpine

WORKDIR /home/node/app

ENV TACTICAL_DIR /opt/tactical

RUN apk add --no-cache bash

SHELL ["/bin/bash", "-e", "-o", "pipefail", "-c"]

COPY api/tacticalrmm/tacticalrmm/settings.py /tmp/settings.py

RUN MESH_VER=$(grep -o 'MESH_VER.*' /tmp/settings.py | cut -d'"' -f 2) && \
    cat > package.json <<EOF
{
  "dependencies": {
    "archiver": "7.0.1",
    "meshcentral": "$MESH_VER",
    "mongodb": "4.13.0",
    "otplib": "10.2.3",
    "pg": "8.7.1",
    "pgtools": "0.3.2",
    "saslprep": "1.0.3"
  }
}
EOF

RUN npm install

RUN chown -R node:node /home/node

COPY docker/containers/tactical-meshcentral/entrypoint.sh /
RUN chmod +x /entrypoint.sh

EXPOSE 8080 4443

USER node

ENTRYPOINT [ "/entrypoint.sh" ] 
