如何在 Turborepo 中对 nuxt 项目进行 dockerize?

问题描述 投票:0回答:1

我稍微修改了文档中的示例 Dockerfile:

FROM node:lts-alpine AS base
 
FROM base AS builder
RUN apk add --no-cache libc6-compat
RUN apk update
# Set working directory
WORKDIR /app
RUN npm i -g turbo
COPY . .
RUN turbo prune @rusinas/blogue-app --docker
 
# Add lockfile and package.json's of isolated subworkspace
FROM base AS installer
RUN apk add --no-cache libc6-compat
RUN apk update
WORKDIR /app
 
# First install the dependencies (as they change less often)
COPY .gitignore .gitignore
COPY --from=builder /app/out/json/ .
COPY --from=builder /app/out/package-lock.json ./package-lock.json
RUN npm install
 
# Build the project
COPY --from=builder /app/out/full/ .
RUN npx turbo run build --filter=web...
 
FROM base AS runner
WORKDIR /app
 
# Don't run production as root
RUN addgroup --system --gid 1001 nodejs
RUN adduser --system --uid 1001 nuxtjs
USER nuxtjs
 
COPY --from=installer /app/apps/web/next.config.js .
COPY --from=installer /app/apps/web/package.json .
 
# Automatically leverage output traces to reduce image size
# https://nextjs.org/docs/advanced-features/output-file-tracing
COPY --from=installer --chown=nuxtjs:nodejs /app/apps/web/.next/standalone ./
COPY --from=installer --chown=nuxtjs:nodejs /app/apps/web/.next/static ./apps/web/.next/static
COPY --from=installer --chown=nuxtjs:nodejs /app/apps/web/public ./apps/web/public
 
CMD node apps/web/server.js

我的 monorepo 的结构非常简单:

apps
  app
    *nuxt-app*
    Dockerfile
packages
  ui

turbo.json

当我尝试构建容器时,我收到此错误:

 > [client builder 6/6] RUN turbo prune @rusinas/blogue-app --docker:
0.476 Turbo error: could not resolve workspaces: We did not find a package manager specified in your root package.json. Please set the "packageManager" property in your root package.json (https://nodejs.org/api/packages.html#packagemanager) or run `npx @turbo/codemod add-package-manager` in the root of your monorepo.

在 docker 之外,

turbo prune @rusinas/blogue-app --docker
工作正常,所以看起来我需要以某种方式将所有 monorepo 放入 Dockerfile 中,因为我真的不明白它将如何找到我的 ui 包。但这听起来很愚蠢。我做错了什么?

docker nuxt.js turborepo
1个回答
0
投票

很可能您的 Docker 构建命令没有正确的上下文。

因此,当您运行

apps/app/Dockerfile
时,Docker 仅使用在
apps/app
中找到的文件。因此,当 Turbo 尝试修剪时,它会错过所需的文件。

© www.soinside.com 2019 - 2024. All rights reserved.