Skip to content

Commit

Permalink
chore: Script to publish Helm charts (#675)
Browse files Browse the repository at this point in the history
* Create helm_push.sh

Adding scripts to push helm charts to ECR

* Tidying up

* Publish charts with release

---------

Co-authored-by: Niall Thomson <[email protected]>
  • Loading branch information
imtrahman and niallthomson authored Nov 22, 2024
1 parent 5f1e72a commit 391ec2f
Show file tree
Hide file tree
Showing 2 changed files with 88 additions and 0 deletions.
7 changes: 7 additions & 0 deletions .github/workflows/publish-build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,13 @@ jobs:
# Push all images
scripts/build-image.sh -r 'public.ecr.aws/aws-containers' -t $TAG --multi-arch -p
- name: Push Helm Charts
env:
TAG: "${{ github.event.inputs.tag }}"
run: |
# Push all charts
scripts/push-charts.sh -r 'public.ecr.aws/aws-containers'
release:
name: Release
needs: [tag, images]
Expand Down
81 changes: 81 additions & 0 deletions scripts/helm_push.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
#!/usr/bin/env bash

set -Eeuo pipefail

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

CHARTS_DIR="$script_dir/../deploy/kubernetes/charts"

usage() {
cat <<EOF
Usage: $(basename "${BASH_SOURCE[0]}") [-h] [-a] [-s service] [-r repository] [-t tag]
Push helm charts to ECR for one or more services.
Available options:
-h, --help Print this help and exit
-r, --repository Repository name to push the charts to
EOF
exit
}

parse_params() {
# default values of variables set from params
repository='public.ecr.aws/aws-containers'
while :; do
case "${1-}" in
-h | --help) usage ;;
-r | --repository)
repository="${2-}"
shift
;;
-?*) die "Unknown option: $1" ;;
*) break ;;
esac
shift
done

args=("$@")

# check required params and arguments
return 0
}

parse_params "$@"

# Function to publish Helm chart to ECR
publish_chart() {
local chart_dir=$1

local chart_name=$(yq '.name' $chart_dir/Chart.yaml)
local chart_version=$(yq '.version' $chart_dir/Chart.yaml)

echo "Publishing chart: $chart_name"

helm dependency build $chart_dir

# Package the Helm chart
helm package "$chart_dir" --destination /tmp/

# Push the Helm chart to ECR
helm push /tmp/${chart_name}-${chart_version}.tgz "oci://${repository}/"

# Clean up the packaged chart file
rm /tmp/${chart_name}-${chart_version}.tgz
}

# Main script execution
main() {
aws ecr-public get-login-password --region us-east-1 | helm registry login --username AWS --password-stdin "${repository}"

# Recursively find and process Helm charts
find "$CHARTS_DIR" -name Chart.yaml -not -path "*/opentelemetry/*" -exec dirname {} \; | sort -z | while read -r chart_dir; do
publish_chart "$chart_dir"
done
}

# Run the main function
main

echo "All charts have been published to $repository"

0 comments on commit 391ec2f

Please sign in to comment.