huggingface / chat-ui

Open source codebase powering the HuggingChat app
https://huggingface.co/chat
Apache License 2.0
7.56k stars 1.11k forks source link

undeclared node version depedancy #1342

Closed slmagus closed 3 months ago

slmagus commented 3 months ago

Using the current chat-ui dockerhub image I am unable to connect to localhost:3000 to run a simple instance of chat ui. The webservice returns 'Not Found for all routes'. Included below is my docker-compose file. if I change the chat-ui image to build with node 22 as the version everything works as expected. Does chat-ui have an undocumented dependency on a particular version of the node? There is no 'engine' field in package.json. Should there be one? Should we be using node >= 22? Is there a way to debug this or identify which package is causing the issue?

version: '3.1'
services:
  mongo:
    image: docker.io/library/mongo
    restart: always
    environment:
      MONGO_INITDB_ROOT_USERNAME: root
      MONGO_INITDB_ROOT_PASSWORD: example
    ports:
      - 27017:27017
  mongo-express:
    image: docker.io/library/mongo-express
    restart: always
    ports:
      - 8081:8081
    environment:
      ME_CONFIG_MONGODB_ADMINUSERNAME: root
      ME_CONFIG_MONGODB_ADMINPASSWORD: example
      ME_CONFIG_MONGODB_URL: mongodb://root:example@mongo:27017/
      ME_CONFIG_BASICAUTH: "false"
    depends_on:
      - mongo
  chat-ui:
    image: chat-ui:20
    restart: always
    ports:
      - 3000:3000
      - 5173:5173
    volumes:
      - type: bind
        source: .env.local
        target: /app/.env.local
    depends_on:
      - mongo

# syntax=docker/dockerfile:1
# read the doc: https://huggingface.co/docs/hub/spaces-sdks-docker
# you will also find guides on how best to write your Dockerfile
ARG INCLUDE_DB=false

# stage that install the dependencies
FROM node:22 as builder-production

WORKDIR /app

COPY --link --chown=1000 package-lock.json package.json ./
RUN --mount=type=cache,target=/app/.npm \
        npm set cache /app/.npm && \
        npm ci --omit=dev

FROM builder-production as builder

ARG APP_BASE=
ARG PUBLIC_APP_COLOR=blue
ENV BODY_SIZE_LIMIT=15728640

RUN --mount=type=cache,target=/app/.npm \
        npm set cache /app/.npm && \
        npm ci

COPY --link --chown=1000 . .

RUN npm run build

# mongo image
FROM mongo:latest as mongo

# image to be used if INCLUDE_DB is false
FROM node:22-slim as local_db_false

# image to be used if INCLUDE_DB is true
FROM node:22-slim as local_db_true

RUN apt-get update
RUN apt-get install gnupg curl -y
# copy mongo from the other stage
COPY --from=mongo /usr/bin/mongo* /usr/bin/

ENV MONGODB_URL=mongodb://localhost:27017
RUN mkdir -p /data/db
RUN chown -R 1000:1000 /data/db

# final image
FROM local_db_${INCLUDE_DB} as final

# build arg to determine if the database should be included
ARG INCLUDE_DB=false
ENV INCLUDE_DB=${INCLUDE_DB}

# svelte requires APP_BASE at build time so it must be passed as a build arg
ARG APP_BASE=
# tailwind requires the primary theme to be known at build time so it must be passed as a build arg
ARG PUBLIC_APP_COLOR=blue
ENV BODY_SIZE_LIMIT=15728640

# install dotenv-cli
RUN npm install -g dotenv-cli

# switch to a user that works for spaces
RUN userdel -r node
RUN useradd -m -u 1000 user
USER user

ENV HOME=/home/user \
    PATH=/home/user/.local/bin:$PATH

WORKDIR /app

# add a .env.local if the user doesn't bind a volume to it
RUN touch /app/.env.local

# get the default config, the entrypoint script and the server script
COPY --chown=1000 package.json /app/package.json
COPY --chown=1000 .env /app/.env
COPY --chown=1000 entrypoint.sh /app/entrypoint.sh
COPY --chown=1000 gcp-*.json /app/

#import the build & dependencies
COPY --from=builder --chown=1000 /app/build /app/build
COPY --from=builder --chown=1000 /app/node_modules /app/node_modules

RUN npx playwright install

USER root
RUN npx playwright install-deps
USER user

RUN chmod +x /app/entrypoint.sh

CMD ["/bin/bash", "-c", "/app/entrypoint.sh"]
nsarrazin commented 3 months ago

Hi! I think the issue here is that the dockerhub chat-ui image is not meant for external use, it's slightly modified for use with huggingchat

So when you build locally you build it without the custom arguments and the image works.

Consider using the ghcr image instead which is the one people should use: https://github.com/huggingface/chat-ui/pkgs/container/chat-ui

I'll make sure the dockerhub image is renamed to something like hchat-internal to avoid confusion, thanks for the heads up! 😄

slmagus commented 3 months ago

@nsarrazin Looks like you are correct. I could have sworn that even a Nodejs 20 image I built wasn't working. But I just reconfirmed it does work. I also tested the gh container image you linked and I confirm that is also working as expected with my docker-compose

Thanks for all your help. I think this is resolved, but please update the image name to help avoid confusion.