我有一个在Google Cloud Storage上运行的reactjs静态应用程序。我正在尝试使用Cloud Build自动化构建和部署过程。
以下是cloudbuild.yaml文件:
steps:
# Install
- name: 'gcr.io/cloud-builders/npm'
entrypoint: 'npm'
args: ['install']
# Test
#- name: 'gcr.io/cloud-builders/npm'
#entrypoint: 'npm'
#args: ['test', 'test:ci']
# Build
- name: 'gcr.io/cloud-builders/npm'
entrypoint: 'npm'
args: ['build']
# Syncing to Static Hosting on GCS
- name: 'gcr.io/cloud-builders/gsutil'
args: ["-m", "rsync", "-r", "-c", "-d", "./build", "gs://mybucket.com"]
同步到GCS的最后一步失败了。我遇到以下错误:
Starting Step #0
Step #0: Already have image (with digest): gcr.io/cloud-builders/npm
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.711s
Step #0: found 0 vulnerabilities
Step #0:
Finished Step #0
Starting Step #1
Step #1: Already have image (with digest): gcr.io/cloud-builders/npm
Finished Step #1
Starting Step #2
Step #2: Already have image (with digest): gcr.io/cloud-builders/gsutil
Step #2: CommandException: arg (./build) does not name a directory, bucket, or bucket subdir.
Finished Step #2
ERROR
ERROR: build step 2 "gcr.io/cloud-builders/gsutil" failed: step exited with non-zero status: 1
我的项目结构:
RootProject
-> front-end-webapp
-> src/
-> cloudbuild.yaml
-> build/
-> public/
-> package.json
-> backend-service1
-> backend-service2
我编写的触发器指向front-end-webapp子文件夹内的cloudbuild.yaml文件。当我手动执行
npm run build or yarn build
然后我将要放入Google Cloud Storage的front-end-webapp下的build文件夹中的产品准备就绪。仅build文件夹内的文件,而不是build文件夹本身包含的文件。
我尝试了很多,但没有得到。如果我做 。而不是像args这样的args中的“ ./build”:["-m"、"rsync"、"-r"、"-c"、"-d"、"./build"、"gs://mybucket .com“],则云构建成功执行,但它还会复制根项目中存在的整个文件和子文件夹。
构建作业由提交到中的文件触发,front-end-webapp
然后您运行cloudbuild.yaml
文件到中front-end-webapp
。
但是,回购的根源是/
and not front-end-webapp
。因此,dir: 'front-end-webapp'
在每个步骤上添加属性。这迫使步骤开始进入正确的文件夹!
编辑
当我陷入目录管理的困境中时,我将介绍此步骤以查看工作空间中存在的内容。
- name: gcr.io/cloud-builders/gcloud:latest
entrypoint: "ls"
args: ["-lah","/workspace"]
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句