Skip to content

OpenShift Build Workflow

For this exercise you need a GitHub personal access token. In GitHub navigate to Settings -> Developer Settings.

oc create secret generic example-github-secret --from-literal=WebHookSecretKey=<PERSONAL_ACCESS_TOKEN>
buildConfig.yaml
kind: BuildConfig
apiVersion: build.openshift.io/v1
metadata:
  name: example-build
  namespace: example-project
spec:
  nodeSelector: null
  output:
    to:
      kind: DockerImage
      name: >-
        image-registry.openshift-image-registry.svc:5000/example-project/fastapi-serve-static:1.0.0
  resources:
    limits:
      cpu: '1'
      memory: 1Gi
    requests:
      cpu: '1'
      memory: 1Gi
  successBuildHistoryLimit: 3
  failedBuildHistoryLimit: 3
  strategy: 
    type: Docker
    dockerStrategy:
      dockerfilePath: Containerfile
  postCommit: {}
  source: 
    type: Git
    git:
      uri: >-
        https://github.com/codewalkr/fastapi-serve-static.git
      ref: main
    sourceSecret:
      name: example-github-secret
  runPolicy: "Serial" 
  triggers: 
    - type: ConfigChange
      type: "GitHub"
      github:
        secretReference:
          name: example-github-secret
    - type: ImageChange
      imageChange:
        lastTriggerImageID: >-
          registry.access.redhat.com/ubi9/python-312:latest
    - type: "ImageChange"
webhook-secret.yaml
kind: Secret
apiVersion: v1
metadata:
  name: webhook-secret
  namespace: example-project
data:
  WebHookSecretKey: <BASE64 Encoded>
type: Opaque

With BuildConfig you can get webhook URL.

Add deployment/service/route

``` oc set triggers deploy/example --from-image=demo:latest -c demo