Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix or improve client build docs #32

Open
struanb opened this issue Jan 18, 2024 · 2 comments
Open

Fix or improve client build docs #32

struanb opened this issue Jan 18, 2024 · 2 comments

Comments

@struanb
Copy link
Contributor

struanb commented Jan 18, 2024

I am trying to build my own client talking to its own sync server.

I have built the sync server using docker build -t prompta . and run it using docker run --name=prompta -p 8080:8080 prompta.

To use it, I understand I have to serve the client over http to allow it to access the server on http://0.0.0.0:8080/.

  1. If I try to build the client as per https://github.com/iansinnott/prompta?tab=readme-ov-file#developing I get the following errors:
$ docker run --rm -it -v ~/Downloads/prompta/:/prompta --entrypoint=/bin/bash -w /prompta node:20

root@430ead86902b:/prompta# npm install
npm notice 
npm notice New minor version of npm available! 10.2.4 -> 10.3.0
npm notice Changelog: https://github.com/npm/cli/releases/tag/v10.3.0
npm notice Run npm install -g [email protected] to update!
npm notice 
npm ERR! code ERESOLVE
npm ERR! ERESOLVE could not resolve
npm ERR! 
npm ERR! While resolving: [email protected]
npm ERR! Found: [email protected]
npm ERR! node_modules/svelte
npm ERR!   dev svelte@"^4.0.0" from the root project
npm ERR!   peer svelte@"^3.55.0" from [email protected]
npm ERR!   node_modules/svelte-check
npm ERR!     dev svelte-check@"~3.4.6" from the root project
npm ERR!   3 more (svelte-preprocess, svelte-preprocess, @sveltejs/kit)
npm ERR! 
npm ERR! Could not resolve dependency:
npm ERR! bits-ui@"^0.11.8" from the root project
npm ERR! 
npm ERR! Conflicting peer dependency: [email protected]
npm ERR! node_modules/svelte
npm ERR!   peer svelte@"^4.0.0" from [email protected]
npm ERR!   node_modules/bits-ui
npm ERR!     bits-ui@"^0.11.8" from the root project
npm ERR! 
npm ERR! Fix the upstream dependency conflict, or retry
npm ERR! this command with --force or --legacy-peer-deps
npm ERR! to accept an incorrect (and potentially broken) dependency resolution.
npm ERR! 
npm ERR! 
npm ERR! For a full report see:
npm ERR! /root/.npm/_logs/2024-01-18T22_47_16_576Z-eresolve-report.txt

npm ERR! A complete log of this run can be found in: /root/.npm/_logs/2024-01-18T22_47_16_576Z-debug-0.log

root@430ead86902b:/prompta# npm run build

> [email protected] build
> tauri build

       Error failed to get cargo metadata: No such file or directory (os error 2)
  1. Alternatively if I try using pnpm as per the Dockerfile I get this error:
root@430ead86902b:/prompta# apt-get update; apt install -y curl python-is-python3 pkg-config build-essential
Get:1 http://deb.debian.org/debian bookworm InRelease [151 kB]
Get:2 http://deb.debian.org/debian bookworm-updates InRelease [52.1 kB]
Get:3 http://deb.debian.org/debian-security bookworm-security InRelease [48.0 kB]
Get:4 http://deb.debian.org/debian bookworm/main arm64 Packages [8685 kB]
Get:5 http://deb.debian.org/debian bookworm-updates/main arm64 Packages [12.5 kB]
Get:6 http://deb.debian.org/debian-security bookworm-security/main arm64 Packages [132 kB]
Fetched 9080 kB in 2s (4275 kB/s)                         
Reading package lists... Done
Reading package lists... Done
Building dependency tree... Done
Reading state information... Done
curl is already the newest version (7.88.1-10+deb12u5).
pkg-config is already the newest version (1.8.1-1).
pkg-config set to manually installed.
The following NEW packages will be installed:
  build-essential python-is-python3
0 upgraded, 2 newly installed, 0 to remove and 0 not upgraded.
Need to get 10.7 kB of archives.
After this operation, 35.8 kB of additional disk space will be used.
Get:1 http://deb.debian.org/debian bookworm/main arm64 build-essential arm64 12.9 [7704 B]
Get:2 http://deb.debian.org/debian bookworm/main arm64 python-is-python3 all 3.11.1-3 [3000 B]
Fetched 10.7 kB in 0s (41.2 kB/s)           
debconf: delaying package configuration, since apt-utils is not installed
Selecting previously unselected package build-essential.
(Reading database ... 23282 files and directories currently installed.)
Preparing to unpack .../build-essential_12.9_arm64.deb ...
Unpacking build-essential (12.9) ...
Selecting previously unselected package python-is-python3.
Preparing to unpack .../python-is-python3_3.11.1-3_all.deb ...
Unpacking python-is-python3 (3.11.1-3) ...
Setting up build-essential (12.9) ...
Setting up python-is-python3 (3.11.1-3) ...
root@430ead86902b:/prompta# npm install -g pnpm

added 1 package in 1s

1 package is looking for funding
  run `npm fund` for details
root@430ead86902b:/prompta# pnpm install
Lockfile is up to date, resolution step is skipped
Packages: +411
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 ERR_PNPM_LINKING_FAILED  Error: ENOENT: no such file or directory, copyfile '/prompta/.pnpm-store/v3/files/4e/e1c88f8c3f4e4cd34cb6c00339bf9d6d036ff4ade3af49e871cc8966b84c729d8b75492acc6413c9a664ac00a57958223ac13c4229da8c62ebe6a53e4f783f' -> '/prompta/node_modules/.pnpm/[email protected][email protected]/node_modules/bits-ui_tmp_247/dist/bits/select/_types.js'
Progress: resolved 411, reused 0, downloaded 105, added 89
@iansinnott
Copy link
Owner

The server build should be relatively simple since it only requires typescript compilation (no bundling, and no Rust dependencies). Try building the server directly first:

pnpm i
pnpm tsc -p ./tsconfig.server.json

At that point it's a standard node.js server which you can run via:

node ./dist-server/server.js

@struanb
Copy link
Contributor Author

struanb commented Feb 4, 2024

Thanks for this. These commands do (now) work, and it turns out at least part of my problem was that I was trying to build inside a repo directory that was bind-mounted from my Mac. This led to the ERR_PNPM_LINKING_FAILED error. Additionally, I found that building from source on an overlay filesystem (e.g. inside a plain docker container) can cause node-gyp build to fail.

Building inside a fresh copy of the repo in a Docker volume inside a container, or using docker build seems to work (and I don't really know why the docker build failed before when I raised this issue).

I've also managed to launch my sync server behind https and resync my local chat.prompta.dev storage to it. So far so good!

I also managed to build and load the client, but had to add NODE_OPTIONS="--max-old-space-size=2048" before pnpm build ui:build and pnpm build ui:build-static.

I think you can close this issue, but I suggest modifying Dockerfile and docs to add NODE_OPTIONS="--max-old-space-size=2048" to the client build instructions.

It would be neat if the sync server could also serve the static client, so that everything can be built and run off one IP and port. In the meantime here is a Dockerfile that builds and (hackily) serves both client and sync server.

FROM node:20 as builder

RUN apt-get update; apt install -y curl python-is-python3 pkg-config build-essential
RUN mkdir /app
WORKDIR /app

COPY . .

RUN npm install -g pnpm
RUN pnpm install
RUN sed -r -i.bak 's!https://prompta-production.up.railway.app!http://localhost:8081!' src/lib/sync/vlcn.ts
RUN pnpm run build:server

RUN NODE_OPTIONS="--max-old-space-size=2048" pnpm run ui:build

EXPOSE 8080
EXPOSE 8081

CMD [ "bash", "-c", "PORT=8081 node ./dist-server/server.js & pnpm run preview --host 0.0.0.0 --port 8080" ]

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants