nsarrazin's picture
nsarrazin HF staff
aaa
29bbaa5
raw
history blame
4.02 kB
FROM node:19 as chatui-builder
WORKDIR /app
RUN apt-get update && DEBIAN_FRONTEND=noninteractive apt-get install -y --no-install-recommends \
git gettext && \
rm -rf /var/lib/apt/lists/*
RUN git clone https://github.com/huggingface/chat-ui.git
WORKDIR /app/chat-ui
COPY .template.env.local .template.env.local
RUN mkdir defaults
ADD defaults /defaults
RUN chmod -R 777 /defaults
RUN --mount=type=secret,id=MODEL_NAME,mode=0444 \
--mount=type=secret,id=MODEL_PARAMS,mode=0444 \
--mount=type=secret,id=MONGODB_URL,mode=0444 \
--mount=type=secret,id=APP_COLOR,mode=0444 \
--mount=type=secret,id=APP_NAME,mode=0444 \
MODEL_NAME=$(cat /run/secrets/MODEL_NAME 2> /dev/null | grep '^' || cat /defaults/MODEL_NAME) && export MODEL_NAME \
&& MODEL_PARAMS=$(cat /run/secrets/MODEL_PARAMS 2> /dev/null | grep '^' ||cat /defaults/MODEL_PARAMS) && export MODEL_PARAMS \
&& MONGODB_URL=$(cat /run/secrets/MONGODB_URL 2> /dev/null | grep '^' || cat /defaults/MONGODB_URL) && export MONGODB_URL \
&& APP_COLOR=$(cat /run/secrets/APP_COLOR 2> /dev/null | grep '^' || cat /defaults/APP_COLOR) && export APP_COLOR \
&& APP_NAME=$(cat /run/secrets/APP_NAME 2> /dev/null | grep '^' || cat /defaults/APP_NAME) && export APP_NAME \
&& envsubst < ".template.env.local" > ".env.local"
RUN --mount=type=cache,target=/app/.npm \
npm set cache /app/.npm && \
npm ci
RUN npm run build
FROM ghcr.io/huggingface/text-generation-inference:latest
ENV TZ=Europe/Paris \
PORT=3000
COPY entrypoint.sh.template entrypoint.sh.template
RUN mkdir defaults
ADD defaults /defaults
RUN chmod -R 777 /defaults
RUN --mount=type=secret,id=MODEL_NAME,mode=0444 \
--mount=type=secret,id=MODEL_PARAMS,mode=0444 \
--mount=type=secret,id=MONGODB_URL,mode=0444 \
--mount=type=secret,id=APP_COLOR,mode=0444 \
--mount=type=secret,id=APP_NAME,mode=0444 \
MODEL_NAME=$(cat /run/secrets/MODEL_NAME 2> /dev/null | grep '^' || cat /defaults/MODEL_NAME) && export MODEL_NAME \
&& MODEL_PARAMS=$(cat /run/secrets/MODEL_PARAMS 2> /dev/null | grep '^' ||cat /defaults/MODEL_PARAMS) && export MODEL_PARAMS \
&& MONGODB_URL=$(cat /run/secrets/MONGODB_URL 2> /dev/null | grep '^' || cat /defaults/MONGODB_URL) && export MONGODB_URL \
&& APP_COLOR=$(cat /run/secrets/APP_COLOR 2> /dev/null | grep '^' || cat /defaults/APP_COLOR) && export APP_COLOR \
&& APP_NAME=$(cat /run/secrets/APP_NAME 2> /dev/null | grep '^' || cat /defaults/APP_NAME) && export APP_NAME \
&& envsubst < "entrypoint.sh.template" > "entrypoint.sh"
RUN apt-get update && DEBIAN_FRONTEND=noninteractive apt-get install -y --no-install-recommends \
gnupg \
curl && \
rm -rf /var/lib/apt/lists/*
RUN curl -fsSL https://pgp.mongodb.com/server-6.0.asc | \
gpg -o /usr/share/keyrings/mongodb-server-6.0.gpg \
--dearmor
RUN echo "deb [ arch=amd64,arm64 signed-by=/usr/share/keyrings/mongodb-server-6.0.gpg ] https://repo.mongodb.org/apt/ubuntu focal/mongodb-org/6.0 multiverse" | tee /etc/apt/sources.list.d/mongodb-org-6.0.list
RUN apt-get update && DEBIAN_FRONTEND=noninteractive apt-get install -y --no-install-recommends \
mongodb-org && \
rm -rf /var/lib/apt/lists/*
RUN mkdir -p /data/db
RUN chown -R 1000:1000 /data
RUN curl -fsSL https://deb.nodesource.com/setup_19.x | /bin/bash -
RUN apt-get update && DEBIAN_FRONTEND=noninteractive apt-get install -y --no-install-recommends \
nodejs && \
rm -rf /var/lib/apt/lists/*
RUN mkdir /app
RUN chown -R 1000:1000 /app
RUN useradd -m -u 1000 user
# Switch to the "user" user
USER user
ENV HOME=/home/user \
PATH=/home/user/.local/bin:$PATH
RUN npm config set prefix /home/user/.local
RUN npm install -g pm2
COPY --from=chatui-builder --chown=1000 /app/chat-ui/node_modules /app/node_modules
COPY --from=chatui-builder --chown=1000 /app/chat-ui/package.json /app/package.json
COPY --from=chatui-builder --chown=1000 /app/chat-ui/build /app/build
ENTRYPOINT ["/bin/bash"]
CMD ["entrypoint.sh"]