Skip to content
This repository has been archived by the owner on Mar 17, 2024. It is now read-only.

Add release steps to serve Helm Charts Repository on Github Pages #183

Merged
merged 2 commits into from
Jan 25, 2021
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
17 changes: 16 additions & 1 deletion build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -75,13 +75,15 @@ lazy val kafkaLagExporter =
updateHelmChartRelease, // Update the Helm Chart
publishDockerImage, // Publish the Docker images used by the chart
packageChart, // Package the Helm Chart
buildChartsIndex, // Build Helm Charts index
packageJavaApp, // Package the standalone Java App
commitReleaseVersion,
updateReadmeRelease, // Update the README.md with this version
commitReadmeVersion, // Commit the README.md
commitChartThisVersion, // Commit the Helm Chart
tagRelease,
githubReleaseDraft, // Create a GitHub release draft
publishChartsIndex, // Publish Helm Charts index
setNextVersion,
updateHelmChartNextVersion, // Update the Helm Chart with the next snapshot version
commitChartNextVersion, // Commit the Helm Chart
Expand Down Expand Up @@ -191,10 +193,23 @@ lazy val packageChart = ReleaseStep(action = st => {
st
})

lazy val buildChartsIndex = ReleaseStep(action = st => {
val (releaseVersion, _) = st.get(versions).getOrElse(sys.error("No versions are set! Was this release part executed before inquireVersions?"))
exec(
s"./scripts/build_charts_index.sh https://github.com/lightbend/kafka-lag-exporter/releases/download/v$releaseVersion/ https://lightbend.github.io/kafka-lag-exporter/index.yaml",
"Error while building Helm Charts index")
st
})

lazy val publishChartsIndex = ReleaseStep(action = st => {
exec("./scripts/publish_charts_index.sh", "Error while publishing Helm Charts index")
st
})

lazy val githubReleaseDraft = ReleaseStep(action = st => {
val (releaseVersion, _) = st.get(versions).getOrElse(sys.error("No versions are set! Was this release part executed before inquireVersions?"))
exec(
s"./scripts/github_release.sh lightbend/kafka-lag-exporter v$releaseVersion -- kafka-lag-exporter-$releaseVersion.tgz ./target/universal/kafka-lag-exporter-$releaseVersion.zip",
s"./scripts/github_release.sh lightbend/kafka-lag-exporter v$releaseVersion -- .helm-release-packages/kafka-lag-exporter-$releaseVersion.tgz ./target/universal/kafka-lag-exporter-$releaseVersion.zip",
"Error while publishing GitHub release draft")
st
})
Expand Down
24 changes: 24 additions & 0 deletions scripts/build_charts_index.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
#!/usr/bin/env bash

set -e

DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null && pwd )"

cd $DIR/..

REMOTE_URL_BASE=$1
REMOTE_INDEX_URL=$2
CHARTS_DIR=".helm-release-packages"

EXISTING_INDEX=$(mktemp /tmp/index.yaml.XXXXXX)

REMOTE_CODE=$(curl -s -L -w "%{http_code}" $REMOTE_INDEX_URL -o $EXISTING_INDEX)
if [ $REMOTE_CODE -eq 200 ]; then
echo Adding new packages to existing index
helm repo index --merge $EXISTING_INDEX --url $REMOTE_URL_BASE CHARTS_DIR
else
echo Creating new index
helm repo index --url $REMOTE_URL_BASE $CHARTS_DIR
fi

rm "${EXISTING_INDEX}"
9 changes: 6 additions & 3 deletions scripts/package_chart.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,11 @@ DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null && pwd )"

cd $DIR/..

CHARTS_DIR=".helm-release-packages"

# Bundle Kafka Lag Exporter Helm Chart into a tarball artifact. The `helm package` command will output the artifact
# in the CWD it is executed from.
# in the CHARTS_DIR.
echo Package helm chart
rm -f ./kafka-lag-exporter-*.tgz
helm package ./charts/kafka-lag-exporter
mkdir -p $CHARTS_DIR
rm -f $CHARTS_DIR/kafka-lag-exporter-*.tgz
helm package ./charts/kafka-lag-exporter -d $CHARTS_DIR
67 changes: 67 additions & 0 deletions scripts/publish_charts_index.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
#!/usr/bin/env bash

set -e

DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null && pwd )"

cd $DIR/..

CHARTS_DIR=".helm-release-packages"
GITHUB_PAGES_BRANCH="gh-pages"

function pages_branch_missing() {
local existed_in_remote=$(git ls-remote --heads origin $GITHUB_PAGES_BRANCH)

[ -z "${existed_in_remote}" ]
}

function create_pages_branch() {
echo "Creating pages branch ${GITHUB_PAGES_BRANCH}"
git checkout --quiet --orphan $GITHUB_PAGES_BRANCH
git rm --quiet -rf .
git commit --quiet --allow-empty -m "Pages initial commit"
git push --quiet origin HEAD:refs/heads/$GITHUB_PAGES_BRANCH
git checkout --detach --quiet
git branch --quiet -d $GITHUB_PAGES_BRANCH
}

function add_pages_worktree() {
local worktree_dir=${1}

if pages_branch_missing; then
git worktree add --quiet --detach ${worktree_dir}
pushd ${worktree_dir} > /dev/null
create_pages_branch
popd > /dev/null
else
git worktree add --quiet ${worktree_dir} "origin/${GITHUB_PAGES_BRANCH}"
fi
}

function remove_pages_worktree() {
local worktree_dir=${1}
git worktree remove --force ${worktree_dir}
rm -rf ${worktree_dir}
}

function push_index() {
if [[ ! -f "${CHARTS_DIR}/index.yaml" ]]; then
return -1
fi

local worktree=$(mktemp -d /tmp/worktree.XXXXXX)
add_pages_worktree ${worktree}

cp ${CHARTS_DIR}/index.yaml ${worktree}/
pushd ${worktree} > /dev/null
git add index.yaml
git commit --quiet --message "Update index.yaml"
git push --quiet origin HEAD:refs/heads/$GITHUB_PAGES_BRANCH
popd > /dev/null

remove_pages_worktree ${worktree}
}

push_index