Dockerfile 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. # syntax = docker/dockerfile:1
  2. ARG NODE_VERSION=24
  3. ##
  4. ## base
  5. ##
  6. FROM node:${NODE_VERSION}-slim AS base
  7. ENV optDir="/opt"
  8. WORKDIR ${optDir}
  9. # Activate corepack so the pnpm version pinned in the workspace package.json
  10. # "packageManager" field is used (avoids drift between Dockerfile and local/CI).
  11. RUN corepack enable
  12. ENV PNPM_HOME="/pnpm"
  13. ENV PATH="$PNPM_HOME/bin:$PATH"
  14. # install turbo
  15. # Note: no cache mount here — pnpm global install links binaries into the store,
  16. # and the BuildKit cache mount would be unmounted after RUN, breaking those links.
  17. RUN pnpm add turbo --global
  18. ##
  19. ## builder
  20. ##
  21. FROM base AS builder
  22. ENV optDir="/opt"
  23. WORKDIR ${optDir}
  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 build --filter @growi/slackbot-proxy
  29. # make artifacts
  30. RUN pnpm deploy out --prod --legacy --filter @growi/slackbot-proxy
  31. RUN rm -rf apps/slackbot-proxy/node_modules && mv out/node_modules apps/slackbot-proxy/node_modules
  32. RUN tar -zcf packages.tar.gz \
  33. package.json \
  34. apps/slackbot-proxy/package.json \
  35. apps/slackbot-proxy/dist \
  36. apps/slackbot-proxy/.env \
  37. apps/slackbot-proxy/node_modules
  38. ##
  39. ## release
  40. ##
  41. ARG NODE_VERSION=24
  42. FROM node:${NODE_VERSION}-slim
  43. LABEL maintainer="Yuki Takei <yuki@weseek.co.jp>"
  44. ENV NODE_ENV="production"
  45. ENV optDir="/opt"
  46. ENV appDir="${optDir}/slackbot-proxy"
  47. # copy artifacts
  48. COPY --from=builder --chown=node:node \
  49. ${optDir}/packages.tar.gz ${appDir}/
  50. # extract artifacts as 'node' user
  51. USER node
  52. WORKDIR ${appDir}
  53. RUN tar -xf packages.tar.gz && rm packages.tar.gz
  54. WORKDIR ${appDir}/apps/slackbot-proxy
  55. EXPOSE 8080
  56. CMD ["node", "-r", "dotenv-flow/config", "dist/index.js"]