Skip to content

Instantly share code, notes, and snippets.

@aweiteka
Last active August 11, 2017 15:20
Show Gist options
  • Save aweiteka/85c63eeb5d050bec0a63bdd7de261593 to your computer and use it in GitHub Desktop.
Save aweiteka/85c63eeb5d050bec0a63bdd7de261593 to your computer and use it in GitHub Desktop.
Method for building APBs without specific tooling

Automate APB builds

The apb tooling adds very little value outside of apb prepare, which simply base64 encodes apb.yml, specifically base64 --wrap=0 apb.yml as an image label, a.k.a. "Dockerfile label". This value may be passed into an OpenShift buildconfig object.

apiVersion: v1
kind: BuildConfig
metadata:
  annotations:
    openshift.io/generated-by: OpenShiftNewBuild
  creationTimestamp: 2017-08-01T17:57:08Z
  labels:
    build: hello-world-apb
  name: hello-world-apb
  namespace: myproject
  resourceVersion: "77735"
  selfLink: /oapi/v1/namespaces/myproject/buildconfigs/hello-world-apb
  uid: d619c306-76e2-11e7-9c8b-54ee75102ab0
spec:
  nodeSelector: null
  output:
    imageLabels:
    - name: com.redhat.apb.spec-test
      value: aWQ6IDU1YzUzYTVkLTY1YTYtNGMyNy04OGZjLWUwMjc0MTBiMTg4MgpuYW1lOiBoZWxsby13b3JsZC1hcGIKaW1hZ2U6IGFuc2libGVwbGF5Ym9va2J1bmRsZS9oZWxsby13b3JsZC1hcGIKZGVzY3JpcHRpb246IGhlbGxvLXdvcmxkLWFwYiBkZXNjcmlwdGlvbgpiaW5kYWJsZTogRmFsc2UKYXN5bmM6IG9wdGlvbmFsCm1ldGFkYXRhOgogIGRpc3BsYXlOYW1lOiBIZWxsbyBXb3JsZAogIGRlcGVuZGVuY2llczogWydkb2NrZXIuaW8vYW5zaWJsZXBsYXlib29rYnVuZGxlL2hlbGxvLXdvcmxkOmxhdGVzdCddCgpwYXJhbWV0ZXJzOiBbXQoKcmVxdWlyZWQ6IFtdCg==
    to:
      kind: ImageStreamTag
      name: hello-world-apb:latest
...

Workflow

Neither oc new-build ... nor oc start-build ... accept overriding imageLables. In this workflow we assume the initial buildconfig object has been created. The APB source has been updated.

  1. Patch the buildconfig object. Note: the apb.yml is checked into source. This may be best handled by a Jenkins job. Example patch command:

     oc patch bc/hello-world-apb --patch="{\"spec\": {\"output\": {\"imageLabels\":[{\"name\":\"com.redhat.apb.spec\", \"value\": \"$(base64 --wrap=0 apb.yml)\"}]}}}"
    
  2. Start new build

     oc start-build hello-world-apb
    

Using docker

Alternatively, building an image using docker CLI allows adding arbitrary labels during build.

  1. Remove the com.redhat.apb.spec label from the Dockerfile (the default trailing slash causes a syntax error).

  2. Build using this command, base64 encoding the apb.yaml file as a label:

     $ sudo docker build --label "com.redhat.apb.spec=$(base64 --wrap=0 apb.yml)" -t apb-test .
    
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment