Files
speckle-server/packages/preview-service/Dockerfile
T
Alexandru Popovici a385823b2d feat(viewer): objectloader2 integration (#4267)
* feat(viewer-sandbox): Made a sandbox function that will only invoke the object-loader loading objects

* first pass of creating an objectloader2

* updated build + added vitest

* try to get viewer sandbox to use new code

* sandbox type fix

* refactor a bit

* can download root

* intermediate commit for downloader/caching queue

* can download stuff!

* refactor files

* intro isBase and fix isString

* move single download to downloader

* fix download

* PR feedback

* some intermediate commit

* do clean up and download better

* clean up promises and linting

* can generate values while downloading and caching

* add a finish method

* remove unused functions

* remove asBase

* add temporary docs

* add more docs with mermaid

* add more test models

* add response validation

* add tests and redo options

* add test for download batch

* fix downloader tests and change Item to have clearer Base items

* add tests and refactor a little

* use fetch in downloader as an option

* use optional in-memory indexdb instead of monkey patching the global one

* more refactors for options for objectloader2

* add tests for objectloader2

* adjust single download

* benchmark loading and adjust ol2 batches

* download more!

* adjust to use hash privates

* refactored again with renaming

* cleanup

* make setupCacheDb throw instead

* use BatchedPool for downloads!

* fix tests

* adjust timings and add adaptive waiting

* Only wait if queue wasn't empty and queue size was full

* fix tests

* fix file names and some private usage

* fix interval and private usage

* rename vars

* use params for methods

* fix params for constructors and tests

* fix params for constructors and tests again

* using dexie

* faster settings but doesn't end well

* fixed end, optimized and removed logs

* fix tests

* fix types?

* update lock with WSL

* add e2e small model test

* fix/update yarn.lock

* Remove unused eslint ignore to fix pre-commit

* prettier fixes

* fix real DB usage

* rename methods to better match OL1

* rename methods to better match OL1 again

* add extra header collection

* add headers correctly

* test getTotalObjectCount

* feat(viewer-lib): Replaced old object loader with Adam's  objectloder2

* fix(viewer-lib): Removed the old object loader. Removed unneeded pause time in speckle loader

* Testing

* only deferred if not downloaded....don't save everything

* Lockfile

* pool isn't adjustable, adjust download buckets, dexie read is faster

* chore

* fix(viewer-lib): Fixed compiler errors

* fix getObject access with real indexeddb...adjust buffer for deferred access

* Fix disposal and pausing

* don't index item!

* fix dockerfiles to use OL2

* fix Dockerfile

* Fix dockerfile

* defer correctly and use record to add/lookup/remove to

* delete stuff correctly

* chore(sandbox): Enabled viewer loading

* use objects instead of arrays to avoid findIndex

* remove extra count

* add a found cache to avoid some db hits

* order matters for deferment

* move found map to deferment

* change option numbers

* 2 level cache with expiry

* defer everything, use loader to track what is requested....expire only found items

* add deferment disposal

* oops mismerge

* chore(sandbox): Default stream

* Beta version of CachePump and CacheReader

* Clean up initialization

* More clean up

* chore(objectloader2): Fixed CI compiler error

* chore(objectloader2): Fixed prettier

* add cachePump tests

* add cacheReader tests

* fixed more tests

* fixed final tests

* moving stuff around and lock return value

* try to move stuff out of objectloader2

* use a factory

* rename factory

* formatting

* eslist fixes

* try allocating no strings

* add comments

* small refactor and add another test

* fix deferment expiration and have test

* use byte size for max memory cache size

* fix deferment manager tests

* saved comment

* fix(viewer-sandbox): Fixed compiler error

* ignore tshy

* chore(frontend): Attempt to make viewer loading sequential

---------

Co-authored-by: Adam Hathcock <adam@hathcock.uk>
Co-authored-by: Kristaps Fabians Geikins <fabis94@live.com>
Co-authored-by: Iain Sproat <68657+iainsproat@users.noreply.github.com>
2025-05-21 10:05:50 +03:00

142 lines
5.4 KiB
Docker

# NOTE: Docker context should be set to git root directory, to include the viewer
FROM node:18-bookworm-slim@sha256:408f8cbbb7b33a5bb94bdb8862795a94d2b64c2d516856824fd86c4a5594a443 AS build-stage
ARG NODE_ENV=production
ENV NODE_ENV=${NODE_ENV}
WORKDIR /speckle-server
# install wait
ARG WAIT_VERSION=2.8.0
ENV WAIT_VERSION=${WAIT_VERSION}
RUN apt-get update -y \
&& DEBIAN_FRONTEND=noninteractive apt-get install -y \
--no-install-recommends \
ca-certificates=20230311 \
curl=7.88.1-10+deb12u12 \
&& curl -fsSL https://github.com/ufoscout/docker-compose-wait/releases/download/${WAIT_VERSION}/wait -o ./wait \
&& chmod +x ./wait \
&& apt-get remove -y curl \
&& apt-get autoremove -y \
&& apt-get clean \
&& rm -rf /var/lib/apt/lists/*
COPY .yarnrc.yml .
COPY .yarn ./.yarn
COPY package.json yarn.lock ./
# Only copy in the relevant package.json files for the dependencies
COPY packages/frontend-2/type-augmentations/stubs ./packages/frontend-2/type-augmentations/stubs/
COPY packages/preview-frontend/package.json ./packages/preview-frontend/
COPY packages/preview-service/package.json ./packages/preview-service/
COPY packages/viewer/package.json ./packages/viewer/
COPY packages/objectloader2/package.json ./packages/objectloader2/
COPY packages/shared/package.json ./packages/shared/
RUN PUPPETEER_SKIP_DOWNLOAD=true PLAYWRIGHT_SKIP_BROWSER_DOWNLOAD=1 yarn workspaces focus -A
# Only copy in the relevant source files for the dependencies
COPY packages/shared ./packages/shared/
COPY packages/objectloader2 ./packages/objectloader2/
COPY packages/viewer ./packages/viewer/
COPY packages/preview-frontend ./packages/preview-frontend/
COPY packages/preview-service ./packages/preview-service/
# This way the foreach only builds the frontend and its deps
RUN yarn workspaces foreach -W run build
# google-chrome-stable is only available for amd64 so we have to fix the platform
# hadolint ignore=DL3029
FROM --platform=linux/amd64 node:22-bookworm-slim@sha256:221ee67425de7a3c11ce4e81e63e50caaec82ede3a7d34599ab20e59d29a0cb5 AS node
SHELL ["/bin/bash", "-o", "pipefail", "-c"]
# Install tini and fonts
RUN apt-get update && \
DEBIAN_FRONTEND=noninteractive apt-get install -y \
--no-install-recommends \
# up to date ca-certs are required for downloading the google signing key
ca-certificates=20230311 \
tini=0.19.0-1 \
fonts-ipafont-gothic=00303-23 \
fonts-wqy-zenhei=0.9.45-8 \
fonts-thai-tlwg=1:0.7.3-1 \
fonts-kacst=2.01+mry-15 \
fonts-freefont-ttf=20120503-10 \
libxss1=1:1.2.3-1 \
# libegl1 & libxext6 are required for hardware accelarated rendering to work
libegl1=1.6.0-1 \
libxext6=2:1.3.4-1+b1 && \
# Clean up
apt-get clean && \
rm -rf /var/lib/apt/lists/*
# hadolint ignore=DL3015
RUN apt-get update && \
DEBIAN_FRONTEND=noninteractive apt-get install -y \
# --no-install-recommends # This is causing issues with the google-chrome-stable install as not all gpg components are installed if recommended installs are disabled
gnupg=2.2.40-1.1 && \
# Clean up
apt-get clean && \
rm -rf /var/lib/apt/lists/*
COPY --link --from=build-stage /speckle-server/wait /wait
ARG NODE_ENV
ENV NODE_ENV=${NODE_ENV}
WORKDIR /speckle-server
COPY .yarnrc.yml .
COPY .yarn ./.yarn
COPY package.json yarn.lock ./
# Only copy in the relevant package.json files for the dependencies
COPY packages/preview-service/package.json ./packages/preview-service/
WORKDIR /speckle-server/packages
COPY --link --from=build-stage /speckle-server/packages/shared ./shared
COPY --link --from=build-stage /speckle-server/packages/preview-service ./preview-service
COPY --link --from=build-stage /speckle-server/packages/preview-frontend/dist ./preview-service/public
WORKDIR /speckle-server/packages/preview-service
RUN PUPPETEER_SKIP_DOWNLOAD=true PLAYWRIGHT_SKIP_BROWSER_DOWNLOAD=1 yarn workspaces focus --production
RUN groupadd -g 30000 -r pptruser && \
useradd -r -g pptruser -G audio,video -u 800 pptruser && \
mkdir -p /home/pptruser/Downloads && \
chown -R pptruser:pptruser /home/pptruser && \
chown -R pptruser:pptruser ./node_modules && \
chown -R pptruser:pptruser ./package.json
# overriding this value via `--build-arg CACHE_BUST=$(date +%s)` will cause the latest google chrome to be fetched
ARG CACHE_BUST=1
# install google chrome
# hadolint ignore=DL3008
RUN apt-get update && \
DEBIAN_FRONTEND=noninteractive apt-get install -y \
--no-install-recommends \
# wget has different versions for different architectures so we cannot pin version
wget && \
wget -q -O - https://dl-ssl.google.com/linux/linux_signing_key.pub | gpg --dearmor -o /usr/share/keyrings/googlechrome-linux-keyring.gpg && \
sh -c 'echo "deb [arch=amd64 signed-by=/usr/share/keyrings/googlechrome-linux-keyring.gpg] https://dl-ssl.google.com/linux/chrome/deb/ stable main" >> /etc/apt/sources.list.d/google.list' && \
# remove wget after use
DEBIAN_FRONTEND=noninteractive apt-get remove -y \
wget && \
# update packages in order to use google chrome repo
apt-get update && \
DEBIAN_FRONTEND=noninteractive apt-get install -y \
--no-install-recommends \
google-chrome-stable && \
# Clean up
apt-get clean && \
rm -rf /var/lib/apt/lists/*
ENV CHROMIUM_EXECUTABLE_PATH="/usr/bin/google-chrome"
ENV USER_DATA_DIR='/tmp/puppeteer'
# Run everything after as non-privileged user.
USER pptruser
CMD [ "tini", "--", "node", "--loader=./dist/bootstrap.js", "dist/main.js" ]