-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: added feature to upload chart to ECR (#239)
* feat: added feature to upload chart to ECR * fixed wrong file name * refactored script for pushing to ECR to use the correct helm command * added oci protocol to the shell command * add prepublish step to publick chart ecr helm job * fixed multiple execution in the helm publish chart ecr job
- Loading branch information
Showing
4 changed files
with
130 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
executor: build-executor | ||
parameters: | ||
chart_directory: | ||
description: Directory containining charts | ||
type: string | ||
default: . | ||
charts: | ||
description: List of charts to publish | ||
type: string | ||
default: "" | ||
prepublish_steps: | ||
description: Steps to run on repo before publishing charts | ||
type: steps | ||
default: [] | ||
steps: | ||
- checkout_shallow_clone | ||
- steps: << parameters.prepublish_steps >> | ||
- helm-add-repos | ||
- run: | ||
name: Package and publish charts | ||
working_directory: << parameters.chart_directory >> | ||
command: <<include(scripts/helm/package-publish-charts-ecr.sh)>> | ||
environment: | ||
CHARTS: << parameters.charts >> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
executor: build-executor | ||
parameters: | ||
working_directory: | ||
description: Directory containing chart directories | ||
type: string | ||
default: "./" | ||
prepublish_steps: | ||
description: Steps to run on repo before publishing charts | ||
type: steps | ||
default: [] | ||
steps: | ||
- checkout_shallow_clone | ||
- set-beta-version: | ||
working_directory: << parameters.working_directory >> | ||
- steps: << parameters.prepublish_steps >> | ||
- helm-add-repos | ||
- run: | ||
name: Package and publish charts | ||
working_directory: << parameters.working_directory >> | ||
command: <<include(scripts/helm/publish-prerelease-ecr.sh)>> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
#!/bin/bash | ||
|
||
# Expected environment variables: | ||
echo "CHARTS: ${CHARTS?}" | ||
echo "AWS_REGION: ${AWS_REGION?}" | ||
|
||
# Set a default value for ECR_REPOSITORY_URI if not set | ||
ECR_REPOSITORY_URI=${ECR_REPOSITORY_URI:-"168387678261.dkr.ecr.us-east-1.amazonaws.com"} | ||
|
||
echo "ECR_REPOSITORY_URI: ${ECR_REPOSITORY_URI}" | ||
|
||
# Enable experimental OCI support in Helm | ||
export HELM_EXPERIMENTAL_OCI=1 | ||
|
||
# Login to ECR | ||
aws ecr get-login-password --region "$AWS_REGION" | helm registry login --username AWS --password-stdin "$ECR_REPOSITORY_URI" | ||
|
||
for chart in ${CHARTS?}; do | ||
echo "Packaging $chart" | ||
|
||
# Create a temporary directory to store the packaged chart | ||
dist="$(mktemp -d)" | ||
|
||
helm dep update "$chart/$chart" | ||
helm package "$chart/$chart" --destination "$dist" | ||
|
||
# Get the chart version from the packaged chart | ||
packaged_chart="$(ls "$dist")" | ||
chart_version=$(helm show chart "$dist/$packaged_chart" | yq --raw-output '.version') | ||
channel=$(helm show chart "$chart/$chart" | yq --raw-output '.annotations."release-repository"') | ||
echo "Publishing in $channel channel" | ||
|
||
repo="voiceflow-charts-private" | ||
if [[ "$channel" == "public" ]]; then | ||
repo="voiceflow-charts-public" | ||
fi | ||
|
||
# Construct the full ECR URL with the OCI protocol | ||
FULL_ECR_URL="oci://$ECR_REPOSITORY_URI/$repo/$chart:$chart_version" | ||
|
||
# Push the chart to ECR using the OCI protocol | ||
helm push "$dist/$packaged_chart" "$FULL_ECR_URL" | ||
|
||
rm -rf "$dist" | ||
done |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
#!/bin/bash | ||
|
||
# Expected environment variables: | ||
echo "BETA_VERSION: ${BETA_VERSION:?}" | ||
echo "AWS_REGION: ${AWS_REGION:?}" | ||
|
||
# Set a default value for ECR_REPOSITORY_URI if not set | ||
ECR_REPOSITORY_URI=${ECR_REPOSITORY_URI:-"168387678261.dkr.ecr.us-east-1.amazonaws.com"} | ||
|
||
echo "ECR_REPOSITORY_URI: ${ECR_REPOSITORY_URI}" | ||
|
||
# Enable experimental OCI support in Helm | ||
export HELM_EXPERIMENTAL_OCI=1 | ||
|
||
# Login to ECR | ||
aws ecr get-login-password --region "$AWS_REGION" | helm registry login --username AWS --password-stdin "$ECR_REPOSITORY_URI" | ||
|
||
# Publishes beta releases for helm charts in subdirectories of working directory | ||
for file in * ; do | ||
if [[ -d "$file" && -f "$file/$file/Chart.yaml" ]]; then | ||
echo "Packaging $file" | ||
cd "$file" || exit | ||
helm dep update "$file" | ||
|
||
echo "Packaging version $BETA_VERSION" | ||
helm package "$file" --version "$BETA_VERSION" | ||
|
||
echo "Publishing beta release" | ||
CHART="$file-$BETA_VERSION.tgz" | ||
|
||
if [ ! -f "$CHART" ]; then | ||
echo "Packaged chart does not have expected name $CHART. Does the name in Chart.yaml match the directory name?" | ||
exit 3 | ||
fi | ||
|
||
# Push the chart to ECR | ||
helm push "$CHART" "oci://$ECR_REPOSITORY_URI/voiceflow-charts-beta" | ||
|
||
cd .. | ||
fi | ||
done |