Skip to content

Commit

Permalink
Inject version requirement and bundle ID into charts
Browse files Browse the repository at this point in the history
Signed-off-by: Brad Davidson <[email protected]>
  • Loading branch information
brandond committed Feb 10, 2022
1 parent d3153fb commit 0aa4ce3
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 2 deletions.
5 changes: 4 additions & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,9 @@ RUN set -x \
gcc \
bsd-compat-headers \
py-pip \
pigz
pigz \
tar \
yq

# Dapper/Drone/CI environment
FROM build AS dapper
Expand Down Expand Up @@ -92,6 +94,7 @@ VOLUME /var/lib/rancher/k3s

FROM build AS charts
ARG CHART_REPO="https://rke2-charts.rancher.io"
ARG KUBERNETES_VERSION=""
ARG CACHEBUST="cachebust"
COPY charts/ /charts/
RUN echo ${CACHEBUST}>/dev/null
Expand Down
25 changes: 24 additions & 1 deletion charts/build-chart.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,34 @@

set -eux -o pipefail

: "${KUBERNETES_VERSION:=v0.0.0-0}"
: "${CHART_FILE?required}"
: "${CHART_NAME:="$(basename "${CHART_FILE%%.yaml}")"}"
: "${CHART_PACKAGE:="${CHART_NAME%%-crd}"}"
: "${TAR_OPTS:=--owner=0 --group=0 --mode=gou-s+r --numeric-owner --no-acls --no-selinux --no-xattrs}"
: "${CHART_URL:="${CHART_REPO:="https://rke2-charts.rancher.io"}/assets/${CHART_PACKAGE}/${CHART_NAME}-${CHART_VERSION:="v0.0.0"}.tgz"}"
curl -fsSL "${CHART_URL}" -o "${CHART_TMP:=$(mktemp)}"
: "${CHART_TMP:=$(mktemp --suffix .tar.gz)}"
: "${YAML_TMP:=$(mktemp --suffix .yaml)}"

cleanup() {
exit_code=$?
trap - EXIT INT
rm -rf ${CHART_TMP} ${CHART_TMP/tar.gz/tar} ${YAML_TMP}
exit ${exit_code}
}
trap cleanup EXIT INT

curl -fsSL "${CHART_URL}" -o "${CHART_TMP}"
gunzip ${CHART_TMP}

# Extract out Chart.yaml, inject a version requirement and bundle-id annotation, and delete/replace the one in the original tarball
tar -xOf ${CHART_TMP/.gz/} ${CHART_NAME}/Chart.yaml > ${YAML_TMP}
yq -i e ".kubeVersion = \">= ${KUBERNETES_VERSION}\" | .annotations.\"fleet.cattle.io/bundle-id\" = \"rke2\"" ${YAML_TMP}
tar --delete -b 8192 -f ${CHART_TMP/.gz/} ${CHART_NAME}/Chart.yaml
tar --transform="s|.*|${CHART_NAME}/Chart.yaml|" ${TAR_OPTS} -vrf ${CHART_TMP/.gz/} ${YAML_TMP}

pigz -11 ${CHART_TMP/.gz/}

cat <<-EOF > "${CHART_FILE}"
apiVersion: helm.cattle.io/v1
kind: HelmChart
Expand Down

0 comments on commit 0aa4ce3

Please sign in to comment.