2.3. ステップリソースの定義
ビルドストラテジーのすべてのステップに対して CPU、メモリー、ディスク使用量に課せられる制限などのリソースの定義を含めることができます。ステップが複数あるストラテジーの場合、ステップによっては他のステップよりも多くのリソースが必要になる場合があります。ストラテジー管理者は、各ステップに最適なリソース値を定義できます。
たとえば、同じステップで異なる名前とステップリソースを含むストラテジーをクラスターにインストールできるため、ユーザーはより小さいまたはより大きいリソース要件でビルドを作成できます。
2.3.1. さまざまなリソースを使用したストラテジー リンクのコピーリンクがクリップボードにコピーされました!
リソースに異なる制限を指定して、同じストラテジーの複数のタイプを定義します。次の例では、リソースに対して小および中程度の制限が定義された同じ buildah ストラテジーを使用します。これらの例では、ストラテジー管理者がステップリソースの定義をより詳細に制御できるようになります。
2.3.1.1. 制限の少ないビルダーストラテジー リンクのコピーリンクがクリップボードにコピーされました!
次の例に示すように、buildah ストラテジーに制限の小さいリソースストラテジーを指定して spec.steps[].resources フィールドを定義します。
例: 制限が小さい buildah ストラテジー
apiVersion: shipwright.io/v1beta1
kind: ClusterBuildStrategy
metadata:
name: buildah-small
spec:
steps:
- name: build-and-push
image: quay.io/containers/buildah:v1.31.0
workingDir: $(params.shp-source-root)
securityContext:
capabilities:
add:
- "SETFCAP"
command:
- /bin/bash
args:
- -c
- |
set -euo pipefail
# Parse parameters
# ...
# That's the separator between the shell script and its args
- --
- --context
- $(params.shp-source-context)
- --dockerfile
- $(build.dockerfile)
- --image
- $(params.shp-output-image)
- --build-args
- $(params.build-args[*])
- --registries-block
- $(params.registries-block[*])
- --registries-insecure
- $(params.registries-insecure[*])
- --registries-search
- $(params.registries-search[*])
resources:
limits:
cpu: 250m
memory: 65Mi
requests:
cpu: 250m
memory: 65Mi
parameters:
- name: build-args
description: "The values for the args in the Dockerfile. Values must be in the format KEY=VALUE."
type: array
defaults: []
# ...
2.3.1.2. 制限が中程度の Buildah ストラテジー リンクのコピーリンクがクリップボードにコピーされました!
次の例に示すように、buildah ストラテジーに制限が中程度のリソースストラテジーを指定して spec.steps[].resources フィールドを定義します。
例: 制限が中程度の buildah ストラテジー
apiVersion: shipwright.io/v1beta1
kind: ClusterBuildStrategy
metadata:
name: buildah-medium
spec:
steps:
- name: build-and-push
image: quay.io/containers/buildah:v1.31.0
workingDir: $(params.shp-source-root)
securityContext:
capabilities:
add:
- "SETFCAP"
command:
- /bin/bash
args:
- -c
- |
set -euo pipefail
# Parse parameters
# ...
# That's the separator between the shell script and its args
- --
- --context
- $(params.shp-source-context)
- --dockerfile
- $(build.dockerfile)
- --image
- $(params.shp-output-image)
- --build-args
- $(params.build-args[*])
- --registries-block
- $(params.registries-block[*])
- --registries-insecure
- $(params.registries-insecure[*])
- --registries-search
- $(params.registries-search[*])
resources:
limits:
cpu: 500m
memory: 1Gi
requests:
cpu: 500m
memory: 1Gi
parameters:
- name: build-args
description: "The values for the args in the Dockerfile. Values must be in the format KEY=VALUE."
type: array
defaults: []
# ...
ストラテジーのリソース定義を設定した後、次の例に示すように、Build CR でストラテジーを参照する必要があります。
apiVersion: shipwright.io/v1beta1
kind: Build
metadata:
name: buildah-medium
spec:
source:
git:
url: https://github.com/shipwright-io/sample-go
contextDir: docker-build
strategy:
name: buildah-medium
kind: ClusterBuildStrategy
# ...
2.3.2. Tekton パイプラインのリソース管理 リンクのコピーリンクがクリップボードにコピーされました!
ビルドコントローラーは Tekton パイプラインコントローラーと連携して、ストラテジー手順を実行する Pod をスケジュールできるようにします。実行時に、ビルドコントローラーは Tekton TaskRun リソースを作成し、TaskRun リソースは特定の namespace に新しい Pod を作成します。次に、この Pod はすべてのストラテジーステップを順番に実行してイメージを構築します。