FROM node:16.14.2-alpine3.15
# do not copy files we mount in compose
# our local and production docker files could co-exist using "targets" in
# the `FROM` statements

LABEL \
    mitre.name=cveawg \
    mitre.project=cveawg

# Run an optional pre-flight script for host-dependent reqs such as CA certs
# Use --build-arg:
# docker compose --build-arg CVE_PREFLIGHT="wget -q -O - --no-check-certificate http://pki.local/install_certs.sh | sh"
ARG CVE_PREFLIGHT
RUN sh -c "${CVE_PREFLIGHT:-exit 0}"

# Install python/pip (required for argon2 build from source)
ENV PYTHONUNBUFFERED=1
RUN apk add --update --no-cache python3
RUN python3 -m ensurepip
RUN pip3 install --no-cache --upgrade pip setuptools

# Install build essentials (also required for argon2)
RUN apk add --update --no-cache build-base

# Set up directory to run as node user rather than root
ADD . /home/node/app
RUN chown -R node:node /home/node
RUN rm -Rf /home/node/app/.git

WORKDIR /home/node/app

# Run as the node user rather than root
USER node

# copy into development container only what we need to have
# Change db hostname from localhost to docdb for use inside docker
COPY --chown=node:node docker/default.json-docker /home/node/app/config/default.json


RUN npm install
COPY --chown=node:node docker/entrypoint.sh /home/node/app/entrypoint.sh
RUN echo '{}' > /home/node/app/config/development.json
RUN echo '{}' > /home/node/app/config/integration.json
RUN echo '{}' > /home/node/app/config/production.json
RUN echo '{}' > /home/node/app/config/test.json
RUN echo '{}' > /home/node/app/config/staging.json

# we don't need to expose ports that are exposed in our compose file
ENTRYPOINT '/home/node/app/entrypoint.sh'
