Dockerfile 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  1. # syntax=docker/dockerfile:1
  2. ARG NODE_VERSION=24
  3. ARG OPT_DIR="/opt"
  4. ##
  5. ## base — official Node.js image with pnpm + turbo
  6. ##
  7. FROM node:24-bookworm 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 globally
  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. ## pruner — turbo prune for Docker-optimized monorepo subset
  21. ##
  22. FROM base AS pruner
  23. ARG OPT_DIR
  24. WORKDIR $OPT_DIR
  25. COPY . .
  26. # Include @growi/pdf-converter because @growi/pdf-converter-client has a turbo
  27. # task dependency on @growi/pdf-converter#gen:swagger-spec (generates the OpenAPI
  28. # spec that orval uses to build the client). Without it, turbo cannot resolve
  29. # the cross-package task dependency in the pruned workspace.
  30. RUN turbo prune @growi/app @growi/pdf-converter --docker
  31. ##
  32. ## deps — dependency installation (layer cached when only source changes)
  33. ##
  34. FROM base AS deps
  35. ARG OPT_DIR
  36. WORKDIR $OPT_DIR
  37. # Copy only package manifests and lockfile for dependency caching
  38. COPY --from=pruner $OPT_DIR/out/json/ .
  39. # --ignore-scripts: postinstall (prisma generate) needs full source, runs in builder stage.
  40. RUN --mount=type=cache,id=pnpm,target=/pnpm/store \
  41. pnpm install --frozen-lockfile --ignore-scripts
  42. ##
  43. ## builder — build + produce artifacts
  44. ##
  45. FROM deps AS builder
  46. ARG OPT_DIR
  47. WORKDIR $OPT_DIR
  48. # Copy full source on top of installed dependencies
  49. COPY --from=pruner $OPT_DIR/out/full/ .
  50. # turbo prune does not include root-level config files in its output.
  51. # tsconfig.base.json is referenced by most packages via "extends": "../../tsconfig.base.json"
  52. COPY tsconfig.base.json .
  53. # Build
  54. RUN turbo run clean
  55. RUN turbo run build --filter @growi/app
  56. # Produce artifacts
  57. RUN bash apps/app/bin/assemble-prod.sh
  58. # Stage artifacts into a clean directory for COPY --from
  59. RUN mkdir -p /tmp/release/apps/app && \
  60. cp package.json /tmp/release/ && \
  61. cp -a node_modules /tmp/release/ && \
  62. cp -a apps/app/.next apps/app/config apps/app/dist apps/app/public \
  63. apps/app/resource apps/app/tmp \
  64. apps/app/package.json apps/app/node_modules \
  65. apps/app/next.config.js \
  66. /tmp/release/apps/app/ && \
  67. (cp apps/app/.env.production* /tmp/release/apps/app/ 2>/dev/null || true)
  68. ##
  69. ## release — DHI runtime (no shell, no additional binaries)
  70. ##
  71. FROM dhi.io/node:24-debian13 AS release
  72. ARG OPT_DIR
  73. ENV NODE_ENV="production"
  74. ENV appDir="$OPT_DIR/growi"
  75. # Copy artifacts from builder (no shell required)
  76. WORKDIR ${appDir}
  77. COPY --from=builder --chown=node:node /tmp/release/ ${appDir}/
  78. # Copy TypeScript entrypoint
  79. COPY --chown=node:node apps/app/docker/docker-entrypoint.ts /docker-entrypoint.ts
  80. # Switch back to root for entrypoint (it handles privilege drop)
  81. USER root
  82. WORKDIR ${appDir}/apps/app
  83. # OCI standard labels
  84. LABEL org.opencontainers.image.source="https://github.com/weseek/growi"
  85. LABEL org.opencontainers.image.title="GROWI"
  86. LABEL org.opencontainers.image.description="Team collaboration wiki using Markdown"
  87. LABEL org.opencontainers.image.vendor="WESEEK, Inc."
  88. VOLUME /data
  89. EXPOSE 3000
  90. ENTRYPOINT ["node", "/docker-entrypoint.ts"]