Upgrade & Secure Your Future with DevOps, SRE, DevSecOps, MLOps!

We spend hours on Instagram and YouTube and waste money on coffee and fast food, but won’t spend 30 minutes a day learning skills to boost our careers.
Master in DevOps, SRE, DevSecOps & MLOps!

Learn from Guru Rajesh Kumar and double your salary in just one year.


Get Started Now!

OpenShift BuildConfig Tutorial

βœ… What is OpenShift BuildConfig?

BuildConfig in OpenShift is a Kubernetes-native custom resource provided by OpenShift that defines how to build a container image from source code. It automates the end-to-end image build process β€” from fetching source code to producing and storing container images β€” using build strategies like Source-to-Image (S2I), Docker, or custom workflows.


πŸ“˜ BuildConfig Definition

A BuildConfig is a declarative configuration object in OpenShift that defines the strategy, source, triggers, and output for building container images automatically or on-demand.

It’s like a recipe for converting application source code into a deployable container image.


⭐ Key Features of BuildConfig

FeatureDescription
🎯 Multiple Build StrategiesSupports S2I, Dockerfile, and Custom strategies.
πŸ”— Git IntegrationPulls source code directly from public/private Git repositories.
πŸ” Automatic TriggersRebuilds can be triggered by Git changes, image changes, or config changes.
πŸ›  Custom Build EnvironmentSupports environment variables, secrets, and configmaps during builds.
🏷️ ImageStream IntegrationBuilt images can be pushed to internal ImageStreams or external registries.
πŸ‘₯ WebhooksAllows GitHub/GitLab to trigger builds via webhooks.
πŸ” Build Logs & HistoryEasily view build logs, status, and retry failed builds.
πŸ” Secure Build ContextsSupports source credentials, secrets, and isolated build pods.

πŸ”§ Example Use Cases

ScenarioHow BuildConfig Helps
CI/CD automationAuto-rebuild on Git push or base image update
DevOps in hybrid cloudWorks with internal and external image registries
Compliance & traceabilityFull build history and image tracking
S2I app deployment (Node.js, Python, etc.)Uses language-specific builder images

πŸ“¦ BuildConfig vs Dockerfile vs Pipelines

Tool/ConceptRole
BuildConfigDefines how to build an image from source
DockerfileManual build instructions (used in Docker strategy)
PipelinesOrchestrates multiple stages/jobs (Tekton-based)

πŸš€ BuildConfig Lifecycle

  1. Developer pushes code to Git
  2. OpenShift triggers a build (via webhook or manually)
  3. Code is fetched and built using specified strategy
  4. Final image is stored (ImageStream or registry)
  5. App is deployed or updated automatically

βœ… Works on OpenShift 4.13+ (including Azure Red Hat OpenShift)


🎯 Goal

Build a Node.js application using:

  • βœ… Git source
  • βœ… External Red Hat base image (ubi8/nodejs-16)
  • βœ… OpenShift S2I strategy (using DockerImage)
  • βœ… No need for preloaded ImageStreams

🧱 Prerequisites

RequirementDetails
OpenShift clusterAccess to 4.13+ (Azure, local, etc.)
Project createdUse oc new-project or create via Web UI
GitHub repo with app codee.g., sclorg/nodejs-ex
OpenShift CLI (optional)oc logged in

🧾 Option 1: YAML Method (CLI or Web Console YAML Editor)

βœ… Step-by-Step (Using YAML)

  1. Create/Open a project oc new-project nodejs-s2i-demo
  2. Apply this working BuildConfig YAML:
apiVersion: build.openshift.io/v1
kind: BuildConfig
metadata:
  name: nodejs-sample-build
  labels:
    app: nodejs-sample
spec:
  source:
    type: Git
    git:
      uri: https://github.com/sclorg/nodejs-ex.git
      ref: main
    contextDir: .
  strategy:
    type: Source
    sourceStrategy:
      from:
        kind: DockerImage
        name: registry.access.redhat.com/ubi8/nodejs-16
      forcePull: true
  output:
    to:
      kind: ImageStreamTag
      name: nodejs-sample:latest
  triggers:
    - type: ConfigChange
    - type: ImageChange
  runPolicy: Serial
  1. Start the build manually: oc start-build nodejs-sample-build --follow
  2. Deploy the built image: oc new-app nodejs-sample oc expose svc/nodejs-sample
  3. Access the app: oc get route

πŸ–±οΈ Option 2: Using the OpenShift Developer Console UI

Based on your screenshots β€” modern and guided flow

βœ… Step-by-Step (Using Developer Web Console)

  1. Go to Developer β†’ +Add β†’ From Git
  2. Fill Git Repository info:
    • Git Repo URL: https://github.com/sclorg/nodejs-ex.git
    • Git Reference: main (or leave blank)
    • Context Dir: .
  3. Builder Image Selection (Build from):
    • Select β€œDocker Image” from the build option dropdown
    • Input Docker Image: registry.access.redhat.com/ubi8/nodejs-16
  4. Deployment Settings:
    • App Name: nodejs-sample
    • Resources: Deployment (leave default)
    • Create Route: βœ… (enabled)
  5. Click “Create”

OpenShift will:

  • Create BuildConfig, ImageStream, Deployment, and Route
  • Trigger an initial build
  • Watch progress from Builds or Topology

πŸ§ͺ How to Monitor

  • Build logs:
    Developer β†’ Builds β†’ nodejs-sample-build β†’ View Logs
  • Application route:
    Developer β†’ Topology β†’ Click route link
  • BuildConfig YAML:
    Admin β†’ Builds β†’ nodejs-sample-build β†’ YAML

πŸ” Updating Code

Just push code to GitHub and trigger a build manually:

oc start-build nodejs-sample-build

Or setup GitHub webhook using:

oc describe bc nodejs-sample-build

βœ… Summary

StepUI PathYAML Equivalent
Git sourceFrom Gitsource.git.uri
Docker imageSelect β€œDocker Image”strategy.sourceStrategy.from.kind: DockerImage
DeploymentAuto-created via +AddUse oc new-app after build manually
RouteEnabled in UIoc expose svc/nodejs-sample

Subscribe
Notify of
guest
0 Comments
Newest
Oldest Most Voted
Inline Feedbacks
View all comments

Certification Courses

DevOpsSchool has introduced a series of professional certification courses designed to enhance your skills and expertise in cutting-edge technologies and methodologies. Whether you are aiming to excel in development, security, or operations, these certifications provide a comprehensive learning experience. Explore the following programs:

DevOps Certification, SRE Certification, and DevSecOps Certification by DevOpsSchool

Explore our DevOps Certification, SRE Certification, and DevSecOps Certification programs at DevOpsSchool. Gain the expertise needed to excel in your career with hands-on training and globally recognized certifications.

0
Would love your thoughts, please comment.x
()
x