Skip to content

Commit dffe9d6

Browse files
committed
Fix Dockerfile: restructure multi-stage build for pnpm workspace
1 parent ea9146d commit dffe9d6

1 file changed

Lines changed: 31 additions & 22 deletions

File tree

Dockerfile

Lines changed: 31 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -56,37 +56,41 @@ RUN curl -fsSL https://deb.nodesource.com/setup_${NODE_VERSION}.x | bash - \
5656
WORKDIR ${DISCOURSE_HOME}
5757

5858
# =============================================================================
59-
# 依赖阶段 - 安装 Gem 和 npm 包
59+
# Ruby 依赖阶段
6060
# =============================================================================
61-
FROM base AS dependencies
61+
FROM base AS ruby-dependencies
6262

63-
# 复制依赖文件
6463
COPY Gemfile Gemfile.lock ./
65-
COPY package.json pnpm-lock.yaml pnpm-workspace.yaml ./
66-
67-
# 复制所有 frontend 子项目的 package.json
68-
COPY frontend/discourse/package.json frontend/discourse/
69-
COPY frontend/asset-processor/package.json frontend/asset-processor/
70-
COPY frontend/discourse-i18n/package.json frontend/discourse-i18n/
71-
COPY frontend/discourse-markdown-it/package.json frontend/discourse-markdown-it/
72-
COPY frontend/discourse-types/package.json frontend/discourse-types/
73-
COPY frontend/deprecation-silencer/package.json frontend/deprecation-silencer/
74-
COPY frontend/custom-proxy/package.json frontend/custom-proxy/
75-
COPY frontend/ember-cli-progress-ci/package.json frontend/ember-cli-progress-ci/
76-
COPY frontend/pretty-text/package.json frontend/pretty-text/
77-
78-
# 安装 Ruby gems
64+
7965
RUN bundle config set --local deployment 'true' \
8066
&& bundle config set --local without 'development test' \
8167
&& bundle install --jobs $(nproc) --retry 3
8268

69+
# =============================================================================
70+
# Node 依赖阶段
71+
# =============================================================================
72+
FROM base AS node-dependencies
73+
74+
# 复制项目文件(pnpm workspace 需要完整项目结构)
75+
COPY . .
76+
8377
# 安装 Node.js 包
84-
RUN pnpm install --frozen-lockfile
78+
RUN pnpm install --frozen-lockfile || pnpm install
8579

8680
# =============================================================================
8781
# 构建阶段 - 编译前端资源
8882
# =============================================================================
89-
FROM dependencies AS build
83+
FROM base AS build
84+
85+
# 复制 Ruby 依赖
86+
COPY --from=ruby-dependencies ${BUNDLE_PATH} ${BUNDLE_PATH}
87+
COPY --from=ruby-dependencies ${DISCOURSE_HOME}/.bundle ${DISCOURSE_HOME}/.bundle
88+
89+
# 复制 Node 依赖
90+
COPY --from=node-dependencies ${DISCOURSE_HOME}/node_modules ${DISCOURSE_HOME}/node_modules
91+
COPY --from=node-dependencies ${DISCOURSE_HOME}/frontend ${DISCOURSE_HOME}/frontend
92+
COPY --from=node-dependencies ${DISCOURSE_HOME}/plugins ${DISCOURSE_HOME}/plugins
93+
COPY --from=node-dependencies ${DISCOURSE_HOME}/themes ${DISCOURSE_HOME}/themes
9094

9195
# 复制源代码
9296
COPY . .
@@ -112,12 +116,17 @@ RUN apt-get update && apt-get install -y --no-install-recommends \
112116
# 创建 discourse 用户
113117
RUN groupadd -r discourse && useradd -r -g discourse -d ${DISCOURSE_HOME} discourse
114118

115-
# 复制依赖
116-
COPY --from=dependencies ${BUNDLE_PATH} ${BUNDLE_PATH}
117-
COPY --from=dependencies ${DISCOURSE_HOME}/node_modules ${DISCOURSE_HOME}/node_modules
119+
# 复制 Ruby 依赖
120+
COPY --from=ruby-dependencies ${BUNDLE_PATH} ${BUNDLE_PATH}
121+
COPY --from=ruby-dependencies ${DISCOURSE_HOME}/.bundle ${DISCOURSE_HOME}/.bundle
122+
123+
# 复制 Node 依赖
124+
COPY --from=node-dependencies ${DISCOURSE_HOME}/node_modules ${DISCOURSE_HOME}/node_modules
118125

119126
# 复制源代码
120127
COPY --chown=discourse:discourse . .
128+
129+
# 复制编译后的资源
121130
COPY --from=build --chown=discourse:discourse ${DISCOURSE_HOME}/public/assets ${DISCOURSE_HOME}/public/assets
122131

123132
# 创建必要的目录

0 commit comments

Comments
 (0)