Dockerfile 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. # syntax = docker/dockerfile:1.4
  2. ARG NODE_VERSION=24
  3. ARG OPT_DIR="/opt"
  4. ##
  5. ## base
  6. ##
  7. FROM node:${NODE_VERSION}-slim AS base
  8. ARG OPT_DIR
  9. WORKDIR $OPT_DIR
  10. # Activate corepack so the pnpm version pinned in the workspace package.json
  11. # "packageManager" field is used (avoids drift between Dockerfile and local/CI).
  12. RUN corepack enable
  13. ENV PNPM_HOME="/pnpm"
  14. ENV PATH="$PNPM_HOME/bin:$PATH"
  15. # install turbo
  16. # Note: no cache mount here — pnpm global install links binaries into the store,
  17. # and the BuildKit cache mount would be unmounted after RUN, breaking those links.
  18. RUN pnpm add turbo --global
  19. ##
  20. ## builder
  21. ##
  22. FROM base AS builder
  23. WORKDIR $OPT_DIR
  24. COPY . .
  25. RUN --mount=type=cache,id=pnpm,target=/pnpm/store \
  26. pnpm install --frozen-lockfile --ignore-scripts
  27. # build
  28. RUN turbo run clean
  29. RUN turbo run build --filter @growi/pdf-converter
  30. # make artifacts
  31. RUN pnpm deploy out --prod --legacy --filter @growi/pdf-converter
  32. RUN rm -rf apps/pdf-converter/node_modules && mv out/node_modules apps/pdf-converter/node_modules
  33. RUN tar -zcf /tmp/packages.tar.gz \
  34. package.json \
  35. apps/pdf-converter/package.json \
  36. apps/pdf-converter/dist \
  37. apps/pdf-converter/.env \
  38. apps/pdf-converter/node_modules
  39. ##
  40. ## release
  41. ##
  42. ARG NODE_VERSION=24
  43. FROM node:${NODE_VERSION}-slim
  44. LABEL maintainer="Yuki Takei <yuki@weseek.co.jp>"
  45. ARG OPT_DIR
  46. ENV NODE_ENV="production"
  47. ENV PUPPETEER_EXECUTABLE_PATH="/usr/bin/chromium"
  48. ENV LANG="ja_JP.UTF-8"
  49. ENV appDir="$OPT_DIR/pdf-converter"
  50. RUN --mount=type=cache,target=/var/lib/apt,sharing=locked \
  51. --mount=type=cache,target=/var/cache/apt,sharing=locked \
  52. apt-get update; \
  53. apt-get install -y chromium fonts-lato fonts-ipafont-gothic fonts-noto-cjk gosu; \
  54. rm -rf /var/lib/apt/lists/*; \
  55. # verify that the binary works
  56. gosu nobody true
  57. # extract artifacts as 'node' user
  58. USER node
  59. WORKDIR ${appDir}
  60. RUN --mount=type=bind,from=builder,source=/tmp/packages.tar.gz,target=/tmp/packages.tar.gz \
  61. tar -zxf /tmp/packages.tar.gz -C ${appDir}/
  62. COPY --chown=node:node --chmod=700 apps/pdf-converter/docker/docker-entrypoint.sh /
  63. USER root
  64. WORKDIR ${appDir}/apps/pdf-converter
  65. EXPOSE 3010
  66. ENTRYPOINT ["/docker-entrypoint.sh"]