β 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
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
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
- 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 a DevOps/SRE/DevSecOps/Cloud Expert passionate about sharing knowledge and experiences. I am working at Cotocus. I blog tech insights at DevOps School, travel stories at Holiday Landmark, stock market tips at Stocks Mantra, health and fitness guidance at My Medic Plus, product reviews at I reviewed , and SEO strategies at Wizbrand.
Do you want to learn Quantum Computing?
Please find my social handles as below;
Rajesh Kumar Personal Website
Rajesh Kumar at YOUTUBE
Rajesh Kumar at INSTAGRAM
Rajesh Kumar at X
Rajesh Kumar at FACEBOOK
Rajesh Kumar at LINKEDIN
Rajesh Kumar at PINTEREST
Rajesh Kumar at QUORA
Rajesh Kumar at WIZBRAND