简体   繁体   English

OpenShift BuildConfig Docker 策略规范 output.to.name 使用环境变量进行标记

[英]OpenShift BuildConfig Docker strategy spec.output.to.name using environment variable for tagging

I have defined the following OpenShift BuildConfig:我已经定义了以下 OpenShift BuildConfig:

<snip>
    output:
      to:
        kind: DockerImage
        name: myregistry.com/myapp:${TAG}
    strategy:
      type: Docker
      dockerStrategy:
        from:
          kind: ImageStreamTag
          name: nodejs-12:latest
          namespace: myproject
        env:
          - name: TAG
            value: latest

I would like the TAG to be a version number which consists of version from the application package.json and the Jenkins #build number.我希望 TAG 是一个版本号,其中包含来自应用程序package.json和 Jenkins #build编号的版本。 So I plan to pass this env value in the OpenShift start-build command line using the -e option.所以我计划使用-e选项在 OpenShift start-build命令行中传递这个 env 值。 However, when applying the BuildConfig definition, it complains that name is not a valid Docker pull specification: invalid reference format .但是,在应用 BuildConfig 定义时,它抱怨name is not a valid Docker pull specification: invalid reference format How do I use variable to specify image tag string value?如何使用变量指定图像标签字符串值? Any advice and insight is appreciated.任何建议和见解都值得赞赏。

Sadly, this is not possible using a single BuildConfig .可悲的是,使用单个BuildConfig是不可能的。 The output part is evaluated during object creation, your build container environment can't set that tag later on. output部分在 object 创建期间进行评估,您的构建容器环境稍后无法设置该标签。

You may want to use a Template instead, creating BuildConfigs for earch tag you need to build.您可能想改用Template ,为您需要构建的每个标签创建BuildConfigs

Or, assuming OpenShift 4+, you could look into Tekton .或者,假设 OpenShift 4+,您可以查看Tekton The Pipeline object allows for generic build definitions - though still requires creating PipelineResources for each image tag, as well as git source ref. Pipeline object 允许通用构建定义 - 尽管仍然需要为每个图像标签创建PipelineResources ,以及 git 源参考。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM