Artifacts, versions and the build-once rule
Understand software deliverables as immutable build artifacts, enforce the build-once rule across deployment stages, and master Semantic Versioning semantics.
Contentsand lesson path
On this page
- The build-once rule: ship the bytes you tested
- Semantic Versioning: Contractual Communication Across Systems
- The Invariant of Artifact Immutability in Enterprise Registries
- Check your understanding
- Apply it
- Review prompt
Lessons of Artifact Management
- Artifacts, versions and the build-once rule Concept · 15 min
- Mutable names, immutable identities: tags, checksums and digests Worked example · 15 min
- Lab: publish a versioned package from CI Lab · 25 min
- Registries: access control, retention, immutability and pull-through caches Concept · 20 min
- Promoting a release to production without rebuilding it Worked example · 20 min
- Check: trace a deployed artifact back to its commit Knowledge check · 6 questions
What you will learn
- Apply a versioning scheme (semantic versions and commit SHAs) and identify artifacts immutably by checksum or digest, so any build traces back to its source commit.
- Promote one verified artifact through staging and production instead of rebuilding it for each environment.
01. The build-once rule: ship the bytes you tested
In legacy release engineering, software delivery frequently relied on compiling source code directly on target servers or triggering separate continuous integration builds for each deployment environment (build-staging, build-production). This looks simple, but it means that the bytes you release are not the bytes you tested.
Even when two builds are executed from the exact same Git commit SHA, build environments are usually not deterministic. Upstream dependency mirrors may publish a patched transitive library, base container image layers may refresh beneath an unpinned tag, dynamic system timestamps change binary bytecode layouts, and compiler flags may subtly diverge across build agents. If production is deployed from a freshly compiled build, the binary executing in production is not the binary that passed quality assurance and staging validation.
To make sure production runs what was tested, teams follow the Build-Once Rule:
-
Compile Once at the Start of the Pipeline: The continuous integration pipeline compiles source code, links binaries, packages libraries, and builds container images once per commit.
-
Publish an Immutable Artifact: The resulting binary payload (such as an OCI container image, deb package, or compressed tarball) is stamped with an immutable cryptographic digest and stored in an enterprise artifact registry.
-
Promote the Tested Binary Unchanged: Staging, load testing, and production environments deploy the exact same binary package. Configuration differences (database connection strings, API gateway URLs, secret tokens) are injected at runtime through environment variables or mounted configuration maps, not baked into the binary deliverable.
This removes one common cause of "it worked in staging, but crashed in production". When a defect appears only in production, engineers can rule out a different build and look at configuration, data, capacity or external dependencies instead.
In addition, engineering organizations establish standardized packaging conventions across development teams. Defining one build entry point (such as make package or pnpm build) means every CI run uses the same compiler flags, optimisation levels and compression settings, whoever pushed the commit.
02. Semantic Versioning: Contractual Communication Across Systems
Software packages do not exist in isolation; they are consumed by microservices, peer applications, and third-party developers. To communicate the impact of changes clearly, the software industry standardizes on Semantic Versioning (SemVer 2.0.0). Under SemVer, version numbers adhere strictly to the tripartite format MAJOR.MINOR.PATCH:
-
MAJOR (
X.0.0): Incremented when you introduce incompatible, breaking API changes. Consumers must modify their calling code, schema structures, or endpoint contracts before upgrading. -
MINOR (
1.Y.0): Incremented when you add functionality in a backward-compatible manner. Existing callers can safely update without breaking changes. -
PATCH (
1.0.Z): Incremented when you introduce backward-compatible bug fixes, security patches, or internal performance enhancements. -
Pre-Release Identifiers: Suffixes preceded by a hyphen (such as
1.4.0-rc.1or2.0.0-beta.2) denote pre-release candidates. A pre-release has lower precedence than the release it leads to, so1.4.0-rc.1sorts before1.4.0. -
Build Metadata: Suffixes preceded by a plus sign (such as
1.4.0+20261028.sha.e4f89a2) provide build diagnostic information. SemVer rules specify that build metadata is ignored when comparing version precedence, meaning1.4.0+build.1and1.4.0+build.2possess identical semantic priority.
The Python script below parses version strings with the regular expression suggested in the SemVer FAQ. It accepts build metadata (+...) and rejects leading zeros such as 01.2.3, which a quick hand-written pattern often gets wrong. Run it with python3 semver.py (Python 3.11 or later).
import re
from dataclasses import dataclass
# Official SemVer 2.0.0 regex (semver.org FAQ), split over lines.
NUM = r"0|[1-9]\d*"
PRE_ID = r"(?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*)"
SEMVER_RE = re.compile(
rf"^(?P<major>{NUM})\.(?P<minor>{NUM})\.(?P<patch>{NUM})"
rf"(?:-(?P<pre>{PRE_ID}(?:\.{PRE_ID})*))?"
r"(?:\+(?P<build>[0-9a-zA-Z-]+(?:\.[0-9a-zA-Z-]+)*))?$"
)
@dataclass(frozen=True)
class SemVer:
major: int
minor: int
patch: int
prerelease: str = ""
buildmeta: str = ""
@classmethod
def parse(cls, version_str: str) -> "SemVer":
# A leading "v" is a tag convention, not part of SemVer itself.
match = SEMVER_RE.match(version_str.strip().removeprefix("v"))
if not match:
raise ValueError(f"Invalid SemVer string: {version_str}")
g = match.groupdict()
return cls(int(g["major"]), int(g["minor"]), int(g["patch"]),
g["pre"] or "", g["build"] or "")
def is_breaking_upgrade(self, target: "SemVer") -> bool:
"""Enforce breaking change detection between releases."""
return target.major > self.major
# Example evaluation of release transitions
current = SemVer.parse("1.4.2")
feature = SemVer.parse("1.5.0")
breaking = SemVer.parse("2.0.0")
assert not current.is_breaking_upgrade(feature), "Minor is non-breaking"
assert current.is_breaking_upgrade(breaking), "Major is breaking"
print(SemVer.parse("1.4.0+20261028.sha.e4f89a2"))
print(SemVer.parse("v1.4.0-rc.1"))
for bad in ("01.2.3", "1.2", "1.2.3-01"):
try:
SemVer.parse(bad)
except ValueError as err:
print(err)SemVer(major=1, minor=4, patch=0, prerelease='', buildmeta='20261028.sha.e4f89a2')
SemVer(major=1, minor=4, patch=0, prerelease='rc.1', buildmeta='')
Invalid SemVer string: 01.2.3
Invalid SemVer string: 1.2
Invalid SemVer string: 1.2.3-0103. The Invariant of Artifact Immutability in Enterprise Registries
Never overwrite a published version: once payment-service-1.4.0.tar.gz is uploaded to an artifact repository (such as Artifactory, Nexus, GitHub Packages, or AWS ECR), the name 1.4.0 must always mean the same bytes. Deletion is a different question. It should be rare, controlled and audited: for example, a release that turns out to contain a leaked secret or malware is withdrawn (npm deprecate or unpublish, PyPI yank, or deletion) and replaced by a new version. A yank does not delete anything: under PEP 592, installers ignore a yanked release whenever another version satisfies the requirement, but an exact pin such as mylib==1.4.0 still installs it, so builds that pinned the release keep working while new installs move on. Retention policies may also delete unreleased CI builds (lesson 04), but not versions that are or were deployed.
If an organization allows overwriting existing release versions, several things break:
-
Downstream Build Non-Reproducibility: Dependent microservices that locked
payment-service == 1.4.0in their manifest files will pull different binary bytes on subsequent builds, invalidating automated integration tests. -
Integrity Errors in Lockfiles: Lockfiles (
package-lock.json,Cargo.lock, pip--require-hashesfiles) record the hash of each version. If the registry changes the bytes behind1.4.0, every build that checks those hashes fails with an integrity error until someone updates the lockfiles. -
Reliable Rollback: If an emergency bug is discovered in
1.4.0, developers must never overwrite1.4.0. Instead, they immediately publish1.4.1with the corrective patch. Keeping released versions unchanged means that rolling back to1.3.9deploys exactly the bytes you ran before. Whether that rollback is safe still depends on compatibility with the current database schema and data (lesson 05). -
Auditability and Compliance: Audits such as SOC 2 or ISO 27001 usually expect change records that trace the software running in production back to a specific build output and source control commit. Neither standard prescribes this exact control, but an auditor will ask how you know what was deployed. Overwriting packages breaks that chain, because the record no longer points at the bytes that ran.
04. Check your understanding
05. Apply it
Implement these artifact management disciplines across your engineering pipelines:
- Build Once, Deploy Many: Make your CI workflow build a single package and promote that package through every testing stage.
- Externalize Environment Configuration: Inject all database URIs, API keys, and operational flags at runtime using environment variables.
- Adhere Contractually to SemVer: Increment MAJOR versions for breaking changes, MINOR for new backward-compatible capabilities, and PATCH for bug fixes.
- Enforce Registry Immutability: Configure your package registry (Artifactory, Nexus, AWS ECR) to reject overwriting a version, and restrict deletion of released versions to a small, audited group.
- Ship New Patches for Bugfixes: When an error is discovered in a published release, publish a new version rather than altering existing packages.
06. Review prompt
Explain the technical risks associated with rebuilding software binaries for each target environment, and describe how the build-once rule mitigates them. Contrast the semantic meaning of MAJOR, MINOR, and PATCH version increments, and explain why package registries should refuse to overwrite a published version.
References
Your progress
Reading state
Sign in to save that you finished reading this lesson.
Prove this skill
6 questions · about 5 minutes · scored automatically. Marking a lesson as read never demonstrates a skill.