Dockerfile 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  1. # syntax = docker/dockerfile:1
  2. ##
  3. ## base
  4. ##
  5. FROM node:20-slim AS base
  6. ENV optDir=/opt
  7. WORKDIR ${optDir}
  8. # install tools
  9. RUN apt-get update && apt-get install -y ca-certificates wget curl --no-install-recommends
  10. # install git and git-lfs
  11. RUN curl -s https://packagecloud.io/install/repositories/github/git-lfs/script.deb.sh | bash \
  12. && apt-get update && apt-get install -y git git-lfs --no-install-recommends \
  13. && git lfs install
  14. # install pnpm
  15. RUN wget -qO- https://get.pnpm.io/install.sh | ENV="$HOME/.shrc" SHELL="$(which sh)" sh -
  16. ENV PNPM_HOME="/root/.local/share/pnpm"
  17. ENV PATH="$PNPM_HOME:$PATH"
  18. # install turbo
  19. RUN pnpm add turbo --global
  20. ##
  21. ## builder
  22. ##
  23. FROM base AS builder
  24. ENV optDir=/opt
  25. WORKDIR ${optDir}
  26. COPY . .
  27. RUN pnpm add node-gyp --global
  28. RUN pnpm install ---frozen-lockfile
  29. # build
  30. RUN turbo run clean
  31. RUN turbo run build --filter @growi/app
  32. # make artifacts
  33. RUN pnpm deploy out --prod --filter @growi/app
  34. RUN rm -rf apps/app/node_modules && mv out/node_modules apps/app/node_modules
  35. RUN rm -rf apps/app/.next/cache
  36. RUN tar -zcf packages.tar.gz \
  37. package.json \
  38. apps/app/.next \
  39. apps/app/config \
  40. apps/app/dist \
  41. apps/app/public \
  42. apps/app/resource \
  43. apps/app/tmp \
  44. apps/app/.env.production* \
  45. apps/app/next.config.js \
  46. apps/app/package.json \
  47. apps/app/node_modules
  48. ##
  49. ## release
  50. ##
  51. FROM node:20-slim
  52. LABEL maintainer="Yuki Takei <yuki@weseek.co.jp>"
  53. ENV NODE_ENV="production"
  54. ENV optDir=/opt
  55. ENV appDir=${optDir}/growi
  56. # Add gosu
  57. # see: https://github.com/tianon/gosu/blob/1.13/INSTALL.md
  58. RUN set -eux; \
  59. apt-get update; \
  60. apt-get install -y gosu; \
  61. rm -rf /var/lib/apt/lists/*; \
  62. # verify that the binary works
  63. gosu nobody true
  64. # Add pnpm for 'node' user
  65. RUN apt-get update && apt-get install -y sudo ca-certificates wget --no-install-recommends \
  66. && wget -qO- https://get.pnpm.io/install.sh | ENV="$HOME/.shrc" SHELL="$(which sh)" sudo -u node sh - \
  67. && apt-get purge -y --auto-remove -o APT::AutoRemove::RecommendsImportant=false
  68. ENV PNPM_HOME="/home/node/.local/share/pnpm"
  69. ENV PATH="$PNPM_HOME:$PATH"
  70. COPY --from=builder --chown=node:node \
  71. ${optDir}/packages.tar.gz ${appDir}/
  72. # extract artifacts as 'node' user
  73. USER node
  74. WORKDIR ${appDir}
  75. RUN tar -zxf packages.tar.gz && rm packages.tar.gz
  76. COPY --chown=node:node --chmod=700 apps/app/docker/docker-entrypoint.sh /
  77. USER root
  78. WORKDIR ${appDir}/apps/app
  79. VOLUME /data
  80. EXPOSE 3000
  81. ENTRYPOINT ["/docker-entrypoint.sh"]
  82. CMD ["pnpm run migrate && node -r dotenv-flow/config --expose_gc dist/server/app.js"]