您可以通过设置以下字段的值来配置Build
自定义资源 (CR) 中构建的源详细信息
-
source.git.url
:定义在 Git 仓库中可用的镜像的源位置。
-
source.git.cloneSecret
:引用命名空间中包含私有 Git 仓库的 SSH 私钥的密钥。
-
source.git.revision
:定义要从源 Git 仓库中选择的特定版本。例如,提交、标签或分支名称。此字段默认为 Git 仓库的默认分支。
-
source.contextDir
:指定源代码不在根文件夹中的仓库的上下文路径。
构建控制器不会自动验证您指定用于拉取镜像的 Git 仓库是否存在。如果需要验证,请将build.shipwright.io/verify.repository
注释的值设置为true
,如下例所示
apiVersion: shipwright.io/v1beta1
kind: Build
metadata:
name: buildah-golang-build
annotations:
build.shipwright.io/verify.repository: "true"
spec:
source:
git:
url: https://github.com/shipwright-io/sample-go
contextDir: docker-build
构建控制器在以下情况下会验证 Git 仓库的存在:
示例:使用凭据配置构建
您可以通过指定凭据来配置具有源的构建,如下例所示
apiVersion: shipwright.io/v1beta1
kind: Build
metadata:
name: buildah-build
spec:
source:
git:
url: https://github.com/sclorg/nodejs-ex
cloneSecret: source-repository-credentials
示例:使用上下文路径配置构建
您可以配置一个具有源的构建,该源在 Git 仓库中指定上下文路径,如下例所示
apiVersion: shipwright.io/v1beta1
kind: Build
metadata:
name: buildah-custom-context-dockerfile
spec:
source:
git:
url: https://github.com/userjohn/npm-simple
contextDir: docker-build
示例:使用标签配置构建
您可以配置一个具有源的构建,该源为 Git 仓库指定标签v.0.1.0
,如下例所示
apiVersion: shipwright.io/v1beta1
kind: Build
metadata:
name: buildah-golang-build
spec:
source:
git:
url: https://github.com/shipwright-io/sample-go
revision: v0.1.0
示例:使用环境变量配置构建
您还可以配置指定环境变量的构建,如下例所示
apiVersion: shipwright.io/v1beta1
kind: Build
metadata:
name: buildah-golang-build
spec:
source:
git:
url: https://github.com/shipwright-io/sample-go
contextDir: docker-build
env:
- name: <example_var_1>
value: "<example_value_1>"
- name: <example_var_2>
value: "<example_value_2>"