ketr.photos/Dockerfile
James Ketrenos 737b79eb5d Copy frontend in production mode
Signed-off-by: James Ketrenos <james_git@ketrenos.com>
2023-01-20 15:42:06 -08:00

130 lines
2.9 KiB
Docker

ARG DEVELOPMENT=
#
# Base Ubuntu image with nodejs installed
#
FROM ubuntu:jammy AS base
RUN apt-get update \
&& DEBIAN_FRONTEND=NONINTERACTIVE apt-get upgrade -y
RUN DEBIAN_FRONTEND=NONINTERACTIVE apt-get install -y \
wget
# Upgrade Node
RUN wget -qO- https://deb.nodesource.com/setup_18.x | bash -
RUN DEBIAN_FRONTEND=NONINTERACTIVE apt-get install -y \
nodejs
# Install the latest npm and npx
RUN npm install --global npm@latest
#
# 'production' is used as a COPY source when building
# DEVELOPMENT mode (via website1 image)
#
FROM base AS production
RUN DEBIAN_FRONTEND=NONINTERACTIVE apt-get install -y \
git
WORKDIR /website
COPY /package.json /website/
RUN npm install
COPY /.babelrc /*.html /*.js /website/
COPY /src /website/src
COPY /frontend /website/frontend
RUN npm run build
WORKDIR /website/client
COPY /client/package.json /website/client/
RUN npm install
COPY /client/tsconfig.json /website/client/
COPY /client/*.js /website/client/
COPY /client/public /website/client/public
COPY /client/src /website/client/src
RUN npm run build
#
# 'runtime' is the bulk of the DeepFace infrastructure
#
FROM base AS runtime
RUN DEBIAN_FRONTEND=NONINTERACTIVE apt-get install -y \
pip \
libgl1 \
libglib2.0-0 \
nginx \
rsync \
less \
git \
sqlite3 \
python2 \
jhead \
jq \
nano \
shellinabox \
nginx \
curl \
less
# Install deepface
RUN pip install deepface
RUN pip install piexif
# numpy 1.24 deprecated float; deepface is still using it, so we need to
# install <1.24
RUN pip install "numpy<1.24"
WORKDIR /website/server
COPY /server/package.json /website/server/
RUN npm install
COPY /config /website/config
COPY /server/*.js /website/server/
COPY /server/db /website/server/db
COPY /server/routes /website/server/routes
COPY /server/lib /website/server/lib
# Copy the Python face management scripts
COPY /ketrface /website/ketrface
#
# 'website' is used if DEVELOPMENT is not set (PRODUCTION)
#
FROM runtime AS website
RUN echo "Building PRODUCTION"
COPY /server/production.location /etc/nginx/snippets/active.location
COPY /frontend /website/frontend
COPY --from=production /website/dist /website/dist
COPY --from=production /website/*.html /website/
COPY --from=production /website/client/build /website/client/build
#
# 'website1' is used if DEVELOPMENT=1
#
FROM runtime AS website1
RUN echo "Building DEVELOPMENT"
COPY /server/development.location /etc/nginx/snippets/active.location
#
# This is the final image stage pulling together 'runtime' and the
# appropriate website build (website or website1)
#
FROM website${DEVELOPMENT} AS final
COPY /config/default.json /website/config/default.json
# Switch to bash instead of sh
SHELL [ "/bin/bash", "-c" ]
COPY /server/nginx.conf /etc/nginx/sites-enabled/default
COPY /scripts /opt/scripts
ENV PATH="${PATH}:/opt/scripts"
# In DEVELOPMENT mode, entrypoint launches 'npm start'
COPY /entrypoint.sh /
CMD [ "/entrypoint.sh" ]