使用 rollup 的 Yarn 构建在 docker 构建过程中挂起
Yarn build using rollup hangs in docker build process
我正在尝试为 svelte 应用程序创建 docker 图像。我正在使用的 svelte 应用程序只是启动了 TypeScript 的 svelte 模板。我没有对应用程序本身进行任何更改,我唯一的目标是使用 Docker 为 svelte 应用程序提供服务。我使用 yarn berry (v2) 作为我的包管理器,并使用 rollupjs 进行构建过程。这是我的第一个问题,如果有什么遗漏请告诉我。
我期待构建图像,但是当构建过程到达“yarn build”命令时,它永远不会完成。它也不会崩溃,但也不会完成构建步骤。好像挂在打包步骤:
=> => # src/main.ts → public/build/bundle.js...
来自 package.json 的构建命令:
"build": "rollup -c"
我的 Docker 文件最初是从这里获取的:https://sveltesociety.dev/recipes/publishing-and-deploying/dockerize-a-svelte-app/. However, I had to make some changes to it for yarn v2 and I found the following stack thread: Using Yarn 2 (Berry) for packaging application in a Docker image。添加一些修改形式,这个问题给我留下了以下 Docker 文件:
WORKDIR /app
COPY package.json ./
RUN yarn set version berry
COPY .yarn ./.yarn
COPY yarn.lock .yarnrc.yml ./
RUN yarn plugin import workspace-tools
RUN yarn workspaces focus -A --production
COPY . ./
RUN yarn build # This is where it gets stuck
FROM nginx:1.19-alpine
COPY --from=build /app/public /usr/share/nginx/html
我 运行 命令 docker build -t svelte-image .
构建,这是我得到的输出:
[+] Building 572.6s (16/18)
=> [internal] load build definition from Dockerfile 0.0s
=> => transferring dockerfile: 37B 0.0s
=> [internal] load .dockerignore 0.0s
=> => transferring context: 34B 0.0s
=> [internal] load metadata for docker.io/library/nginx:1.19-alpine 1.2s
=> [internal] load metadata for docker.io/library/node:12 1.1s
=> CACHED [stage-1 1/2] FROM docker.io/library/nginx:1.19-alpine@sha256:07ab71a2c8e4ecb19a5a5abcfb3a4f175946c001c8af288b1aa766d67b0 0.0s
=> CACHED [build 1/6] FROM docker.io/library/node:12@sha256:cc4adb82efc04b74b9f96326e682ad04be2df84d23e40609802eb6d6c207abde 0.0s
=> [internal] load build context 0.1s
=> => transferring context: 69.58kB 0.0s
=> CACHED [stage-1 2/3] RUN rm /etc/nginx/nginx.conf /etc/nginx/conf.d/default.conf 0.0s
=> CACHED [build 2/10] WORKDIR /app 0.0s
=> CACHED [build 3/10] COPY package.json ./ 0.0s
=> CACHED [build 4/10] RUN yarn set version berry 0.0s
=> [build 5/10] COPY .yarn ./.yarn 0.2s
=> [build 6/10] COPY yarn.lock .yarnrc.yml ./ 0.0s
=> [build 7/10] RUN yarn plugin import workspace-tools 1.5s
=> [build 8/10] RUN yarn workspaces focus -A --production 0.5s
=> [build 9/10] COPY . ./ 0.1s
=> [build 10/10] RUN yarn build 568.9s
=> => # src/main.ts → public/build/bundle.js... # -> Never completes
我一直在试图找出构建挂起的原因,但我无法找到错误的来源。使用 yarn build 在本地构建时它工作得很好。有没有人知道为什么它在捆绑过程中挂起?
我没弄清楚哪里出了问题,但我成功地构建了 docker 图像并 运行 它成功了。这是工作的 Dockerfile:
FROM node:16 AS build
WORKDIR /app
COPY package.json ./
RUN yarn set version berry
COPY .yarn ./.yarn #
COPY yarn.lock .yarnrc.yml ./
RUN yarn install
# These two lines are from the original example. It did not work to use this,
# but I leave it here to highlight the difference
## RUN yarn plugin import workspace-tools
## RUN yarn workspaces focus -A --production
COPY . ./
RUN yarn build
FROM nginx:1.19-alpine
COPY --from=build /app/public /usr/share/nginx/html
我正在尝试为 svelte 应用程序创建 docker 图像。我正在使用的 svelte 应用程序只是启动了 TypeScript 的 svelte 模板。我没有对应用程序本身进行任何更改,我唯一的目标是使用 Docker 为 svelte 应用程序提供服务。我使用 yarn berry (v2) 作为我的包管理器,并使用 rollupjs 进行构建过程。这是我的第一个问题,如果有什么遗漏请告诉我。
我期待构建图像,但是当构建过程到达“yarn build”命令时,它永远不会完成。它也不会崩溃,但也不会完成构建步骤。好像挂在打包步骤:
=> => # src/main.ts → public/build/bundle.js...
来自 package.json 的构建命令:
"build": "rollup -c"
我的 Docker 文件最初是从这里获取的:https://sveltesociety.dev/recipes/publishing-and-deploying/dockerize-a-svelte-app/. However, I had to make some changes to it for yarn v2 and I found the following stack thread: Using Yarn 2 (Berry) for packaging application in a Docker image。添加一些修改形式,这个问题给我留下了以下 Docker 文件:
WORKDIR /app
COPY package.json ./
RUN yarn set version berry
COPY .yarn ./.yarn
COPY yarn.lock .yarnrc.yml ./
RUN yarn plugin import workspace-tools
RUN yarn workspaces focus -A --production
COPY . ./
RUN yarn build # This is where it gets stuck
FROM nginx:1.19-alpine
COPY --from=build /app/public /usr/share/nginx/html
我 运行 命令 docker build -t svelte-image .
构建,这是我得到的输出:
[+] Building 572.6s (16/18)
=> [internal] load build definition from Dockerfile 0.0s
=> => transferring dockerfile: 37B 0.0s
=> [internal] load .dockerignore 0.0s
=> => transferring context: 34B 0.0s
=> [internal] load metadata for docker.io/library/nginx:1.19-alpine 1.2s
=> [internal] load metadata for docker.io/library/node:12 1.1s
=> CACHED [stage-1 1/2] FROM docker.io/library/nginx:1.19-alpine@sha256:07ab71a2c8e4ecb19a5a5abcfb3a4f175946c001c8af288b1aa766d67b0 0.0s
=> CACHED [build 1/6] FROM docker.io/library/node:12@sha256:cc4adb82efc04b74b9f96326e682ad04be2df84d23e40609802eb6d6c207abde 0.0s
=> [internal] load build context 0.1s
=> => transferring context: 69.58kB 0.0s
=> CACHED [stage-1 2/3] RUN rm /etc/nginx/nginx.conf /etc/nginx/conf.d/default.conf 0.0s
=> CACHED [build 2/10] WORKDIR /app 0.0s
=> CACHED [build 3/10] COPY package.json ./ 0.0s
=> CACHED [build 4/10] RUN yarn set version berry 0.0s
=> [build 5/10] COPY .yarn ./.yarn 0.2s
=> [build 6/10] COPY yarn.lock .yarnrc.yml ./ 0.0s
=> [build 7/10] RUN yarn plugin import workspace-tools 1.5s
=> [build 8/10] RUN yarn workspaces focus -A --production 0.5s
=> [build 9/10] COPY . ./ 0.1s
=> [build 10/10] RUN yarn build 568.9s
=> => # src/main.ts → public/build/bundle.js... # -> Never completes
我一直在试图找出构建挂起的原因,但我无法找到错误的来源。使用 yarn build 在本地构建时它工作得很好。有没有人知道为什么它在捆绑过程中挂起?
我没弄清楚哪里出了问题,但我成功地构建了 docker 图像并 运行 它成功了。这是工作的 Dockerfile:
FROM node:16 AS build
WORKDIR /app
COPY package.json ./
RUN yarn set version berry
COPY .yarn ./.yarn #
COPY yarn.lock .yarnrc.yml ./
RUN yarn install
# These two lines are from the original example. It did not work to use this,
# but I leave it here to highlight the difference
## RUN yarn plugin import workspace-tools
## RUN yarn workspaces focus -A --production
COPY . ./
RUN yarn build
FROM nginx:1.19-alpine
COPY --from=build /app/public /usr/share/nginx/html