搜索

1.2. 源定义

download PDF

您可以通过设置以下字段的值,在 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>"
Red Hat logoGithubRedditYoutubeTwitter

学习

尝试、购买和销售

社区

关于红帽文档

通过我们的产品和服务,以及可以信赖的内容,帮助红帽用户创新并实现他们的目标。

让开源更具包容性

红帽致力于替换我们的代码、文档和 Web 属性中存在问题的语言。欲了解更多详情,请参阅红帽博客.

關於紅帽

我们提供强化的解决方案,使企业能够更轻松地跨平台和环境(从核心数据中心到网络边缘)工作。

© 2024 Red Hat, Inc.