1.2. 源定义
您可以通过设置以下字段的值,在 Build 自定义资源(CR)中配置构建的源详情:
-
source.git.url:定义 Git 存储库中提供的镜像的源位置。 -
source.git.cloneSecret:引用命名空间中包含私有 Git 存储库的 SSH 私钥的 secret。 -
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 存储库是否存在:
- 当您将端点 URL 与 HTTP 或 HTTPS 协议搭配使用时。
-
当您定义了 SSH 协议时,如
git@,而不是引用的 secret,如source.git.cloneSecret。
以下示例演示了如何使用不同源输入集配置构建。
示例:使用凭证配置构建
您可以通过指定凭证来使用源配置构建,如下例所示:
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>"