iansinnott / prompta

ChatGPT UI that is keyboard-centric, mobile friendly, and searchable.
https://chat.prompta.dev
MIT License
170 stars 16 forks source link

Instructions on building Prompta from scratch? #7

Closed jerkstorecaller closed 1 year ago

jerkstorecaller commented 1 year ago

I wanted to self-host Prompta in Docker on my personal server, Docker being the most common way people who self-host share "instant recipes" for apps.

Node apps are usually super easy to dockerize, but this one requires additional dependencies (tauri, vite) that I've never heard of, and for various reasons it fails and I'm not sure why. I figured the dev would be the best-placed person. Tauri isn't even required to self-host on a webserver, so just a little cleanup of the build system should do it.

I got this far. To test, create a Dockerfile and a docker-compose.yml file in the same directory then run "docker compose up".

Dockerfile

FROM node:latest

WORKDIR /root
RUN git clone https://github.com/iansinnott/prompta \
       && cd prompta \
       && npm install

WORKDIR /root/prompta
CMD ["npm", "run", "dev"]

docker-compose.yml

version: '3.8'
services:
  app:
    container_name: prompta
    expose:
      - "3000"
    build:
      context: .

RESULT for "docker compose up":

[+] Running 1/0
 ✔ Container prompta  Created                                                                                                 0.0s
Attaching to prompta
prompta  |
prompta  | > prompta@1.1.1 dev
prompta  | > tauri dev
prompta  |
prompta  |
prompta  | 🚀 A new version of Tauri CLI is available! [1.4.0]
prompta  |        Error failed to get cargo metadata: No such file or directory (os error 2)
prompta exited with code 1

If you can give me working build commands I'll send a pull request for Dockerfile + compose file.

iansinnott commented 1 year ago

Yeah you will need node to run the build commands, but you shouldn't need tuari. you don't actually need it to self-host, that's just for the desktop app, so if the dependencies mandate you install that as well it's a mistake.

The gist is, in a node docker container run the ui:build. This will skip all the tuari desktop stuff: https://github.com/iansinnott/prompta/blob/master/package.json#L11

The you will have all the static built files for the site. Then you can run npm run preview to start the web app.

The whole thing gets built to a static site, so you won't need vite or any of that stuff to run the site if you want a simpler setup. However, there's no command to server the static assets so you'd need to configure that however you like in the docker container.

jerkstorecaller commented 1 year ago

Thanks Ian. I didn't know npm was installing vite and tauri executables and they could be invoked using "npx ". I couldn't figure out how to install those tools.

The only change I ended up doing is making the startup command "npx run preview --host" because otherwise it only listens on localhost which is not reachable from outside the Prompta container.

So the final Dockerfile is:

FROM node:latest

WORKDIR /root
RUN git clone https://github.com/iansinnott/prompta \
       && cd prompta \
       && npm install \
       && npm run ui:build

WORKDIR /root/prompta
CMD ["npx", "vite", "preview", "--host"]

And an alternative docker-compose.yml from the OP which serves the above image publically on port 4173 (the one in the OP uses "expose"i nstead of "ports" which only works when you have a webserver in a different container reverse proxying to Prompta):

version: '3.8'
services:
  app:
    container_name: prompta
    ports:
      - '4173:4173'
    build:
      context: .
iansinnott commented 1 year ago

Great, thanks @jerkstorecaller !