โ 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
BuildConfigis 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
| Feature | Description |
|---|---|
| ๐ฏ Multiple Build Strategies | Supports S2I, Dockerfile, and Custom strategies. |
| ๐ Git Integration | Pulls source code directly from public/private Git repositories. |
| ๐ Automatic Triggers | Rebuilds can be triggered by Git changes, image changes, or config changes. |
| ๐ Custom Build Environment | Supports environment variables, secrets, and configmaps during builds. |
| ๐ท๏ธ ImageStream Integration | Built images can be pushed to internal ImageStreams or external registries. |
| ๐ฅ Webhooks | Allows GitHub/GitLab to trigger builds via webhooks. |
| ๐ Build Logs & History | Easily view build logs, status, and retry failed builds. |
| ๐ Secure Build Contexts | Supports source credentials, secrets, and isolated build pods. |
๐ง Example Use Cases
| Scenario | How BuildConfig Helps |
|---|---|
| CI/CD automation | Auto-rebuild on Git push or base image update |
| DevOps in hybrid cloud | Works with internal and external image registries |
| Compliance & traceability | Full build history and image tracking |
| S2I app deployment (Node.js, Python, etc.) | Uses language-specific builder images |
๐ฆ BuildConfig vs Dockerfile vs Pipelines
| Tool/Concept | Role |
|---|---|
| BuildConfig | Defines how to build an image from source |
| Dockerfile | Manual build instructions (used in Docker strategy) |
| Pipelines | Orchestrates multiple stages/jobs (Tekton-based) |
๐ BuildConfig Lifecycle
- Developer pushes code to Git
- OpenShift triggers a build (via webhook or manually)
- Code is fetched and built using specified strategy
- Final image is stored (ImageStream or registry)
- 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
| Requirement | Details |
|---|---|
| OpenShift cluster | Access to 4.13+ (Azure, local, etc.) |
| Project created | Use oc new-project or create via Web UI |
| GitHub repo with app code | e.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)
- Create/Open a project
oc new-project nodejs-s2i-demo - Apply this working
BuildConfigYAML:
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
Code language: JavaScript (javascript)
- Start the build manually:
oc start-build nodejs-sample-build --follow - Deploy the built image:
oc new-app nodejs-sample oc expose svc/nodejs-sample - 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)
- Go to Developer โ +Add โ From Git
- Fill Git Repository info:
- Git Repo URL:
https://github.com/sclorg/nodejs-ex.git - Git Reference:
main(or leave blank) - Context Dir:
.
- Git Repo URL:
- Builder Image Selection (Build from):
- Select โDocker Imageโ from the build option dropdown
- Input Docker Image:
registry.access.redhat.com/ubi8/nodejs-16
- Deployment Settings:
- App Name:
nodejs-sample - Resources: Deployment (leave default)
- Create Route: โ (enabled)
- App Name:
- Click “Create”
OpenShift will:
- Create
BuildConfig,ImageStream,Deployment, andRoute - 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
| Step | UI Path | YAML Equivalent |
|---|---|---|
| Git source | From Git | source.git.uri |
| Docker image | Select โDocker Imageโ | strategy.sourceStrategy.from.kind: DockerImage |
| Deployment | Auto-created via +Add | Use oc new-app after build manually |
| Route | Enabled in UI | oc expose svc/nodejs-sample |
I’m Rajesh Kumar, a DevOps, SRE, DevSecOps, Cloud, and Platform Engineering expert passionate about sharing practical knowledge, real-world experiences, and industry best practices. I have worked at Cotocus and regularly write about technology, travel, investing, health, product reviews, and digital marketing through my various platforms.
I publish technical articles at DevOps School, travel stories at Holiday Landmark, stock market insights at Stocks Mantra, health and fitness guidance at My Medic Plus, product reviews at TrueReviewNow, and SEO and digital marketing strategies at Wizbrand.
Find Trusted Cardiac Hospitals
Compare heart hospitals by city and services โ all in one place.
Explore Hospitals