2.3. ステップリソースの定義
ビルドストラテジーの各ステップにおける CPU、メモリー、およびディスクの制限を定義します。ストラテジーに複数のステップがある場合、それぞれのステップに異なるリソース量を割り当てることができます。
管理者として、同じストラテジーの異なるバージョン (たとえば、buildah-small と buildah-large) を提供することで、ユーザーが自身のビルド要件に合ったリソースプロファイルを選択できるようにすることができます。
2.3.1. さまざまなリソースを使用したストラテジー リンクのコピーリンクがクリップボードにコピーされました!
異なるビルド要件に対して異なるリソース制限を適用するために、同じストラテジーの複数のバリエーションを定義します。
以下の例では、リソースに対して小および中程度の制限を定義した同じ buildah ストラテジーを使用しています。これらの例により、ストラテジー管理者はステップリソースの定義をより詳細に制御できます。
次の例に示すように、buildah ストラテジーの spec.steps[].resources フィールドに小さなリソース制限を設定できます。
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: []
# ...
次の例に示すように、buildah ストラテジーの spec.steps[].resources フィールドに中程度のリソース制限を設定できます。
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: []
# ...
ストラテジーのリソース定義を設定した後、次の例に示すように、ビルド カスタムリソース (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
# ...