Skip to content

Commit

Permalink
Refactor chart scripts
Browse files Browse the repository at this point in the history
  • Loading branch information
mallardduck committed Oct 6, 2024
1 parent a6b1753 commit 9367ce3
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 18 deletions.
16 changes: 12 additions & 4 deletions scripts/build-chart
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,20 @@ if [[ "${BUILD_TARGET}" != "helm-project-operator" ]]; then
fi

source $(dirname $0)/version
source $(dirname $0)/util-chart

cd $(dirname $0)/..

CHART=${CHART:-"project-operator-example"}
VERSION=0.0.0

helm package charts/${CHART} --destination bin/${CHART}
base64 -i bin/${CHART}/${CHART}-${VERSION}.tgz > cmd/${BUILD_TARGET}/fs/${CHART}.tgz.base64
rm bin/${CHART}/${CHART}-${VERSION}.tgz
# Prepare base chart for build
rm -rf build/charts
mkdir -p build/charts dist/artifacts
cp -rf "charts/${CHART}" build/charts/

# Update the chart placeholders
edit-charts "build/charts/${CHART}/Chart.yaml" "${HELM_CHART_VERSION}" "${HELM_IMAGE_TAG}"
package-charts "./build/charts/${CHART}" ./dist/charts

# Prepare chart for embedding location
base64 -i "./dist/charts/${CHART}-${HELM_CHART_VERSION}.tgz" > "cmd/${BUILD_TARGET}/fs/${CHART}.tgz.base64"
18 changes: 4 additions & 14 deletions scripts/package-helm
Original file line number Diff line number Diff line change
@@ -1,29 +1,19 @@
#!/bin/bash
set -e

function edit-charts() {
sed -i \
-e 's/^version:.*/version: '${1}'/' \
-e 's/^appVersion:.*/appVersion: '${2}'/' \
build/charts/helm-project-operator/Chart.yaml
}

function package-charts() {
helm package --debug -d ./dist/artifacts ./build/charts/helm-project-operator
}

if ! hash helm 2>/dev/null; then
echo "Helm is not installed"
exit 1
fi

cd $(dirname $0)/..
cd "$(dirname $0)/.."
source ./scripts/version
source ./scripts/util-chart

rm -rf build/charts
mkdir -p build/charts dist/artifacts
cp -rf charts/helm-project-operator build/charts/

edit-charts "${HELM_CHART_VERSION}" "${HELM_IMAGE_TAG}"
edit-charts build/charts/helm-project-operator/Chart.yaml "${HELM_CHART_VERSION}" "${HELM_IMAGE_TAG}"
cp -a ./build/charts/helm-project-operator/ ./dist/chart
package-charts
package-charts
12 changes: 12 additions & 0 deletions scripts/util-chart
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#!/bin/bash

function edit-charts() {
sed -i \
-e 's/^version:.*/version: '${2}'/' \
-e 's/^appVersion:.*/appVersion: '${3}'/' \
"${1}"
}

function package-charts() {
helm package --debug "${1:-"./build/charts/helm-project-operator"}" -d "${2:-"./dist/artifacts"}"
}

0 comments on commit 9367ce3

Please sign in to comment.