Serve and Publish Repositories
Putting a repository on a web server is more than copying a directory. While an update is
in flight, a client can read the new index before its packages arrive, or keep using a
cached index after you deleted the packages it names. Both show up as 404 or checksum
errors in dnf and apt. A hand-written copy script also cannot resume a half-finished
upload or tell you what the server actually holds.
For a standard repository, sow publish handles
this for you:
- Client-safe order. It copies package files first, then metadata with
content-specific file names, and replaces the entry points that clients read first,
repomd.xmlandRelease, last. - Resumable. It records progress, so rerunning the same command finishes an interrupted publication. Rerunning it after success is a no-op.
- Cache grace before deletion. Files that the new build no longer needs stay on the
target for the cache lifetime you declare, so clients holding an old index can still
download what it names. Only then can
sow gcremove them. - Verified delivery. It reads the published files back through the public endpoint before it records the publication.
In this tutorial you publish the local repository to a directory, serve that directory
with Nginx, check it from a client, and publish an update. A final section covers hosts
that SOW cannot reach.
You need:
- The
localrepository and itsel9andbookwormDists from Your first standard repository, in the/srv/sowworkspace. - Nginx on the serving host, and
sudoto create/srv/repo-public. - A
dnforaptclient that can reach the server.
The source tree is /srv/sow/local; the public copy will be /srv/repo-public/local.
Both hold the complete pool/ and dists/ tree. sow.yml and the private .sow/ state
stay outside the server root.
1. Build and check
publish delivers the last completed build, so build pending changes first. Continue when
check succeeds.
2. Add a filesystem target
Create the target’s parent directory and give the account that runs sow publish, here
your own, write access to it:
The endpoint must already exist as a real directory; SOW rejects a path with a symlink
component. Add the target to /srv/sow/sow.yml:
SOW creates /srv/repo-public/local from endpoint and prefix. The three authority
fields declare that this workspace is the source of truth and the only writer for that
path. They default to true when omitted, and an explicit false is rejected. Give other
tools their own prefix; sibling targets with distinct prefixes under the same parent
directory do not block each other.
public_endpoint and max_cache_ttl tell SOW where clients read the files and how long
they may cache them. This example checks the files through file:// and declares no
cache, so superseded files get no grace period. Once clients cache older indexes, or you
put a proxy or CDN in front, set public_endpoint to the public repository URL and
max_cache_ttl to the longest cache lifetime, then apply the change with
sow publish public --rebind.
Publish the repository:
For the sample repository, the first run and a repeat print:
The Generation number and object count depend on your repository. Exit status 0 means the
target holds the current build.
3. Configure Nginx
Install Nginx and add a server block like this one, with your hostname in place of
repo.example.com:
The last location keeps hidden files, including temporary files, private. Check and
reload the configuration:
reload assumes Nginx is already running. On a new installation, start it through your
service manager once nginx -t succeeds.
Clients use these addresses:
| Client | Address |
|---|---|
DNF baseurl |
http://repo.example.com/local/dists/el9/$basearch/ |
APT URIs |
http://repo.example.com/local |
APT Suites / Components |
bookworm / main |
The YUM and APT tutorials show the full source configuration. To verify signatures, distribute the public key as described in Sign your repository.
4. Check client access
Configure a client with the addresses above, refresh its indexes, and install a package.
Success proves that both dists/ and pool/ are reachable over HTTP; if only the refresh
works, the server treats the two directories differently. Give them the same access rules.
Publish an update
After you change membership or configuration, build and publish again:
If publication stops partway, rerun sow publish public to resume it. Once the cache
grace period has passed, remove the files that no current build needs from the target:
See sow publish for abort, recovery, and target changes, and
target GC for what gc keeps.
Deliver to an isolated host
When SOW cannot reach the destination, you take over the ordering that publish normally
provides. Never copy over the live tree: build a complete new release directory and switch
to it in one step. Stop all writes to the source repository while you create and check the copy.
- Run
sow checkon the source. - Copy the complete repository to a new release directory on the destination. Preserve hard links, for example with
rsync -aHortar. - Verify the transferred files against
sow changes 0, which lists every file of the current build with its size and SHA-256, or against an archive checksum manifest. - Switch the server’s path to the new release directory.
- Keep package and immutable metadata URLs that old indexes reference reachable until the longest client cache lifetime has passed, then remove the old release.
During that interval, the HTTP server can fall back to the previous release directory for paths missing from the new one.
Copying directly over a live tree can expose indexes before their package files arrive. Prepare the new directory first and switch it as a unit.
Serve a simple repository
For a simple repository, serve the directory you passed to
sow create, with the same dotfile rule so temporary hidden files stay private.
sow publish works only for standard repositories, so switch updates to a simple
repository as a unit, as described above.
Publish to R2
For Cloudflare R2, use provider: r2 and configure its endpoint, bucket, credential
reference, public URL, and cache lifetime; see the
target configuration reference. Publish to a
test prefix first and check it from your package clients.
On R2, sow gc TARGET only reports candidates after the cache grace period. If this
workspace is the sole writer to the prefix, run sow gc TARGET --delete to reclaim them.
See target GC.
Next steps
- Sign your repository before other hosts depend on it.
- Build the pigsty-infra repository for several channels served from one pool.
sow publishand the Publication & Recovery for recovery details.