Dockerfile 3.2 KB

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