最新消息: 电脑我帮您提供丰富的电脑知识,编程学习,软件下载,win7系统下载。

您能否验证我的cloudbuild.yaml文件?

IT培训 admin 13浏览 0评论

您能否验证我的cloudbuild.yaml文件?

我是第一次使用GCP云构建为我的nodejs应用程序设置CI CD管道。以下是我已完成的步骤:

  1. 编写cloudbuild.yaml文件。完成
  2. [镜像了我的GCP云源存储库中的bitbucket存储库。完成
  3. 在我的GCP中配置了Webhook触发器。完成
  4. 当我推送代码时,它会被触发。完成

Cloudbuild.yaml

steps:
- name: "node:8.13"
  args: ["npm", "install"]
- name: "node:8.13"
  args: ["npm", "test"]
- name: "node:8.13"
  args: ["npm", "run", "build"]
- name: "gcr.io/cloud-builders/gcloud"
  args: ['functions', 'deploy', '[job_scheduling]', '--source=.', '--runtime', '[nodejs8.17]', '--trigger-http', '--allow-unauthenticated', '--entry-point=App']

package.json:

{
  "name": "groups",
  "version": "1.0.0",
  "description": "",
  "main": "src/index.js",
  "scripts": {
    "test": "mocha test/GET.js test/POST.js test/PUT.js test/DELETE.js",
    "coverage":"nyc --reporter=text --reporter=lcov mocha test/GET.js test/POST.js test/PUT.js test/DELETE.js"
  },
  "author": "",
  "license": "ISC",
  "dependencies": {
    "cors": "^2.8.5",
    "express": "^4.17.1",
    "firebase-admin": "^8.9.1",
    "is-my-json-valid": "^2.20.0"
  },
  "devDependencies": {
    "chai": "^4.2.0",
    "mocha": "^7.0.1",
    "nyc": "^15.0.0",
    "supertest": "^4.0.2"
  }
}

当我将代码推送到我的Bitbucket存储库中时,将触发构建并获得以下日志:

starting build "43d640c7-159e-45d2-9d69-af1c03892f8e"

FETCHSOURCE
Initialized empty Git repository in /workspace/.git/
From 
 * branch            5f57724022fffa3b874c8929f410f3249eedeab8 -> FETCH_HEAD
HEAD is now at 5f57724 cloudbuild.yaml edited online with Bitbucket
BUILD
Starting Step #0
Step #0: Pulling image: node:8.13
Step #0: 8.13: Pulling from library/node
Step #0: 54f7e8ac135a: Pulling fs layer
Step #0: d6341e30912f: Pulling fs layer
Step #0: 087a57faf949: Pulling fs layer
Step #0: 5d71636fb824: Pulling fs layer
Step #0: 0c1db9598990: Pulling fs layer
Step #0: 89669bc2deb2: Pulling fs layer
Step #0: 4c84cd37194c: Pulling fs layer
Step #0: a8061553ef43: Pulling fs layer
Step #0: 5d71636fb824: Waiting
Step #0: 0c1db9598990: Waiting
Step #0: 89669bc2deb2: Waiting
Step #0: 4c84cd37194c: Waiting
Step #0: a8061553ef43: Waiting
Step #0: 087a57faf949: Verifying Checksum
Step #0: 087a57faf949: Download complete
Step #0: d6341e30912f: Verifying Checksum
Step #0: d6341e30912f: Download complete
Step #0: 54f7e8ac135a: Verifying Checksum
Step #0: 54f7e8ac135a: Download complete
Step #0: 89669bc2deb2: Verifying Checksum
Step #0: 89669bc2deb2: Download complete
Step #0: 5d71636fb824: Verifying Checksum
Step #0: 5d71636fb824: Download complete
Step #0: a8061553ef43: Verifying Checksum
Step #0: a8061553ef43: Download complete
Step #0: 4c84cd37194c: Verifying Checksum
Step #0: 4c84cd37194c: Download complete
Step #0: 0c1db9598990: Verifying Checksum
Step #0: 0c1db9598990: Download complete
Step #0: 54f7e8ac135a: Pull complete
Step #0: d6341e30912f: Pull complete
Step #0: 087a57faf949: Pull complete
Step #0: 5d71636fb824: Pull complete
Step #0: 0c1db9598990: Pull complete
Step #0: 89669bc2deb2: Pull complete
Step #0: 4c84cd37194c: Pull complete
Step #0: a8061553ef43: Pull complete
Step #0: Digest: sha256:3ecf259bf23f8a75555cf0b92ac5ad3c746e7e2262e937a9bed9ca1685f8e1c7
Step #0: Status: Downloaded newer image for node:8.13
Step #0: docker.io/library/node:8.13
Step #0: npm WARN saveError ENOENT: no such file or directory, open '/workspace/package.json'
Step #0: npm notice created a lockfile as package-lock.json. You should commit this file.
Step #0: npm WARN enoent ENOENT: no such file or directory, open '/workspace/package.json'
Step #0: npm WARN workspace No description
Step #0: npm WARN workspace No repository field.
Step #0: npm WARN workspace No README data
Step #0: npm WARN workspace No license field.
Step #0: 
Step #0: up to date in 0.447s
Step #0: found 0 vulnerabilities
Step #0: 
Finished Step #0
Starting Step #1
Step #1: Already have image: node:8.13
Step #1: npm ERR! path /workspace/package.json
Step #1: npm ERR! code ENOENT
Step #1: npm ERR! errno -2
Step #1: npm ERR! syscall open
Step #1: npm ERR! enoent ENOENT: no such file or directory, open '/workspace/package.json'
Step #1: npm ERR! enoent This is related to npm not being able to find a file.
Step #1: npm ERR! enoent 
Step #1: 
Step #1: npm ERR! A complete log of this run can be found in:
Step #1: npm ERR!     /builder/home/.npm/_logs/2020-04-15T18_49_03_616Z-debug.log
Finished Step #1
ERROR
ERROR: build step 1 "node:8.13" failed: step exited with non-zero status: 254

请帮助我解决此问题。

更新:当我运行您的代码时:

steps:
- name: "gcr.io/cloud-builders/gcloud"
  entrypoint: "ls"
  args: ["-la", "/workspace"]

下面是日志:

[![starting build "363526b2-37f7-4b5a-9ee6-599db1442933"

FETCHSOURCE
Initialized empty Git repository in /workspace/.git/
From 
 * branch            98a8af215a8e683f94558a6351af60512b6fa1d7 -> FETCH_HEAD
HEAD is now at 98a8af2 cloudbuild.yaml edited online with Bitbucket
BUILD
Already have image (with digest): gcr.io/cloud-builders/gcloud
total 20
drwxr-xr-x  5 root root 4096 Apr 16 14:17 .
drwxr-xr-x  1 root root 4096 Apr 16 14:17 ..
drwxr-xr-x  8 root root 4096 Apr 16 14:17 .git
drwxr-xr-x 15 root root 4096 Apr 16 14:17 API
drwxr-xr-x  4 root root 4096 Apr 16 14:17 UI
PUSH
DONE][1]][1]

我已附上我的项目结构的屏幕截图。

回答如下:

您应该已将触发器配置为使用/api/groups/cloudbuild.yaml文件,但git存储库的根是/

通过添加cloudbuild.yaml参数来设置正确的工作目录来更新dir步骤>>

- name: "node:8.13"
  args: ["npm", "install"]
  dir: 'API/groups'
...

完整文档here

您能否验证我的cloudbuild.yaml文件?

我是第一次使用GCP云构建为我的nodejs应用程序设置CI CD管道。以下是我已完成的步骤:

  1. 编写cloudbuild.yaml文件。完成
  2. [镜像了我的GCP云源存储库中的bitbucket存储库。完成
  3. 在我的GCP中配置了Webhook触发器。完成
  4. 当我推送代码时,它会被触发。完成

Cloudbuild.yaml

steps:
- name: "node:8.13"
  args: ["npm", "install"]
- name: "node:8.13"
  args: ["npm", "test"]
- name: "node:8.13"
  args: ["npm", "run", "build"]
- name: "gcr.io/cloud-builders/gcloud"
  args: ['functions', 'deploy', '[job_scheduling]', '--source=.', '--runtime', '[nodejs8.17]', '--trigger-http', '--allow-unauthenticated', '--entry-point=App']

package.json:

{
  "name": "groups",
  "version": "1.0.0",
  "description": "",
  "main": "src/index.js",
  "scripts": {
    "test": "mocha test/GET.js test/POST.js test/PUT.js test/DELETE.js",
    "coverage":"nyc --reporter=text --reporter=lcov mocha test/GET.js test/POST.js test/PUT.js test/DELETE.js"
  },
  "author": "",
  "license": "ISC",
  "dependencies": {
    "cors": "^2.8.5",
    "express": "^4.17.1",
    "firebase-admin": "^8.9.1",
    "is-my-json-valid": "^2.20.0"
  },
  "devDependencies": {
    "chai": "^4.2.0",
    "mocha": "^7.0.1",
    "nyc": "^15.0.0",
    "supertest": "^4.0.2"
  }
}

当我将代码推送到我的Bitbucket存储库中时,将触发构建并获得以下日志:

starting build "43d640c7-159e-45d2-9d69-af1c03892f8e"

FETCHSOURCE
Initialized empty Git repository in /workspace/.git/
From 
 * branch            5f57724022fffa3b874c8929f410f3249eedeab8 -> FETCH_HEAD
HEAD is now at 5f57724 cloudbuild.yaml edited online with Bitbucket
BUILD
Starting Step #0
Step #0: Pulling image: node:8.13
Step #0: 8.13: Pulling from library/node
Step #0: 54f7e8ac135a: Pulling fs layer
Step #0: d6341e30912f: Pulling fs layer
Step #0: 087a57faf949: Pulling fs layer
Step #0: 5d71636fb824: Pulling fs layer
Step #0: 0c1db9598990: Pulling fs layer
Step #0: 89669bc2deb2: Pulling fs layer
Step #0: 4c84cd37194c: Pulling fs layer
Step #0: a8061553ef43: Pulling fs layer
Step #0: 5d71636fb824: Waiting
Step #0: 0c1db9598990: Waiting
Step #0: 89669bc2deb2: Waiting
Step #0: 4c84cd37194c: Waiting
Step #0: a8061553ef43: Waiting
Step #0: 087a57faf949: Verifying Checksum
Step #0: 087a57faf949: Download complete
Step #0: d6341e30912f: Verifying Checksum
Step #0: d6341e30912f: Download complete
Step #0: 54f7e8ac135a: Verifying Checksum
Step #0: 54f7e8ac135a: Download complete
Step #0: 89669bc2deb2: Verifying Checksum
Step #0: 89669bc2deb2: Download complete
Step #0: 5d71636fb824: Verifying Checksum
Step #0: 5d71636fb824: Download complete
Step #0: a8061553ef43: Verifying Checksum
Step #0: a8061553ef43: Download complete
Step #0: 4c84cd37194c: Verifying Checksum
Step #0: 4c84cd37194c: Download complete
Step #0: 0c1db9598990: Verifying Checksum
Step #0: 0c1db9598990: Download complete
Step #0: 54f7e8ac135a: Pull complete
Step #0: d6341e30912f: Pull complete
Step #0: 087a57faf949: Pull complete
Step #0: 5d71636fb824: Pull complete
Step #0: 0c1db9598990: Pull complete
Step #0: 89669bc2deb2: Pull complete
Step #0: 4c84cd37194c: Pull complete
Step #0: a8061553ef43: Pull complete
Step #0: Digest: sha256:3ecf259bf23f8a75555cf0b92ac5ad3c746e7e2262e937a9bed9ca1685f8e1c7
Step #0: Status: Downloaded newer image for node:8.13
Step #0: docker.io/library/node:8.13
Step #0: npm WARN saveError ENOENT: no such file or directory, open '/workspace/package.json'
Step #0: npm notice created a lockfile as package-lock.json. You should commit this file.
Step #0: npm WARN enoent ENOENT: no such file or directory, open '/workspace/package.json'
Step #0: npm WARN workspace No description
Step #0: npm WARN workspace No repository field.
Step #0: npm WARN workspace No README data
Step #0: npm WARN workspace No license field.
Step #0: 
Step #0: up to date in 0.447s
Step #0: found 0 vulnerabilities
Step #0: 
Finished Step #0
Starting Step #1
Step #1: Already have image: node:8.13
Step #1: npm ERR! path /workspace/package.json
Step #1: npm ERR! code ENOENT
Step #1: npm ERR! errno -2
Step #1: npm ERR! syscall open
Step #1: npm ERR! enoent ENOENT: no such file or directory, open '/workspace/package.json'
Step #1: npm ERR! enoent This is related to npm not being able to find a file.
Step #1: npm ERR! enoent 
Step #1: 
Step #1: npm ERR! A complete log of this run can be found in:
Step #1: npm ERR!     /builder/home/.npm/_logs/2020-04-15T18_49_03_616Z-debug.log
Finished Step #1
ERROR
ERROR: build step 1 "node:8.13" failed: step exited with non-zero status: 254

请帮助我解决此问题。

更新:当我运行您的代码时:

steps:
- name: "gcr.io/cloud-builders/gcloud"
  entrypoint: "ls"
  args: ["-la", "/workspace"]

下面是日志:

[![starting build "363526b2-37f7-4b5a-9ee6-599db1442933"

FETCHSOURCE
Initialized empty Git repository in /workspace/.git/
From 
 * branch            98a8af215a8e683f94558a6351af60512b6fa1d7 -> FETCH_HEAD
HEAD is now at 98a8af2 cloudbuild.yaml edited online with Bitbucket
BUILD
Already have image (with digest): gcr.io/cloud-builders/gcloud
total 20
drwxr-xr-x  5 root root 4096 Apr 16 14:17 .
drwxr-xr-x  1 root root 4096 Apr 16 14:17 ..
drwxr-xr-x  8 root root 4096 Apr 16 14:17 .git
drwxr-xr-x 15 root root 4096 Apr 16 14:17 API
drwxr-xr-x  4 root root 4096 Apr 16 14:17 UI
PUSH
DONE][1]][1]

我已附上我的项目结构的屏幕截图。

回答如下:

您应该已将触发器配置为使用/api/groups/cloudbuild.yaml文件,但git存储库的根是/

通过添加cloudbuild.yaml参数来设置正确的工作目录来更新dir步骤>>

- name: "node:8.13"
  args: ["npm", "install"]
  dir: 'API/groups'
...

完整文档here

发布评论

评论列表 (0)

  1. 暂无评论