在OpenShift中动态设置OPENSHIFT_BUILD_REFERENCE和io.openshift.build.commit.ref?

时间:2018-08-04 06:40:00

标签: openshift

我为服务使用了一个相对简单的BuildConfig。

name = instance.customer.name
email = instance.customer.user_customer.email
contact = instance.customer.phone_no

if not instance.b_customer_id and instance.customer:
    try:
        customer = client.customer.create(     {
                                            "name" : name,
                                            "email" : email,
                                            "contact" : contact,
                                            "notes": {}
                                            }
                                    )
        instance.b_customer_id = customer["id"]
    except Exception as e:
        print(e)

pre_save.connect(billing_profile_recieved,sender=BillingProfile)

我可以像这样用它从git中的标签构建图像。

apiVersion: build.openshift.io/v1
kind: BuildConfig
metadata:
  labels:
    app: identity-server
  name: identity-server
  namespace: dev
spec:
  failedBuildsHistoryLimit: 5
  nodeSelector: {}
  output:
    to:
      kind: ImageStreamTag
      name: 'identity-server:latest'
  postCommit: {}
  resources: {}
  runPolicy: Serial
  source:
    git:
      ref: master
      uri: 'ssh://git@bitbucket.example.com:7999/my-project/my-repo.git'
    sourceSecret:
      name: bitbucket
    type: Git
  strategy:
    dockerStrategy:
      dockerfilePath: Dockerfile.openshift
      from:
        kind: ImageStreamTag
        name: 'dotnet:2.1-sdk'
    type: Docker
  successfulBuildsHistoryLimit: 5
  triggers:
    - type: ConfigChange
    - imageChange:
      type: ImageChange

这很好用,并且图像是根据标记的提交构建的。

但是,在构建的最后两个步骤中,我看到了

$ oc start-build identity-server -n dev --commit 0.0.1
build "identity-server-22" started
根据BuildConfig中的Step 14/15 : ENV "OPENSHIFT_BUILD_NAME" "identity-server-25" "OPENSHIFT_BUILD_NAMESPACE" "dev" "OPENSHIFT_BUILD_SOURCE" "ssh://git@bitbucket.example.com:7999/my-project/my-repo.git" "OPENSHIFT_BUILD_REFERENCE" "master" "OPENSHIFT_BUILD_COMMIT" "6fa1c07b2e4f70bfff5ed1614907a1d00597fb51" ---> Running in 6d1e8a67976b ---> b7a869b8c133 Removing intermediate container 6d1e8a67976b Step 15/15 : LABEL "io.openshift.build.name" "identity-server-25" "io.openshift.build.namespace" "dev" "io.openshift.build.commit.author" "Everett Toews \u003cEverett.Toews@example.com\u003e" "io.openshift.build.commit.date" "Sat Aug 4 16:46:48 2018 +1200" "io.openshift.build.commit.id" "6fa1c07b2e4f70bfff5ed1614907a1d00597fb51" "io.openshift.build.commit.ref" "master" "io.openshift.build.commit.message" "Try to build master branch" "io.openshift.build.source-location" "ssh://git@bitbucket.example.com:7999/my-project/my-repo.git" ---> Running in 3e8d8200f2cf ---> 1a591207a29f Removing intermediate container 3e8d8200f2cf

OPENSHIFT_BUILD_REFERENCEio.openshift.build.commit.ref被设置为master。我希望将这些设置为spec.source.git.ref中的0.0.1标志所覆盖的--commit 0.0.1

是否可以在OpenShift中动态设置OPENSHIFT_BUILD_REFERENCE和io.openshift.build.commit.ref?

还是我需要对BuildConfig进行模板化并用参数替换ōc start-build以获得所需的行为?

0 个答案:

没有答案