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

Docker support #223

Open
aliuq opened this issue Aug 27, 2024 · 2 comments
Open

Docker support #223

aliuq opened this issue Aug 27, 2024 · 2 comments

Comments

@aliuq
Copy link

aliuq commented Aug 27, 2024

srcbook is a great project

The current api and shared build methods will cause the image size to be too large, it contains some devDependencies for start works, I don’t know if there is any reason for this design.

Some thoughts on containers, there should be two images, one web and one api. After the web image is built, use nginx/apache to run it. After the api image is built, use node to run it.

Useful library building tools,tsup and unbuild

@benjreinhart
Copy link
Contributor

Hey @aliuq thanks for this. We may support docker eventually but it's not a priority at this time.

Are you interested in docker for running this locally, developing against the repo, or are you trying to host srcbook?

@aliuq
Copy link
Author

aliuq commented Aug 29, 2024

@benjreinhart Hi, I tried a rebuild and during the process I found that the @srcbook/api package has a few packages that cannot be packaged into the esm output type, and also after the build, when accessing the portal using the separate SRCBOOK_CONFIG.api.host, there is a websocket connectivity error, so it is a bit tricky to split the web and api into two images at the moment.

On the contrary, building the container with the official npm package is much easier, the only problem is that some extra files are bundled with the container, resulting in a large image size.

I've built an image aliuq/srcbook, which is not fully tested for functionality and may be missing relevant dependencies.

Dockerfile

FROM node:22.7.0-alpine3.20 AS builder
WORKDIR /app

RUN yarn add srcbook && \
  mv node_modules/srcbook . && \
  rm node_modules yarn.lock package.json -rf && \
  mv srcbook/* . && \
  rm node_modules -rf && \
  yarn install --prod && \
  find ./node_modules -type f \( -name "*.d.ts" -o -name "*.log" -o -name "*.bak" -o -name "DS_Store" -o -name "LICENSE" -o -name "*.d.mts" -o -name "*.txt" \) -delete

FROM node:22.7.0-alpine3.20 AS runner
WORKDIR /app

COPY --from=builder /app .
CMD [ "node", "bin/cli.mjs", "start" ]

EXPOSE 2150
VOLUME /root/.srcbook
VOLUME /root/.npm

Usage

# Start
docker run -p 2150:2150 -v $PWD/srcbookData:/root/.srcbook --name srcbook aliuq/srcbook

# Stop
docker rm srcbook -f

# Exec
docker exec -it srcbook /bin/sh

It would be nice to start building from web and api!

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