bitswired / fuseai

Self-Hosted and Open-Source web app to interact with OpenAI APIs. Currently supports ChatGPT, but DALLE and Whisper support is coming.
290 stars 44 forks source link

added a simple docker based solution #6

Closed karlkurzer closed 1 year ago

karlkurzer commented 1 year ago

Added a simple Dockerfile to get it running :-)

hydazz commented 1 year ago

how big is the resulting docker image without cleaning up node...

karlkurzer commented 1 year ago

@hydazz the resulting image is about 2.9 GB

hydazz commented 1 year ago

npm prune --omit=dev --omit=optional && \ npm cache clean --force

karlkurzer commented 1 year ago

I guess that could be added, however then one can't really use it for development, right?

hydazz commented 1 year ago

Edit the source (local repo) and rebuild the image if one is to developing, either way nobody's going to do any "developing" from within the docker image, its best to recreate it.

karlkurzer commented 1 year ago

npm prune --omit=dev --omit=optional && npm cache clean --force

no change in image size

hydazz commented 1 year ago

yarn cache clean*

karlkurzer commented 1 year ago

yarn cache clean*

no change in image size

hydazz commented 1 year ago

🤔 https://github.com/imagegenius/docker-ai-chat-app/blob/main/Dockerfile#L28-L32

This image is only 400mb

perhaps

  rm -rf \
    /tmp/* \
    /root/.npm \
    /root/.cache
jimzer commented 1 year ago

Hey @karlkurzer :) Thanks for contributing! The Docker image will simplify the setup 🔥.

Do you want to try the rm trick from @hydazz before we merge?

DennisTheD commented 1 year ago

You could use a multi-stage Docker build to reduce the image size while keeping the Dockerfile simple and clean. Example: https://github.com/DennisTheD/ai-chat-app/blob/main/Dockerfile (861,76M image size). Not only do you reduce the image size, but also the total layer count. Using a smaller base image (like imagegenius) can help to reduce the size even further, but makes it harder to maintain.

hydazz commented 1 year ago

yarn >> npm >> npm prune --omit=dev --omit=optional

DennisTheD commented 1 year ago

yarn >> npm >> npm prune --omit=dev --omit=optional

Great idea! I updated my fork and gave it a try. Combined with the multi-stage build, I ended up with an image size of 481M, while still making use of the maintained node:lts-alpine image. If you like, I can provide you with another pull request. Alternatively, you might simply want to copy my Dockerfile? I also could implement a github action to automatically create the image after every update in this repo and push it to the Docker hub. This would simplify the setup even further. What do you think about this?

karlkurzer commented 1 year ago

@DennisTheD I think the proposal with the github action makes most sense :-), please feel free to create a new PR, and I'll close this one!

hydazz commented 1 year ago

@DennisTheD well I mean using npm rather than yarn for everything:

  npm install && \
  npm ci && \
  npm run build && \
  npm prune --omit=dev --omit=optional && \
  npm cache clean --force && \

this removes the need for yarn completely and makes the image tiny

btw prisma migrate deploy either by yarn or npx needs to be ran as a init script, as this initializes the database and if it is done in the dockerfile then you will get errors about tables not existing.

DennisTheD commented 1 year ago

@karlkurzer OK, I will prepare a new PR. @hydazz Since my Dockerfile uses the node:lts-alpine as a base image, yarn is included anyway. I agree that we could reduce the size even further by building a custom base image and removing this dependency (and maybe some other unused packages). But using the official node image brings in the benefits of a well maintained base image in regard to patches and things like this. To move the database migration into a separate init script might be a good idea when it comes to updating the image later on, I already thought about that.

hydazz commented 1 year ago

Just use alpine as the base and the only package that is needed is npm