1.2. 创建 Source-to-image 构建
您可以创建 Source-to-image 构建,并将创建的镜像推送到自定义 Quay 存储库。
先决条件
- 您已在 OpenShift Container Platform 集群中安装了 Red Hat OpenShift Operator 的构建。
-
已安装
ocCLI。 -
可选: 已安装
shpCLI。
流程
创建
Build资源,并使用其中一个 CLI 将它应用到 OpenShift Container Platform 集群:示例: 使用
ocCLI$ oc apply -f - <<EOF apiVersion: shipwright.io/v1beta1 kind: Build metadata: name: s2i-nodejs-build spec: source:1 type: Git git: url: https://github.com/redhat-openshift-builds/samples contextDir: s2i-build/nodejs strategy:2 name: source-to-image kind: ClusterBuildStrategy paramValues:3 - name: builder-image value: quay.io/centos7/nodejs-12-centos7:master output: image: quay.io/<repo>/s2i-nodejs-example4 pushSecret: registry-credential5 EOF示例: 使用
shpCLI$ shp build create s2i-nodejs-build \ --source-url="https://github.com/redhat-openshift-builds/samples" --source-context-dir="s2i-build/nodejs" \1 --strategy-name="source-to-image" \2 --builder-image="quay.io/centos7/nodejs-12-centos7" \3 --output-image="quay.io/<repo>/s2i-nodejs-example" \4 --output-credentials-secret="registry-credential"5 使用其中一个 CLI 检查是否创建了
Build资源:示例: 使用
ocCLI$ oc get builds.shipwright.io s2i-nodejs-build示例: 使用
shpCLI$ shp build list创建
BuildRun资源,并使用其中一个 CLI 将它应用到 OpenShift Container Platform 集群:示例: 使用
ocCLI$ oc apply -f - <<EOF apiVersion: shipwright.io/v1beta1 kind: BuildRun metadata: name: s2i-nodejs-buildrun spec: build: name: s2i-nodejs-build1 EOF- 1
spec.build.name字段表示要运行的相应构建,该构建应该在同一个命名空间中可用。
示例: 使用
shpCLI$ shp build run s2i-nodejs-build --follow1 - 1
- 可选:通过使用-
follow标志,您可以在输出结果中查看构建日志。
运行以下命令之一检查
BuildRun资源是否已创建:示例: 使用
ocCLI$ oc get buildrun s2i-nodejs-buildrun示例: 使用
shpCLI$ shp buildrun listBuildRun资源创建一个TaskRun资源,然后创建 Pod 来执行构建策略步骤。
验证
所有容器完成其任务后,验证以下内容:
检查 pod 是否显示
STATUS字段为Completed:$ oc get pods -w输出示例
NAME READY STATUS RESTARTS AGE s2i-nodejs-buildrun-phxxm-pod 2/2 Running 0 10s s2i-nodejs-buildrun-phxxm-pod 1/2 NotReady 0 14s s2i-nodejs-buildrun-phxxm-pod 0/2 Completed 0 2m检查对应的
TaskRun资源是否显示SUCCEEDED字段为True:$ oc get tr输出示例
NAME SUCCEEDED REASON STARTTIME COMPLETIONTIME s2i-nodejs-buildrun-phxxm True Succeeded 2m39s 13s检查对应的
BuildRun资源是否将SUCCEEDED字段显示为True:$ oc get br输出示例
NAME SUCCEEDED REASON STARTTIME COMPLETIONTIME s2i-nodejs-buildrun True Succeeded 2m41s 15s在验证过程中,如果构建失败,您可以检查
BuildRun资源中的status.failureDetails字段,以识别 pod 或容器中故障的确切点。注意pod 可能会切换到
NotReady状态,因为其中一个容器完成了其任务。这是预期的行为。
验证镜像是否已推送到
build.spec.output.image字段中指定的 registry。在登录到 registry 后,您可以尝试拉取镜像:$ podman pull quay.io/<repo>/<image>1 - 1
- 创建
Build资源时使用的存储库名称和镜像名称。例如,您可以使用s2i-nodejs-example作为镜像名称。
1.2.1. 在网络限制环境中创建 Source-to-image 构建 复制链接链接已复制到粘贴板!
您可以通过镜像 Source-to-image 构建策略,在网络限制环境中创建 Source-to-image 构建。
先决条件
- 集群可以连接并与可用于创建 Source-to-image 构建的 git 源进行交互。
-
您有在本地 registry 中创建
source-to-image构建所需的 builder-to-image。如果您在本地 registry 中没有 builder-image,则镜像源镜像。
流程
运行以下命令镜像
source-to-image构建策略所需的镜像:$ oc image mirror --insecure -a <registry_authentication> registry.redhat.io/source-to-image/source-to-image-rhel8@sha256:d041c1bbe503d152d0759598f79802e257816d674b342670ef61c6f9e6d401c5 <mirror_registry>/<repo>/source-to-image-source-to-image-rhel8- 执行"创建 source-to-image 构建"部分中所述的步骤。