IBM Cloud Docs
调试构建

调试构建

使用故障诊断提示来了解如何对构建的 IBM Cloud® Code Engine 构建和运行进行故障诊断。

无论您是在控制台还是 CLI 中运行构建,请使用 CLI 对构建问题进行故障诊断。

  1. 运行 ibmcloud ce buildrun get --name BUILDRUN_NAME 命令以显示构建运行的详细信息。
  2. 查看命令输出中的 Reason

当构建未按预期进行时,查看日志和系统事件可提供有助于您调试问题的信息。

要考虑的构建限制

每个项目可以具有的最大构建配置数为 100。 在需要除去或清除旧的构建运行之前,每个项目总共限制为 100 个构建运行。

有关包括内存和 CPU 在内的构建限制的更多信息,请参阅 Code Engine的限制和配额

通过 CLI,您可以使用 ibmcloud ce project get 命令来显示有关限制和当前使用情况的信息。 例如:

ibmcloud ce project create --name myproject

示例输出

Getting project 'myproject'...
OK

Name:                                      myproject
ID:                         abcdabcd-abcd-abcd-abcd-f1de4aab5d5d
Status:                                    active
Enabled:                                   true
Application Private Visibility Supported:  true
Selected:                                  true
Region:                                    us-south
Resource Group:             default
Service Binding Service ID: ServiceId-1234abcd-abcd-abcd-1111-1a2b3c4d5e6f
Age:                        52d
Created:                                   Tue, 28 Sep 2021 05:12:16 -0500
Updated:                                   Tue, 28 Sep 2021 05:12:19 -0500

Quotas:
Category                                  Used  Limit
App revisions                             2    120
Apps                                      1     40
Build runs                                1     100
Builds                                    2     100
Configmaps                                2     100
CPU                                       0     128
Ephemeral storage                         0     512G
Functions                                 0     20
Instances (active)                        0     250
Instances (total)                         0     2500
Job runs                                 13     100
Jobs                                      2     100
Memory                                    0     512G
Secrets                                   6     100
Subscriptions (cron)                      0     100
Subscriptions (IBM Cloud Object Storage)  0     100
Subscriptions (Kafka)                     0     100

获取我的构建的日志

日志可帮助您在运行构建时对问题进行故障诊断。 您可以使用 CLI 或控制台查看构建的日志。

从控制台获取我的构建的日志

您可以从控制台显示特定构建运行实例的日志。

  1. 转至 Code Engine 仪表板
  2. 选择项目 (或 创建一个)。
  3. 在项目页面中,单击 映像构建
  4. 映像构建 选项卡中,单击映像构建的名称以打开已定义构建的构建页面,或者 创建构建
  5. 从已定义构建的构建页面中,单击 构建运行 部分中构建运行实例的名称。 您可能需要单击 提交构建 以创建构建运行。
  6. 从构建运行实例页面,您可以查看构建日志信息。 展开特定构建步骤以获取详细的日志记录信息。

有关更多信息,请参阅 从控制台查看构建日志

使用 CLI 获取构建的日志

使用 ibmcloud ce buildrun logs 命令可显示有关构建运行的日志。 使用此命令可根据构建运行的名称显示构建运行的所有实例的日志。

要查看 mybuildrun 构建运行的所有实例的日志,请使用 --name 选项指定构建运行的名称; 例如,

ibmcloud ce buildrun logs --name mybuildrun

示例输出

Getting build run 'mybuildrun'...
Getting instances of build run 'mybuildrun'...
Getting logs for build run 'mybuildrun'...
OK

mybuildrun-bvzbg-pod-tppvg/step-source-default:
2021/09/21 09:39:08 Info: ssh (/usr/bin/ssh): OpenSSH_8.0p1, OpenSSL 1.1.1g FIPS  21 Apr 2020
2021/09/21 09:39:08 Info: git (/usr/bin/git): git version 2.27.0
2021/09/21 09:39:08 Info: git-lfs (/usr/bin/git-lfs): git-lfs/2.11.0 (GitHub; linux amd64; go 1.14.4)
2021/09/21 09:39:08 /usr/bin/git clone --quiet --no-tags --branch main --depth 1 --single-branch -- https://github.com/IBM/CodeEngine /workspace/source
2021/09/21 09:39:09 /usr/bin/git -C /workspace/source submodule update --init --recursive --depth 1
2021/09/21 09:39:10 /usr/bin/git -C /workspace/source rev-parse --abbrev-ref HEAD
2021/09/21 09:39:10 Successfully loaded https://github.com/IBM/CodeEngine (main) into /workspace/source
2021/09/21 09:39:10 /usr/bin/git -C /workspace/source rev-parse --verify HEAD

mybuildrun-bvzbg-pod-tppvg/step-build-and-push:
INFO[0000] Retrieving image manifest golang:alpine
INFO[0000] Retrieving image golang:alpine from registry index.docker.io
INFO[0001] Retrieving image manifest alpine
INFO[0001] Retrieving image alpine from registry index.docker.io
INFO[0003] Built cross stage deps: map[0:[/codeengine]]
INFO[0003] Retrieving image manifest golang:alpine
INFO[0003] Returning cached image manifest
INFO[0003] Executing 0 build triggers
INFO[0003] Unpacking rootfs as cmd COPY ./helloworld /helloworld requires it.
INFO[0009] COPY ./helloworld /helloworld
INFO[0009] Taking snapshot of files...
INFO[0009] COPY codeengine.go /
INFO[0009] Taking snapshot of files...
INFO[0009] RUN go build -o /codeengine /codeengine.go
INFO[0009] Taking snapshot of full filesystem...
INFO[0017] cmd: /bin/sh
INFO[0017] args: [-c go build -o /codeengine /codeengine.go]
INFO[0017] Running: [/bin/sh -c go build -o /codeengine /codeengine.go]
INFO[0018] Taking snapshot of full filesystem...
INFO[0018] Saving file codeengine for later use
INFO[0018] Deleting filesystem...
INFO[0019] Retrieving image manifest alpine
INFO[0019] Returning cached image manifest
INFO[0019] Executing 0 build triggers
INFO[0019] Unpacking rootfs as cmd COPY --from=0 /codeengine /codeengine requires it.
INFO[0019] COPY --from=0 /codeengine /codeengine
INFO[0019] Taking snapshot of files...
INFO[0019] CMD /codeengine
INFO[0019] Pushing image to us.icr.io/acme-namespace/codeengine-sample
INFO[0023] Pushed image to 1 destinations

获取我的构建的系统事件信息

系统事件信息可帮助您在运行构建时对问题进行故障诊断。 您可以使用 CLI 查看构建的系统事件信息。

  1. 使用 ibmcloud ce buildrun list 命令列出项目中的所有构建运行; 例如,

    ibmcloud ce buildrun list  
    
  2. 使用 ibmcloud ce buildrun get 命令来获取构建运行的详细信息,例如,

    ibmcloud ce buildrun get --name mybuildrun  
    

    示例输出

    Getting build run 'mybuildrun'...
    Run 'ibmcloud ce buildrun events -n mybuildrun' to get the system events of the build run.
    Run 'ibmcloud ce buildrun logs -f -n mybuildrun' to follow the logs of the build run.
    OK
    
    Name:          mybuilddrun
    [...]
    
    Created:       2021-06-01T11:43:24-04:00
    
    Summary:  Succeeded
    Status:   Succeeded
    Reason:   All Steps have completed executing
    
    Image:  us.icr.io/mynamespace/codeengine-codeengine-200
    

    如果需要有关构建运行的更多细颗粒度详细信息,请将 --o yaml 选项与 buildrun get 命令配合使用; 例如,ibmcloud ce buildrun get --name myapp --o yaml。 此选项有助于在 CLI 中显示有关构建运行的更多详细信息。

  3. 显示构建运行的系统事件。 使用 ibmcloud ce buildrun events 命令; 例如,

    ibmcloud ce buildrun events --name mybuildrun
    

    示例输出

    Getting build run 'mybuildrun'...
    Getting instances of build run 'mybuildrun'...
    Getting events for build run 'mybuildrun'...
    OK
    
    mybuildrun-bvzbg-pod-tppvg:
        Type    Reason     Age    Source                Messages
        Normal  Scheduled  4m43s  default-scheduler     Successfully assigned 62ckpsxlh7x/mybuildrun-bvzbg-pod-tppvg to 10.242.0.17
        Normal  Pulled     4m42s  kubelet, 10.242.0.17  Container image "icr.io/obs/codeengine/tekton-pipeline/entrypoint-bff0a22da108bc2f16c818c97641a296:v0.23.0-rc6@sha256:43dd56a6c7c10f80300a861615f6f8d91c026deba744f81553a4e536b301b322" already present on machine
        Normal  Created    4m42s  kubelet, 10.242.0.17  Created container place-tools
        Normal  Started    4m41s  kubelet, 10.242.0.17  Started container place-tools
        Normal  Pulled     4m40s  kubelet, 10.242.0.17  Container image "icr.io/obs/codeengine/git:v0.8.100" already present on machine
        Normal  Created    4m40s  kubelet, 10.242.0.17  Created container step-source-default
        Normal  Started    4m40s  kubelet, 10.242.0.17  Started container step-source-default
        Normal  Pulled     4m40s  kubelet, 10.242.0.17  Container image "icr.io/obs/codeengine/buildkit/builder:v0.9.0-rc.19" already present on machine
        Normal  Created    4m40s  kubelet, 10.242.0.17  Created container step-build-and-push
        Normal  Started    4m40s  kubelet, 10.242.0.17  Started container step-build-and-push
    

    事件仅在系统中存储一小时。