In simple words
- Artifact: a file produced by a build, such as a .jar, a Docker image, an npm package or a Helm chart.
- Artifact repository: a server that stores and serves artifacts with versions, permissions and history.
- Build once, deploy many: build an artifact once, then deploy that exact file to every environment.
- Artifactory / Nexus: the two most popular artifact repository products.
Big picture
Think of a warehouse. A factory builds products, and the warehouse stores them with labels, so any shop can collect exactly the product it ordered. An artifact repository is that warehouse for software. CI builds your app, and the repository keeps the result, safe and labelled, until someone needs it.
What is an artifact?
An artifact is any file your build produces or your build needs.
| Kind | Examples |
|---|---|
| Packages | .jar, .war, .whl, .tgz, .nupkg |
| Container images | shop-api:1.4.2 |
| Charts and installers | Helm charts, .deb, .rpm, .zip |
| Libraries you download | Spring, React, requests |
Two directions matter. Your build produces artifacts (it publishes them). Your build also consumes artifacts (it downloads libraries). A repository helps with both.
The problem without a repository
- Builds download libraries from the public internet every time. If the site is down, your build breaks.
- A library author can delete or change a package. Your old build then cannot be repeated.
- Each server builds its own copy, so "the same version" is not really the same.
- Nobody knows which code made the file now running in production.
- Old files pile up on shared disks, or in someone's home folder.
Here is a real example. In 2016 a developer removed a tiny public package called left-pad. Thousands of builds around the world failed in minutes. A repository that had cached the package would have kept working.
Build once, deploy many
The golden rule: build the artifact one time, then move that exact file through dev, test and prod. Never rebuild for production, because a rebuild can give a different result (a new library version, a different compiler, a changed clock).
commit -> CI build -> shop-api-1.4.2.jar in Artifactory |-> deploy to dev |-> deploy to staging (same file) |-> deploy to prod (same file)You can prove the files are the same by comparing their checksum, a short fingerprint of the content:
sha256sum shop-api-1.4.2.jar9b1f4c0e7d2a...c3 shop-api-1.4.2.jarIf the fingerprint is the same in dev and prod, the file is the same. Artifactory stores this checksum for every file.
Versions: the rules
| Rule | Why |
|---|---|
| Every build gets a version number | you can say exactly what runs |
| A released version never changes | caches, rollbacks and audits stay correct |
A fix is a new version (1.4.3) | history stays clear |
Use semantic versions: MAJOR.MINOR.PATCH | the number tells you how big the change is |
Semantic versioning in one line: change PATCH for a bug fix, MINOR for a new feature that does not break anything, and MAJOR for a change that can break users.
What a repository gives you
| Benefit | In plain words |
|---|---|
| One home | All packages and images in one place |
| Versions | Every build has a number, and nothing is overwritten |
| Cache | Public libraries are copied once, then served fast and offline |
| Access control | You choose who can read and who can publish |
| Scanning | Check files for known security problems |
| Traceability | Link a file back to the commit and build that made it |
| Promotion | Move a tested file from dev to prod with a clear record |
The main products
| Product | Notes |
|---|---|
| JFrog Artifactory | Many package types, strong security tools, popular in large companies |
| Sonatype Nexus Repository | Many package types, has a free community edition |
| Cloud registries | ECR, GitHub Packages, GitLab Package Registry: simple, tied to one platform |
This course teaches Artifactory in depth and Nexus in lesson 13.
How the course fits together
| Lessons | You learn |
|---|---|
| 1-3 | what a repository is, the repository types, how to set one up |
| 4-7 | publishing and downloading Maven, Docker, npm, PyPI, Helm, and the JFrog CLI |
| 8-10 | people and tokens, CI and promotion, properties and search |
| 11-12 | clean-up and security scanning |
| 13-16 | Nexus, high availability, replication, performance |
Common mistakes
- Rebuilding the same version for each environment.
- Overwriting a released version. Once
1.4.2is out, never change it. - Letting builds pull straight from the internet.
- Keeping the only copy of a release on a build server's disk.
Summary
- An artifact repository stores build results and downloaded libraries.
- Build once, then promote the same file. Compare checksums to prove it.
- Released versions never change. A fix gets a new version.
- You gain speed, safety and a clear history.
CHECK YOUR UNDERSTANDING
3 quick questions
1. What does 'build once, deploy many' mean?
2. A release version 1.4.2 has a bug. What should you do?
3. Which is a benefit of caching public libraries in a repository?