Skip to content

Commit 7a44793

Browse files
committed
build(task,helm:gen): make dep tgz reproducible
**Problem:** `helm dependency update` packages chart source files with their filesystem modification times. Since git does not preserve file timestamps, every checkout gets different mtimes, producing different tar bytes and thus different `.tgz` files -- even when the file contents are identical. **Fix (two layers of normalization in `helm:gen`):** 1. **Pre-packaging:** `find ... -exec env TZ=UTC touch -t 200001010000.00 {} +` normalizes all chart source file timestamps to a fixed UTC date before Helm packages them. 2. **Post-packaging:** `dd` patches the gzip header MTIME (bytes 4-7) and OS byte (byte 9) to fixed values, eliminating gzip envelope differences. Signed-off-by: Patrik Egyed <pregnor@cisco.com>
1 parent 122a4f6 commit 7a44793

File tree

1 file changed

+21
-3
lines changed

1 file changed

+21
-3
lines changed

Taskfile.yml

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2141,19 +2141,37 @@ tasks:
21412141
vars:
21422142
HELM_ALL_CHART_PATHS:
21432143
sh: find . -name Chart.yaml -exec dirname {} \;
2144-
# SOURCE_DATE_EPOCH makes Go's archive/tar use a fixed mtime so chart tgz hashes
2145-
# are reproducible across environments (CI vs local, different checkouts).
21462144
env:
2147-
SOURCE_DATE_EPOCH: "0"
2145+
SOURCE_DATE_EPOCH: "0" # SOURCE_DATE_EPOCH is kept for any Helm code paths that honour it.
21482146
cmds:
21492147
# Add Helm repo
21502148
- "{{ .HELM_BIN }} repo add project-zot http://zotregistry.dev/helm-charts"
21512149
- "{{ .HELM_BIN }} repo add spiffe https://spiffe.github.io/helm-charts-hardened"
21522150

2151+
# Reproducible chart packaging requires two layers of normalization:
2152+
# 1. File timestamps: git does not preserve mtime, so every checkout gets
2153+
# different values. We touch all chart source files to a fixed date before
2154+
# packaging so tar entry headers are identical across machines.
2155+
# 2. Gzip envelope: the MTIME and OS header bytes vary per build; we patch
2156+
# them to fixed values after packaging.
2157+
2158+
# Normalize chart source file timestamps for reproducible tar entries.
2159+
# TZ=UTC ensures the same Unix timestamp regardless of local timezone.
2160+
- for: { var: HELM_ALL_CHART_PATHS }
2161+
cmd: "find {{ .ITEM }} -exec env TZ=UTC touch -t 200001010000.00 {} +"
2162+
21532163
# Update dependencies
21542164
- for: { var: HELM_ALL_CHART_PATHS }
21552165
cmd: "cd {{ .ITEM }} && {{ .HELM_BIN }} dependency update"
21562166

2167+
# Zero out gzip header MTIME (bytes 4-7) and set OS (byte 9) to 0xff
2168+
# so tgz hashes are identical regardless of build time or platform.
2169+
- |
2170+
find . -path '*/charts/*.tgz' -type f | while read -r tgz; do
2171+
printf '\x00\x00\x00\x00' | dd of="$tgz" bs=1 seek=4 count=4 conv=notrunc 2>/dev/null
2172+
printf '\xff' | dd of="$tgz" bs=1 seek=9 count=1 conv=notrunc 2>/dev/null
2173+
done
2174+
21572175
##
21582176
## GUI
21592177
##

0 commit comments

Comments
 (0)