gpt4 book ai didi

node.js - 错误 : Cannot find module '/app/__sapper__/build' on Cloud Build

转载 作者:行者123 更新时间:2023-12-02 18:50:48 25 4
gpt4 key购买 nike

我正在尝试为部署到 Cloud Run 的工兵项目设置自动化 Cloud Build。但是我在部署时遇到错误。
这是我第一次尝试 CI 工作流程,所以我确信我做错了很多事情。

cloudbuild.yaml

steps:
- name: "gcr.io/cloud-builders/gcloud"
args:
- kms
- decrypt
- --ciphertext-file=.env.enc
- --plaintext-file=.env
- --location=global
- --keyring=jointcreative
- --key=cloudbuild-env

- name: "gcr.io/cloud-builders/docker"
args: ["build", "-t", "gcr.io/$PROJECT_ID/$PROJECT_ID", "."]

- name: "gcr.io/cloud-builders/docker"
args: ["push", "gcr.io/$PROJECT_ID/$PROJECT_ID"]

- name: "gcr.io/cloud-builders/npm"
args: ["ci", "--production"]

- name: 'gcr.io/cloud-builders/gcloud'
args:
- 'run'
- 'deploy'
- 'jointcreative'
- '--image'
- 'gcr.io/$PROJECT_ID/$PROJECT_ID'
- '--region'
- 'us-central1'
- '--platform'
- 'managed'

- name: "gcr.io/$PROJECT_ID/firebase"
args: ['deploy']


Dockerfile
FROM mhart/alpine-node:12


WORKDIR /app
COPY package.json package-lock.json ./
RUN npm ci --production

FROM mhart/alpine-node:slim-12

WORKDIR /app
COPY --from=0 /app .
COPY . .

ENV PORT 8080
ENV HOST 0.0.0.0

EXPOSE 8080
CMD ["node", "__sapper__/build"]

错误日志
enter image description here

最佳答案

您收到此错误的原因是您没有使用 npm run build 构建 Sapper 应用程序。 .

几分钟前,我在 Github 上发布了一个将 Sapper 部署到 Cloud Run 的存储库,地址为 https://github.com/mikenikles/sapper-on-cloud-run。 .
Dockerfile我使用的是基于 3 个阶段来最小化最终图像大小。

# This stage builds the sapper application.
FROM mhart/alpine-node:12 AS build-app
WORKDIR /app
COPY . .
RUN npm install --no-audit --unsafe-perm
RUN npm run build

# This stage installs the runtime dependencies.
FROM mhart/alpine-node:12 AS build-runtime
WORKDIR /app
COPY package.json package-lock.json ./
RUN npm ci --production --unsafe-perm

# This stage only needs the compiled Sapper application
# and the runtime dependencies.
FROM mhart/alpine-node:slim-12
WORKDIR /app
COPY --from=build-app /app/__sapper__ ./__sapper__
COPY --from=build-app /app/static ./static
COPY --from=build-runtime /app/node_modules ./node_modules

EXPOSE 3000
CMD ["node", "__sapper__/build"]

我还推荐以下 .dockerignore文件以仅复制 Sapper 运行所需的内容:
/*
!/package.json
!/package-lock.json
!/rollup.config.js
!/src
!/static

在您的 cloudbuild.yaml ,您可能需要考虑将以下内容添加到 Cloud Run 部署脚本 如果您打算公开服务 :
  - 'managed'
- '--allow-unauthenticated'

关于node.js - 错误 : Cannot find module '/app/__sapper__/build' on Cloud Build,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60804830/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com