【问题标题】:Deployment to App Engine using Cloudbuild failing使用 Cloudbuild 部署到 App Engine 失败
【发布时间】:2021-09-24 15:22:21
【问题描述】:

我已经构建了一个 Node + Vue JS 项目,该项目由前端和后端代码的不同目录构成。 /api 是带有自己的 package.json 的后端代码,ui 是带有自己的 package.json 的前端代码。项目结构如下:

/app
  /api
    package.json
  /ui
    package.json
  /config
    cloudbuild.yaml

我正在尝试使用 Cloudbuild 将项目部署到 App Engine。 cloudbuild.yaml 文件的结构如下:

steps:
- name: gcr.io/cloud-builders/gcloud:latest
  entrypoint: "ls"
  args: ["-lah","/workspace"]
- name: node
  entrypoint: yarn
  args: ["install"]
  dir: "api"
- name: node
  entrypoint: yarn
  args: ['global', 'add', '@vue/cli']
  dir: "ui"
- name: node
  entrypoint: yarn
  args: ['run', 'build']
  dir: "ui"
- name: "gcr.io/cloud-builders/gcloud"
  args: ["app", "deploy", "./app.yaml"]
timeout: "1600s"

步骤 0-2 成功完成,但是在构建用于生产的 Vue 应用程序时构建失败,特别是 yarn run build 的命令。此命令在 /ui 目录的 package.json 中列为 vue-cli-service build

错误是/bin/sh: 1: vue-cli-service: not found

Cloudbuild 好像找不到 vue-cli 好像它没有安装或者它不知道要构建什么。

我的问题是如何使用 Cloudbuild 将具有单独目录的项目部署到 App Engine?

【问题讨论】:

  • 您能否尝试在步骤 2 中不全局安装 vue/li 依赖项,而仅在项目本地安装?如果有效,我会回答问题并解释原因。
  • 哇!那行得通!但是怎么样?

标签: node.js vue.js google-app-engine google-cloud-platform google-cloud-build


【解决方案1】:

Cloud Build 的核心原则之一是在每一步都从下一个执行上下文开始。在每个步骤之间只保留/workspace 目录。

在第三步中,您将全局安装 vue cli,因此,不是在当前目录(工作区的子目录)中,而是容器运行时目录(/etc 或其他地方;无论如何,不​​在工作区下.

如果您删除 global 参数,您将在本地应用程序目录(/workspace 下)安装该库,因此安装将持续执行以下步骤。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2021-03-01
    • 2014-03-14
    • 2021-09-25
    • 1970-01-01
    • 1970-01-01
    • 2020-06-05
    • 2020-06-02
    相关资源
    最近更新 更多