在 docker build 中不会发生云构建上的构建类型错误
Getting a build type error on cloud build that doesn't happen in docker build
我的问题
我仅在执行 gcloud 构建提交时收到错误。我的构建在本地工作,并且在本地创建 docker 图像时。我假设这是一个文件没有正确复制到 tarball 中的问题;然而,在我的调试中,我发现它似乎正在被复制。
我的错误:
Type error: Parameter 'service' implicitly has an 'any' type
这来自一些看起来像这样的代码:
const {
firestore,
collections: {
rentals: { services },
},
} = useFirebaseCtx();
const newServiceEvents = services.map((service, index) => {
...
})
在哪里 useFirebaseCtx 被广泛键入(其中没有明确的任何内容)
服务有明确的类型 Organizations.Rentals.Services.Flat[]
调试我试过了
当我 运行 yarn run eslint . --ext .js,.jsx,.ts,.tsx
我没有得到任何错误
当我 运行 docker build -t my-docker-image-name .
我没有收到任何错误(图像构建完成)
我已经确认(通过 运行ning gcloud meta list-files-for-upload
)我的类型文件夹确实被上传到 tarball
gcloud meta list-files-for-upload
的缩写输出:
...
types/organizations/index.d.ts <- this is the file the type is defined in
...
补充文件
.docker忽略
Dockerfile
.dockerignore
.gitignore
node_modules
npm-debug.log
README.md
.next
functions
fire*
jest*
__tests__
.gcloudignore
.gcloudignore
.git
.gitignore
node_modules
npm-debug.log
README.md
.next
functions
fire*
jest*
__tests__
!.env*
.env.development*
Docker 文件
# Install dependencies only when needed
FROM node:14-alpine AS deps
# Check https://github.com/nodejs/docker-node/tree/b4117f9333da4138b03a546ec926ef50a31506c3#nodealpine to understand why libc6-compat might be needed.
RUN apk add --no-cache libc6-compat
WORKDIR /app
COPY package.json yarn.lock ./
# COPY ./private/sitemap/generate-sitemap.mjs ./private/sitemap/generate-sitemap.mjs
RUN yarn install --frozen-lockfile
# Rebuild the source code only when needed
FROM node:14-alpine AS builder
WORKDIR /app
COPY . .
COPY --from=deps /app/node_modules ./node_modules
ENV NODE_ENV production
# Failing here
RUN yarn build
# Production image, copy all the files and run next
FROM node:14-alpine AS runner
WORKDIR /app
RUN addgroup -g 1001 -S nodejs
RUN adduser -S nextjs -u 1001
# You only need to copy next.config.js if you are NOT using the default configuration
COPY --from=builder /app/next.config.js ./
COPY --from=builder /app/public ./public
COPY --from=builder /app/.env* ./
COPY --from=builder --chown=nextjs:nodejs /app/.next ./.next
COPY --from=builder /app/node_modules ./node_modules
COPY --from=builder /app/package.json ./package.json
COPY --from=builder /app/next.config.js ./next.config.js
USER nextjs
EXPOSE 3000
# Next.js collects completely anonymous telemetry data about general usage.
# Learn more here: https://nextjs.org/telemetry
# Uncomment the following line in case you want to disable telemetry.
# ENV NEXT_TELEMETRY_DISABLED 1
CMD ["yarn", "start"]
TL;DR
不要在源代码中命名任何文件夹 firebase*
。
怎么了
问题是我有一个名为 firebase
的内部文件夹,它没有包含在 tarball 中。我不得不重命名该文件夹,以便将其包含在内。
我是如何发现错误的以及我的解决方案
- 我进入云控制台并下载了 tarball(他们在 CLI 中给了你一行)
- CD 进入文件夹并 运行
yarn install
- 我在树上追踪错误,发现我的 src 文件夹中缺少整个文件夹
- 我 运行
gcloud meta list-files-for-upload
在我的原始文件夹中,发现文件 (firebase/*.(ts|tsx)) 没有被包括在内。因此我得出结论,将文件夹命名为“firebase”是个坏主意。
- 重命名文件夹。
另一种可能的解决方案
将文件作为不可忽略文件添加到您的 .gcloudignore
我的问题
我仅在执行 gcloud 构建提交时收到错误。我的构建在本地工作,并且在本地创建 docker 图像时。我假设这是一个文件没有正确复制到 tarball 中的问题;然而,在我的调试中,我发现它似乎正在被复制。
我的错误:
Type error: Parameter 'service' implicitly has an 'any' type
这来自一些看起来像这样的代码:
const {
firestore,
collections: {
rentals: { services },
},
} = useFirebaseCtx();
const newServiceEvents = services.map((service, index) => {
...
})
在哪里 useFirebaseCtx 被广泛键入(其中没有明确的任何内容)
服务有明确的类型 Organizations.Rentals.Services.Flat[]
调试我试过了
当我 运行
yarn run eslint . --ext .js,.jsx,.ts,.tsx
我没有得到任何错误当我 运行
docker build -t my-docker-image-name .
我没有收到任何错误(图像构建完成)我已经确认(通过 运行ning
gcloud meta list-files-for-upload
)我的类型文件夹确实被上传到 tarball
gcloud meta list-files-for-upload
的缩写输出:
...
types/organizations/index.d.ts <- this is the file the type is defined in
...
补充文件
.docker忽略
Dockerfile
.dockerignore
.gitignore
node_modules
npm-debug.log
README.md
.next
functions
fire*
jest*
__tests__
.gcloudignore
.gcloudignore
.git
.gitignore
node_modules
npm-debug.log
README.md
.next
functions
fire*
jest*
__tests__
!.env*
.env.development*
Docker 文件
# Install dependencies only when needed
FROM node:14-alpine AS deps
# Check https://github.com/nodejs/docker-node/tree/b4117f9333da4138b03a546ec926ef50a31506c3#nodealpine to understand why libc6-compat might be needed.
RUN apk add --no-cache libc6-compat
WORKDIR /app
COPY package.json yarn.lock ./
# COPY ./private/sitemap/generate-sitemap.mjs ./private/sitemap/generate-sitemap.mjs
RUN yarn install --frozen-lockfile
# Rebuild the source code only when needed
FROM node:14-alpine AS builder
WORKDIR /app
COPY . .
COPY --from=deps /app/node_modules ./node_modules
ENV NODE_ENV production
# Failing here
RUN yarn build
# Production image, copy all the files and run next
FROM node:14-alpine AS runner
WORKDIR /app
RUN addgroup -g 1001 -S nodejs
RUN adduser -S nextjs -u 1001
# You only need to copy next.config.js if you are NOT using the default configuration
COPY --from=builder /app/next.config.js ./
COPY --from=builder /app/public ./public
COPY --from=builder /app/.env* ./
COPY --from=builder --chown=nextjs:nodejs /app/.next ./.next
COPY --from=builder /app/node_modules ./node_modules
COPY --from=builder /app/package.json ./package.json
COPY --from=builder /app/next.config.js ./next.config.js
USER nextjs
EXPOSE 3000
# Next.js collects completely anonymous telemetry data about general usage.
# Learn more here: https://nextjs.org/telemetry
# Uncomment the following line in case you want to disable telemetry.
# ENV NEXT_TELEMETRY_DISABLED 1
CMD ["yarn", "start"]
TL;DR
不要在源代码中命名任何文件夹 firebase*
。
怎么了
问题是我有一个名为 firebase
的内部文件夹,它没有包含在 tarball 中。我不得不重命名该文件夹,以便将其包含在内。
我是如何发现错误的以及我的解决方案
- 我进入云控制台并下载了 tarball(他们在 CLI 中给了你一行)
- CD 进入文件夹并 运行
yarn install
- 我在树上追踪错误,发现我的 src 文件夹中缺少整个文件夹
- 我 运行
gcloud meta list-files-for-upload
在我的原始文件夹中,发现文件 (firebase/*.(ts|tsx)) 没有被包括在内。因此我得出结论,将文件夹命名为“firebase”是个坏主意。 - 重命名文件夹。
另一种可能的解决方案
将文件作为不可忽略文件添加到您的 .gcloudignore