Skip to content

Commit 2382ec8

Browse files
committed
feat(cache): include Pigsty source in offline bundle
1 parent 592cb5f commit 2382ec8

4 files changed

Lines changed: 110 additions & 11 deletions

File tree

cache.yml

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
# File : cache.yml
55
# Desc : Create offline package cache from infra nodes
66
# Ctime : 2024-08-22
7-
# Mtime : 2024-12-31
7+
# Mtime : 2026-08-14
88
# Path : cache.yml
99
# Docs : https://pigsty.io/docs/setup/offline
1010
# License : Apache-2.0 @ https://pigsty.io/docs/about/license/
@@ -48,9 +48,10 @@
4848
#--------------------------------------------------------------#
4949
# This play runs on the target infra node to:
5050
# 1. Detect node identity (OS, version, architecture)
51-
# 2. Clean dirty packages and recreate repo metadata
52-
# 3. Create compressed tarball at /tmp/pkg.tgz
53-
# 4. Fetch tarball back to control node
51+
# 2. Include the versioned Pigsty source release artifact when available
52+
# 3. Clean dirty packages and recreate repo metadata
53+
# 4. Create compressed tarball at /tmp/pkg.tgz
54+
# 5. Fetch tarball back to control node
5455
#--------------------------------------------------------------#
5556
- name: MAKE OFFLINE PACKAGE
5657
hosts: all
@@ -61,6 +62,7 @@
6162
#cache_repo: pigsty # target repo(s) to be cached, use `,` to separate multiple repos
6263
#cache_pkg_dir: 'dist/${version}' # where to store the cached package? dist/${version} by default
6364
#cache_pkg_name: 'pigsty-pkg-${version}.${os}.${arch}.tgz' # cache offline package filename pattern
65+
#cache_src: auto # source policy: auto, local, remote
6466
roles:
6567
- { role: node_id, tags: id } # detect node identity
6668
- { role: cache, tags: cache } # create and fetch cache tarball
@@ -109,6 +111,9 @@
109111
# # Cache multiple repos
110112
# ./cache.yml -l infra -e cache_repo=pigsty,minio
111113
#
114+
# # Air-gapped build: use pre-staged dist/${version}/pigsty-${version}.tgz
115+
# ./cache.yml -l infra -e cache_src=local
116+
#
112117
#==============================================================#
113118
# Tag Reference
114119
#==============================================================#
@@ -118,6 +123,7 @@
118123
# cache : full cache role execution
119124
# cache_id : calculate cache tarball filename
120125
# cache_check : verify repo directories exist and not empty
126+
# cache_src : include versioned Pigsty source release artifact
121127
# cache_create : clean dirty packages, recreate repo metadata
122128
# cache_tgz : create /tmp/pkg.tgz tarball on target
123129
# cache_fetch : fetch tarball from target to control node

roles/cache/README.md

Lines changed: 64 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,10 @@
1313
The `cache` role creates an **offline package tarball** from an existing local repository:
1414

1515
- Verify repository directories exist and are populated
16+
- Include the versioned Pigsty source release artifact when available
1617
- Clean up dirty/unwanted packages to reduce size
1718
- Recreate YUM/APT repository metadata
18-
- Create compressed tarball of all packages
19+
- Create a compressed tarball containing packages and optional source
1920
- Fetch tarball to control node for distribution
2021

2122
This enables:
@@ -34,6 +35,7 @@ Before running the cache role:
3435
3. **`rsync` must be installed** on both control and target nodes (for `synchronize` module)
3536
4. **SOW 0.3.0 must be available** from the Pigsty INFRA repository
3637
5. The repo should contain all required packages (run `./infra.yml -t repo` first)
38+
6. To include source in an air-gapped build, stage `dist/<version>/pigsty-<version>.tgz` first
3739

3840

3941
## Playbooks
@@ -79,6 +81,8 @@ cache # Full role execution
7981
8082
├── cache_check # Verify repo directories exist
8183
84+
├── cache_src # Resolve and include Pigsty source artifact
85+
8286
├── cache_create # Clean packages & recreate metadata
8387
8488
├── cache_tgz # Create compressed tarball
@@ -97,6 +101,12 @@ cache # Full role execution
97101
| `cache_pkg_dir` | `dist/${version}` | Output directory on control node |
98102
| `cache_repo` | `pigsty` | Repo names to cache (CSV for multiple) |
99103

104+
### Source Artifact Settings
105+
106+
| Variable | Default | Description |
107+
|-------------|---------|--------------------------------------|
108+
| `cache_src` | `auto` | Policy: `auto`, `local`, or `remote` |
109+
100110
### Referenced Variables
101111

102112
| Variable | Default | Description |
@@ -142,14 +152,61 @@ dist/<version>/pigsty-pkg-<version>.<os>.<arch>.tgz
142152
```text
143153
pigsty/ # repo_name directory
144154
├── *.rpm or *.deb # Package files
155+
├── pigsty-v4.5.0.tgz # Pigsty source release artifact, when available
145156
├── repodata/ # YUM metadata (RPM only)
146157
│ ├── repomd.xml
147158
│ └── *-primary.xml.gz # Plus filelists/other metadata
148159
├── Packages # APT metadata (DEB only)
149160
├── Packages.gz # APT metadata (DEB only)
150-
└── repo_complete # SHA-256 checksums marker
161+
└── repo_complete # Package checksum marker
162+
```
163+
164+
165+
## Pigsty Source Artifact
166+
167+
The cache role never packages the current checkout implicitly. It only looks for
168+
the versioned release artifact or downloads the same versioned filename.
169+
170+
The `cache_src` policy determines provenance:
171+
172+
| Policy | Behavior |
173+
|----------|----------|
174+
| `auto` | Try local `dist/<version>/pigsty-<version>.tgz`, then download from the versioned URL |
175+
| `local` | Copy the local `dist` artifact when it exists; never access the network |
176+
| `remote` | Download `https://repo.pigsty.io/src/pigsty-<version>.tgz` directly |
177+
178+
Source inclusion is best-effort. Copy or download errors are reported and
179+
ignored, so the package cache tarball is still produced without the source file.
180+
The source step runs only when `repo_name` is included in `cache_repo`, ensuring
181+
the source artifact is part of the resulting cache tarball. SOW scans RPM/DEB
182+
packages only and preserves the TGZ as a plain repository asset.
183+
184+
For a disconnected build, prepare the artifact explicitly and force local-only
185+
resolution:
186+
187+
```bash
188+
# Create this only when the current checkout is intentionally the release input
189+
bin/release v4.5.0
190+
191+
# Never use network; a missing file is reported and ignored
192+
./cache.yml -l infra -e cache_src=local
193+
```
194+
195+
For a normal connected release build, `auto` requires no extra arguments:
196+
197+
```bash
198+
./cache.yml -l infra
199+
```
200+
201+
With the default `repo_home` and `repo_name`, after extracting the outer cache
202+
archive the source contract is:
203+
204+
```text
205+
/www/pigsty/pigsty-<version>.tgz
151206
```
152207

208+
This stable path can be consumed by a later bootstrap enhancement without
209+
guessing from the build checkout or requiring network access.
153210

154211

155212
## Dirty Package Cleanup
@@ -232,8 +289,11 @@ ls -la /www/pigsty/
232289
# Only recreate repo metadata (skip fetch)
233290
./cache.yml -l infra -t cache_create
234291

235-
# Only create tarball and fetch (skip metadata)
236-
./cache.yml -l infra -t cache_tgz,cache_fetch
292+
# Only include source, create tarball and fetch (skip metadata)
293+
./cache.yml -l infra -t cache_src,cache_tgz,cache_fetch
294+
295+
# Use a pre-staged local source artifact (never use network)
296+
./cache.yml -l infra -e cache_src=local
237297

238298
# Show cache info only
239299
./cache.yml -l infra -t cache_info

roles/cache/defaults/main.yml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,11 @@ cache_pkg_name: 'pigsty-pkg-${version}.${os}.${arch}.tgz' # cache offline packag
66
cache_pkg_dir: 'dist/${version}' # where to store the cached package? dist/${version} by default
77
cache_repo: pigsty # target repo(s) to be cached, use `,` to separate multiple repos
88

9+
#-----------------------------------------------------------------
10+
# SOURCE
11+
#-----------------------------------------------------------------
12+
cache_src: auto # source policy: auto, local, remote
13+
914
#-----------------------------------------------------------------
1015
# REPO (Reference)
1116
#-----------------------------------------------------------------

roles/cache/tasks/main.yml

Lines changed: 31 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,9 @@
1313
cache_filename: "{{ cache_pkg_name|replace('${version}', version)|replace('${os}', node_os_code)|replace('${arch}', os_arch) }}"
1414
cache_dirname: "{{ cache_pkg_dir | replace('${version}', version) }}"
1515
cache_repo_list: "{{ cache_repo.split(',') }}"
16+
cache_src_local: "{{ playbook_dir }}/dist/{{ version }}/pigsty-{{ version }}.tgz"
17+
cache_src_url: "https://repo.pigsty.io/src/pigsty-{{ version }}.tgz"
18+
cache_src_target: "{{ repo_home }}/{{ repo_name }}/pigsty-{{ version }}.tgz"
1619

1720

1821
#--------------------------------------------------------------#
@@ -32,7 +35,32 @@
3235

3336

3437
#--------------------------------------------------------------#
35-
# 2. Create Repo [cache_create]
38+
# 2. Include Pigsty Source [cache_src]
39+
#--------------------------------------------------------------#
40+
# Include the versioned Pigsty source artifact:
41+
#
42+
# - auto: local release artifact, then URL
43+
# - local: use the local release artifact when present
44+
# - remote: download the release artifact from the versioned URL
45+
#
46+
# Only include source when repo_name is archived by cache_repo.
47+
# SOW scans RPM/DEB files only and preserves this plain TGZ asset.
48+
#--------------------------------------------------------------#
49+
- name: cache_src
50+
tags: cache_src
51+
become: true
52+
ignore_errors: true
53+
when: repo_name in cache_repo_list
54+
block:
55+
- copy: { src: "{{ cache_src_local }}", dest: "{{ cache_src_target }}", mode: '0644' }
56+
register: cache_src_copy
57+
when: cache_src|lower in ['auto', 'local']
58+
- get_url: { url: "{{ cache_src_url }}", dest: "{{ cache_src_target }}", mode: '0644', force: yes }
59+
when: cache_src|lower == 'remote' or (cache_src|lower == 'auto' and cache_src_copy is failed)
60+
61+
62+
#--------------------------------------------------------------#
63+
# 3. Create Repo [cache_create]
3664
#--------------------------------------------------------------#
3765
# Clean up dirty packages and recreate repository metadata
3866
#
@@ -59,7 +87,7 @@
5987

6088

6189
#--------------------------------------------------------------#
62-
# 3. Create Cache Tarball [cache_tgz]
90+
# 4. Create Cache Tarball [cache_tgz]
6391
#--------------------------------------------------------------#
6492
# Create compressed tarball of all repo directories
6593
# Tarball is created at /tmp/pkg.tgz on the target node
@@ -76,7 +104,7 @@
76104

77105

78106
#--------------------------------------------------------------#
79-
# 4. Fetch Cache Tarball [cache_fetch]
107+
# 5. Fetch Cache Tarball [cache_fetch]
80108
#--------------------------------------------------------------#
81109
# Pull tarball from target node to control node using rsync
82110
# Destination: {{ cache_dirname }}/{{ cache_filename }}

0 commit comments

Comments
 (0)