2019-01-24 17:51:14 +00:00
|
|
|
#!/bin/bash
|
|
|
|
|
|
|
|
cd $(dirname $0)/..
|
|
|
|
|
2019-11-12 23:36:04 +00:00
|
|
|
. ./scripts/version.sh
|
|
|
|
|
2021-07-02 08:43:15 +00:00
|
|
|
RUNC_VERSION=v1.0.1
|
2021-07-13 16:09:58 +00:00
|
|
|
ROOT_VERSION=v0.9.1
|
2021-07-03 09:03:50 +00:00
|
|
|
TRAEFIK_VERSION=$(awk -F/ '/traefik-([[:digit:]]+\.)/ {sub(/traefik-/, "", $6) ; sub(/\.tgz/, "", $6); print $6}' manifests/traefik.yaml)
|
2019-03-20 00:21:49 +00:00
|
|
|
CHARTS_DIR=build/static/charts
|
2021-05-17 20:30:55 +00:00
|
|
|
RUNC_DIR=build/src/github.com/opencontainers/runc
|
2021-04-08 22:33:15 +00:00
|
|
|
DATA_DIR=build/data
|
|
|
|
export TZ=UTC
|
2019-03-20 00:21:49 +00:00
|
|
|
|
2021-04-08 22:33:15 +00:00
|
|
|
umask 022
|
2021-05-17 20:30:55 +00:00
|
|
|
rm -rf ${CHARTS_DIR}
|
|
|
|
rm -rf ${RUNC_DIR}
|
2019-03-20 00:21:49 +00:00
|
|
|
mkdir -p ${CHARTS_DIR}
|
2021-04-08 22:33:15 +00:00
|
|
|
mkdir -p ${DATA_DIR}
|
2019-03-20 00:21:49 +00:00
|
|
|
|
2020-12-01 07:16:38 +00:00
|
|
|
curl --compressed -sfL https://github.com/k3s-io/k3s-root/releases/download/${ROOT_VERSION}/k3s-root-${ARCH}.tar | tar xf -
|
2019-03-20 00:21:49 +00:00
|
|
|
|
2021-05-17 20:30:55 +00:00
|
|
|
git clone --depth=1 https://github.com/opencontainers/runc ${RUNC_DIR} || true
|
|
|
|
pushd ${RUNC_DIR}
|
2021-05-12 18:50:24 +00:00
|
|
|
git fetch --all --tags
|
|
|
|
git checkout ${RUNC_VERSION} -b k3s
|
|
|
|
popd
|
|
|
|
|
2020-12-23 01:28:19 +00:00
|
|
|
setup_tmp() {
|
|
|
|
TMP_DIR=$(mktemp -d --tmpdir=${CHARTS_DIR})
|
|
|
|
cleanup() {
|
|
|
|
code=$?
|
|
|
|
set +e
|
|
|
|
trap - EXIT
|
|
|
|
rm -rf ${TMP_DIR}
|
|
|
|
exit $code
|
|
|
|
}
|
|
|
|
trap cleanup INT EXIT
|
|
|
|
}
|
|
|
|
|
|
|
|
download_and_package_traefik () {
|
|
|
|
echo "Downloading Traefik Helm chart from ${TRAEFIK_URL}"
|
|
|
|
curl -sfL ${TRAEFIK_URL} -o ${TMP_DIR}/${TRAEFIK_FILE}
|
|
|
|
code=$?
|
|
|
|
|
|
|
|
if [ $code -ne 0 ]; then
|
|
|
|
echo "Error: Failed to download Traefik Helm chart!"
|
|
|
|
exit $code
|
|
|
|
fi
|
|
|
|
|
|
|
|
echo "Uncompress ${TMP_DIR}/${TRAEFIK_FILE}"
|
|
|
|
tar xf ${TMP_DIR}/${TRAEFIK_FILE} -C ${TMP_DIR}
|
|
|
|
|
|
|
|
echo "Prepare traefik CRD"
|
|
|
|
TRAEFIK_TMP_CHART=${TMP_DIR}/traefik
|
|
|
|
TRAEFIK_TMP_CRD=${TRAEFIK_TMP_CHART}-crd
|
|
|
|
|
|
|
|
# Collect information on chart
|
2021-04-08 22:33:15 +00:00
|
|
|
name=$(yq e '.name' ${TRAEFIK_TMP_CHART}/Chart.yaml)
|
|
|
|
api_version=$(yq e '.apiVersion' ${TRAEFIK_TMP_CHART}/Chart.yaml)
|
|
|
|
chart_version=$(yq e '.version' ${TRAEFIK_TMP_CHART}/Chart.yaml)
|
2020-12-23 01:28:19 +00:00
|
|
|
|
|
|
|
# Collect information on CRDs
|
|
|
|
crd_apis=()
|
2021-04-08 22:33:15 +00:00
|
|
|
for crd_yaml in $(find ${TRAEFIK_TMP_CHART}/crds -type f | sort); do
|
|
|
|
echo "Processing CRD at ${crd_yaml}"
|
|
|
|
crd_group=$(yq e '.spec.group' ${crd_yaml})
|
|
|
|
crd_kind=$(yq e '.spec.names.kind' ${crd_yaml})
|
|
|
|
crd_version=$(yq e '.spec.version' ${crd_yaml})
|
2021-07-03 09:03:50 +00:00
|
|
|
if [[ -z "$crd_version" ]] || [[ "$crd_version" == "null" ]]; then
|
2021-04-08 22:33:15 +00:00
|
|
|
crd_version=$(yq e '.spec.versions[0].name' ${crd_yaml})
|
2020-12-23 01:28:19 +00:00
|
|
|
fi
|
2021-07-03 09:03:50 +00:00
|
|
|
echo "Found CRD with GVK ${crd_group}/${crd_version}/${crd_kind}"
|
2020-12-23 01:28:19 +00:00
|
|
|
crd_apis+=("${crd_group}/${crd_version}/${crd_kind}")
|
|
|
|
done
|
2020-12-21 23:55:13 +00:00
|
|
|
|
2020-12-23 01:28:19 +00:00
|
|
|
set_found_crd=$(
|
|
|
|
for crd in ${crd_apis[@]}; do
|
|
|
|
echo "# {{- set \$found \"${crd}\" false -}}"
|
|
|
|
done
|
|
|
|
)
|
|
|
|
|
|
|
|
# Copy base template and apply variables to the template
|
|
|
|
mkdir -p ${TRAEFIK_TMP_CRD}
|
|
|
|
cp -R ./scripts/chart-templates/crd-base/* ${TRAEFIK_TMP_CRD}
|
2021-04-08 22:33:15 +00:00
|
|
|
for template_file in $(find ${TRAEFIK_TMP_CRD} -type f | sort); do
|
2020-12-23 01:28:19 +00:00
|
|
|
# Applies any environment variables currently set onto your template file
|
2021-04-08 22:33:15 +00:00
|
|
|
echo "Templating ${template_file}"
|
2020-12-23 01:28:19 +00:00
|
|
|
eval "echo \"$(sed 's/"/\\"/g' ${template_file})\"" > ${template_file}
|
|
|
|
done
|
|
|
|
|
|
|
|
# Move anything from ${f}/charts-crd/overlay-upstream to the main chart
|
|
|
|
cp -R ${TRAEFIK_TMP_CRD}/overlay-upstream/* ${TRAEFIK_TMP_CHART}
|
|
|
|
rm -rf ${TRAEFIK_TMP_CRD}/overlay-upstream
|
|
|
|
|
2021-05-10 22:58:41 +00:00
|
|
|
# Modify charts to support system-default-registry
|
|
|
|
echo -e 'global:\n systemDefaultRegistry: ""' >> ${TRAEFIK_TMP_CHART}/values.yaml
|
|
|
|
find ${TRAEFIK_TMP_CHART} -type f | xargs sed -i 's/{{ .Values.image.name }}/{{ template "system_default_registry" .}}&/g'
|
|
|
|
|
2020-12-23 01:28:19 +00:00
|
|
|
# Move CRDs from main chart to CRD chart
|
|
|
|
mkdir -p ${TRAEFIK_TMP_CRD}/templates
|
|
|
|
mv ${TRAEFIK_TMP_CHART}/crds/* ${TRAEFIK_TMP_CRD}/templates
|
|
|
|
rm -rf ${TRAEFIK_TMP_CHART}/crds
|
|
|
|
|
|
|
|
# Package charts
|
2021-04-08 22:33:15 +00:00
|
|
|
OPTS="--format=gnu --sort=name --owner=0 --group=0 --mode=gou-s --numeric-owner --no-acls --no-selinux --no-xattrs"
|
|
|
|
tar ${OPTS} --mtime='2021-01-01 00:00:00Z' -cf - -C ${TMP_DIR} $(basename ${TRAEFIK_TMP_CHART}) | gzip -n > ${CHARTS_DIR}/${TRAEFIK_FILE}
|
|
|
|
tar ${OPTS} --mtime='2021-01-01 00:00:00Z' -cf - -C ${TMP_DIR} $(basename ${TRAEFIK_TMP_CRD}) | gzip -n > ${CHARTS_DIR}/${TRAEFIK_CRD_FILE}
|
|
|
|
for TAR in ${CHARTS_DIR}/${TRAEFIK_FILE} ${CHARTS_DIR}/${TRAEFIK_CRD_FILE}; do
|
|
|
|
sha256sum ${TAR}
|
|
|
|
stat ${TAR}
|
|
|
|
tar -vtf ${TAR}
|
|
|
|
done
|
2020-12-23 01:28:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
TRAEFIK_FILE=traefik-${TRAEFIK_VERSION}.tgz
|
|
|
|
TRAEFIK_CRD_FILE=traefik-crd-${TRAEFIK_VERSION}.tgz
|
|
|
|
TRAEFIK_URL=https://helm.traefik.io/traefik/${TRAEFIK_FILE}
|
2020-12-21 23:55:13 +00:00
|
|
|
|
2020-12-23 01:28:19 +00:00
|
|
|
setup_tmp
|
|
|
|
download_and_package_traefik
|
2019-09-03 23:41:54 +00:00
|
|
|
|
|
|
|
cp scripts/wg-add.sh bin/aux/
|