Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -303,6 +303,12 @@ check-mod: ## Ensure the go mod files are up-to-date
.PHONY: check-helm
check-helm: ## Ensure the helm charts lint successfully and can be read by ArtifactHub
helm lint helm/*
@# A line ending in whitespace, e.g. in the artifacthub.io/changes changelog, cannot be written as a YAML
@# block scalar, so the Helm repository index would hold that annotation as a long quoted string instead.
@if grep -n -E '[[:space:]]+$$' helm/*/Chart.yaml; then \
echo "The lines above, in the charts' Chart.yaml files, end in whitespace. Please remove it." >&2; \
exit 1; \
fi
# Check that the ArtifactHub Metadata is correct
docker run --rm --name artifact-hub-check -v "${PWD}/helm:/etc/helm" artifacthub/ah ah lint -k helm -p /etc/helm

Expand Down
12 changes: 10 additions & 2 deletions dev-docs/helm-repository.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,15 @@ It needs Docker, since the registry, the index server and each Helm version run

[`update_helm_index.sh`](../hack/release/upload/update_helm_index.sh) adds a release to the index.
It downloads the released charts, verifies their checksums and GPG signatures, writes entries
pointing at the OCI registry, and signs the index. It never commits or uploads anything.
pointing at the OCI registry. It never commits or uploads anything.

The index is not signed. Helm never checks a signature on a repository index, so a detached
signature next to it would protect nobody. What `helm install --verify` does check is each chart's
provenance (`.prov`) file, signed by the release manager and pushed to the OCI registry with the
chart. Changes to the index itself go through reviewed commits to solr-site.

The index is written the way Helm writes one, with lists not indented under their keys, so that an
update's diff only shows the entries that changed.

A release does this in the release wizard's `website_update_helm_index` step, after the charts are
published to the OCI registry (`publish_helm_charts_oci`), and the website change is published with
Expand All @@ -69,7 +77,7 @@ the website redirects to nightlies.apache.org. To move one of them to OCI:
-r https://archive.apache.org/dist/solr/solr-operator/v0.9.1 \
-i ../solr-site/content/charts/index.yaml
```
3. Commit the updated `index.yaml`, `index.yaml.asc` and `index.yaml.sha512` in solr-site.
3. Commit the updated `index.yaml` in solr-site.

Versions from before the donation to Apache (`v0.2.x`) have no archive.apache.org copy, so they
are left as they are.
Expand Down
2 changes: 1 addition & 1 deletion hack/release/smoke_test/test_oci_index.sh
Original file line number Diff line number Diff line change
Expand Up @@ -257,7 +257,7 @@ fi

# --- Generate the index, exactly as a release would ----------------------------------------------

./hack/release/upload/update_helm_index.sh -n -c -d "${CHARTS_DIR}" -o "${OCI_BASE}" -i "${SITE_DIR}/index.yaml"
./hack/release/upload/update_helm_index.sh -c -d "${CHARTS_DIR}" -o "${OCI_BASE}" -i "${SITE_DIR}/index.yaml"

# --- The checks, run once per Helm version -------------------------------------------------------

Expand Down
41 changes: 13 additions & 28 deletions hack/release/upload/update_helm_index.sh
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,17 @@ set -u

show_help() {
cat << EOF
Usage: ./hack/release/upload/update_helm_index.sh [-h] [-g GPG_KEY] [-n] [-c] [-o OCI_BASE] [-v VERSION] (-r RELEASE_URL | -d CHARTS_DIR) -i INDEX_FILE
Usage: ./hack/release/upload/update_helm_index.sh [-h] [-c] [-o OCI_BASE] [-v VERSION] (-r RELEASE_URL | -d CHARTS_DIR) -i INDEX_FILE

Add (or replace) Helm chart versions in a Helm repository index.yaml, whose entries point at
the OCI registry the charts were published to, instead of at HTTPS tarballs.

The index is served from https://solr.apache.org/charts, and is checked into the solr-site
repository. Point -i at the index.yaml in a solr-site checkout. Nothing is committed or uploaded.

The index is not signed. Helm never checks a signature on a repository index: what 'helm install
--verify' checks is each chart's .prov file, which is pushed to the OCI registry with the chart.

An entry that already exists for the same chart and version is replaced in place, keeping its
original 'created' timestamp. Its digest must not change, since the OCI copy is required to be
byte-identical to the released chart. This makes it safe to re-run, and is what backfills older
Expand All @@ -47,16 +50,14 @@ releases once they have been published to the OCI registry.
Meant for testing.
-v Version of the release, e.g. v0.10.0 (Optional, defaults to the last path element of -r)
-o OCI registry the charts were pushed to (Optional, defaults to ${DEFAULT_OCI_BASE})
-g GPG Key to sign the new index file (Optional, defaults to the gpg default key)
-n Do not sign the index, or write its checksum. Meant for testing.
EOF
}

DEFAULT_OCI_BASE="oci://ghcr.io/apache/solr-operator/helm"
CHART_NAMES=(solr-operator solr)

OPTIND=1
while getopts hi:r:d:v:o:g:nc opt; do
while getopts hi:r:d:v:o:c opt; do
case $opt in
h)
show_help
Expand All @@ -72,10 +73,6 @@ while getopts hi:r:d:v:o:g:nc opt; do
;;
o) OCI_BASE=$OPTARG
;;
g) GPG_KEY=$OPTARG
;;
n) NO_SIGN=true
;;
c) CREATE=true
;;
*)
Expand Down Expand Up @@ -111,6 +108,9 @@ if [[ ! -x "${YQ}" ]]; then
echo "yq was not found at ${YQ}. Run 'make yq' first, or set the YQ env var." >&2 && exit 1
fi
HELM="${HELM:-helm}"
# Helm writes lists without indenting them under their key, and yq indents them unless told not to.
# Writing the index the same way keeps an update's diff down to the entries that actually changed.
YQ_WRITE=("${YQ}" --yaml-compact-seq-indent)

sha512() {
if command -v sha512sum >/dev/null 2>&1; then
Expand Down Expand Up @@ -168,7 +168,7 @@ fi
# can only produce HTTP urls. Helm resolves an oci:// url with a tag through its OCI getter.
NEW_INDEX="${TMP_DIR}/charts/index.yaml"
"${HELM}" repo index "${TMP_DIR}/charts"
OCI_BASE="${OCI_BASE}" "${YQ}" -i \
OCI_BASE="${OCI_BASE}" "${YQ_WRITE[@]}" -i \
'.entries[][] |= (.urls = [strenv(OCI_BASE) + "/" + .name + ":" + .version])' "${NEW_INDEX}"

# Guard against indexing a chart whose digest does not match the tarball that was verified.
Expand All @@ -182,7 +182,7 @@ done < <("${YQ}" '.entries[][] | [.name, .version, .digest] | @tsv' "${NEW_INDEX
# Start from the existing index, dropping its comments (the license header is re-added below).
WORK_INDEX="${TMP_DIR}/index.yaml"
if [[ -f "${INDEX_FILE}" ]]; then
"${YQ}" '... comments=""' "${INDEX_FILE}" > "${WORK_INDEX}"
"${YQ_WRITE[@]}" '... comments=""' "${INDEX_FILE}" > "${WORK_INDEX}"
else
echo "Creating a new index at ${INDEX_FILE}"
printf 'apiVersion: v1\nentries: {}\n' > "${WORK_INDEX}"
Expand All @@ -200,14 +200,14 @@ while IFS=$'\t' read -r name version; do
exit 1
fi
echo "Replacing ${name} ${version}, keeping its original created timestamp"
"${YQ}" -i '
"${YQ_WRITE[@]}" -i '
(.entries[strenv(N)][] | select(.version == strenv(V))) |=
(load(strenv(NEW)).entries[strenv(N)][] | select(.version == strenv(V))) * {"created": .created}
' "${WORK_INDEX}"
else
echo "Adding ${name} ${version}"
# New releases are prepended, so the index stays newest-first. Helm sorts on load anyway.
"${YQ}" -i '
"${YQ_WRITE[@]}" -i '
.entries[strenv(N)] = (
[load(strenv(NEW)).entries[strenv(N)][] | select(.version == strenv(V))] + (.entries[strenv(N)] // [])
)
Expand All @@ -216,7 +216,7 @@ while IFS=$'\t' read -r name version; do
unset N V NEW
done < <("${YQ}" '.entries[][] | [.name, .version] | @tsv' "${NEW_INDEX}")

GENERATED="$(date -u +%Y-%m-%dT%H:%M:%S.000000000Z)" "${YQ}" -i '.generated = strenv(GENERATED)' "${WORK_INDEX}"
GENERATED="$(date -u +%Y-%m-%dT%H:%M:%S.000000000Z)" "${YQ_WRITE[@]}" -i '.generated = strenv(GENERATED)' "${WORK_INDEX}"

mkdir -p "$(dirname "${INDEX_FILE}")"
{
Expand All @@ -225,18 +225,3 @@ mkdir -p "$(dirname "${INDEX_FILE}")"
cat "${WORK_INDEX}"
} > "${INDEX_FILE}"
echo "Wrote ${INDEX_FILE}"

if [[ "${NO_SIGN:-}" != "true" ]]; then
GPG_USER=()
if [[ -n "${GPG_KEY:-}" ]]; then
GPG_USER=(-u "${GPG_KEY}")
fi
(
cd "$(dirname "${INDEX_FILE}")"
index_name="$(basename "${INDEX_FILE}")"
rm -f "${index_name}.asc"
gpg ${GPG_USER[@]+"${GPG_USER[@]}"} --pinentry-mode loopback -ab "${index_name}"
sha512 -b "${index_name}" > "${index_name}.sha512"
)
echo "Signed ${INDEX_FILE}, and wrote its checksum"
fi
6 changes: 3 additions & 3 deletions hack/release/wizard/releaseWizard.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -1383,20 +1383,20 @@ groups:
signatures, and adds entries for them to the index, pointing at:
- oci://ghcr.io/apache/solr-operator/helm/solr-operator:{{ release_version[1:] }}
- oci://ghcr.io/apache/solr-operator/helm/solr:{{ release_version[1:] }}
It then signs the index, and writes its checksum.
The index is not signed: Helm never checks a signature on a repository index, and the
charts' own provenance (.prov) files, which 'helm install --verify' checks, are on ghcr.io.
commands: !Commands
root_folder: '{{ git_checkout_folder }}'
confirm_each_command: false
commands_text: |
This will add the new release to the website's Helm repository index.
You will be prompted for your GPG Key passphrase, to sign the index.yaml.
commands:
- !Command
cmd: git checkout {{ release_version }} && make yq
comment: The index script and yq come from the release tag
tee: true
- !Command
cmd: ./hack/release/upload/update_helm_index.sh -g "{{ gpg_key | default("<gpg_key_id>", True) }}" -r "{{ dist_release_url }}" -i "{{ helm_index_file }}"
cmd: ./hack/release/upload/update_helm_index.sh -r "{{ dist_release_url }}" -i "{{ helm_index_file }}"
logfile: update_helm_index.log
tee: true
- !Command
Expand Down
Loading