首页 > 解决方案 > 运行 Cloud Build 时 GCP 引用格式无效

问题描述

嗨 StackOverflow 偷看。

在尝试创建 Google Cloud Platform CI/CD 管道并卡在测试部分时寻求帮助。我有以下 Dockerfile 创建图像,当我推送到 github 存储库时会触发这些图像:

FROM node:alpine as builder

WORKDIR /usr/app

COPY package.json .
RUN npm install
COPY . .

RUN npm run build

# Run phase
FROM nginx
COPY --from=builder /usr/app/build /usr/share/nginx/html

然后我有以下cloudbuild.yaml文件构建容器,将其推送到我的仓库,并尝试运行我拥有的纱线测试:

# Start cloudbuild
# we just want to install and run tests for now
steps:
  # build the docker image
  - name: gcr.io/cloud-builders/docker
    id: buildinstaller
    args:
      [
        "build",
        "-t",
        "gcr.io/$PROJECT_ID/docker-react-ci:$BRANCH_NAME-$SHORT_SHA",
        "-f",
        "Dockerfile",
        "."
      ]
  # this step pushes the image to Container Registry
  - name: "gcr.io/cloud-builders/docker"
    id: Push
    args:
      - "push"
      - "gcr.io/$PROJECT_ID/docker-react-ci:$BRANCH_NAME-$SHORT_SHA"
  # fires the jest tests of the app so far
  - name: 'gcr.io/cloud-builders/docker'
    id: test
    args:
      - "run"
      - "-e"
      - "CI=true"
      - "gcr.io/$PROJECT_ID/docker-react-ci:$BRANCH_NAME-$SHORT_SHA"
      - "npm"
      - "run"
      - "test"
      - "--"
      - "--coverage"

Cloud Build Logs 的输出是:

starting build "f06de889-d88f-480d-bb51-9734cdf9447a"

FETCHSOURCE
Initialized empty Git repository in /workspace/.git/
From https://github.com/landon-sturgeon/docker-react
 * branch            3daf6a3fc0bf951b2b4de1a06d75fdeef9178e8b -> FETCH_HEAD
HEAD is now at 3daf6a3 hard code the right project name  again
BUILD
Starting Step #0 - "buildinstaller"
Step #0 - "buildinstaller": Already have image (with digest): gcr.io/cloud-builders/docker
Step #0 - "buildinstaller": Sending build context to Docker daemon  921.1kB

Step #0 - "buildinstaller": Step 1/8 : FROM node:alpine as builder
< INSTALLS CONTAINER CORRECTLY REMOVED LOGS FOR BREVITY >
Step #0 - "buildinstaller": Successfully tagged gcr.io/docker-react-306100/test:latest
Finished Step #0 - "buildinstaller"
Starting Step #1 - "Push"
Step #1 - "Push": Already have image (with digest): gcr.io/cloud-builders/docker
Step #1 - "Push": The push refers to repository [gcr.io/docker-react-306100/test]
Step #1 - "Push": 446f1465778a: Preparing
Step #1 - "Push": 2acf82036f38: Preparing
Step #1 - "Push": 9f65d1d4c869: Preparing
Step #1 - "Push": 0f804d36244d: Preparing
Step #1 - "Push": 9b23c8e1e6f9: Preparing
Step #1 - "Push": ffd3d6313c9b: Preparing
Step #1 - "Push": 9eb82f04c782: Preparing
Step #1 - "Push": ffd3d6313c9b: Waiting
Step #1 - "Push": 9eb82f04c782: Waiting
Step #1 - "Push": 9b23c8e1e6f9: Layer already exists
Step #1 - "Push": 9f65d1d4c869: Layer already exists
Step #1 - "Push": 2acf82036f38: Layer already exists
Step #1 - "Push": 0f804d36244d: Layer already exists
Step #1 - "Push": ffd3d6313c9b: Layer already exists
Step #1 - "Push": 9eb82f04c782: Layer already exists
Step #1 - "Push": 446f1465778a: Pushed
Step #1 - "Push": latest: digest: sha256:26172522a0d7199af3e8b044f0fa73d9efed0ed278b7af16062b00060369b96a size: 1780
Finished Step #1 - "Push"
Starting Step #2 - "test"
Step #2 - "test": Already have image (with digest): gcr.io/cloud-builders/docker
Step #2 - "test": /usr/bin/docker: invalid reference format: repository name must be lowercase.
Step #2 - "test": See '/usr/bin/docker run --help'.
Finished Step #2 - "test"
ERROR
ERROR: build step 2 "gcr.io/cloud-builders/docker" failed: step exited with non-zero status: 125

这是/usr/bin/docker: invalid reference format: repository name must be lowercase我坚持的错误。我已经尝试对 repo 名称进行硬编码,但我仍然遇到同样的错误。不知道从这里做什么,但希望 SO 神能进来拯救这一天!

谢谢!

标签: reactjsgoogle-cloud-platformcontinuous-integrationgoogle-cloud-build

解决方案


推荐阅读