Created
September 27, 2021 09:42
-
-
Save zxkane/f548965c8d84871cd8f5eb4ceaaffbc9 to your computer and use it in GitHub Desktop.
push helm chart to all ecr regions
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
#!/bin/bash -xe | |
create_repo() { | |
local name=$1 | |
local region=$2 | |
# create ecr repo | |
aws ecr create-repository --region $region --repository-name "$name" --image-tag-mutability IMMUTABLE --image-scanning-configuration scanOnPush=true --encryption-configuration encryptionType=AES256 2>/dev/null | |
# set repo permission | |
read -r -d '' POLICY_TEXT << EOM | |
{ | |
"Version": "2008-10-17", | |
"Statement": [ | |
{ | |
"Sid": "public statement", | |
"Effect": "Allow", | |
"Principal": "*", | |
"Action": [ | |
"ecr:BatchCheckLayerAvailability", | |
"ecr:BatchGetImage", | |
"ecr:GetDownloadUrlForLayer" | |
] | |
} | |
] | |
} | |
EOM | |
aws ecr set-repository-policy --region $region --repository-name "$name" --policy-text "$POLICY_TEXT" 2>/dev/null | |
} | |
push_to_ecr() { | |
local name=$1 | |
local tag=$2 | |
local region=$3 | |
REGISTRYID=`aws ecr describe-repositories --region $region --repository-names $name --query 'repositories[].registryId' 2>/dev/null |jq -r '.[0]'` | |
REPO=`aws ecr describe-repositories --region $region --repository-names $name --query 'repositories[0].repositoryUri' --output text 2>/dev/null | sed -E 's/(.*\.amazonaws\.com(.cn)?).*/\1/'` | |
aws ecr get-login-password --region "$region" | helm registry login --username AWS --password-stdin $REPO | |
helm push "$name-$tag.tgz" "oci://$REPO/" | |
} | |
push_chart() { | |
local name=$1 | |
local tag=$2 | |
local region=$3 | |
EXISTINGREPO=`aws ecr describe-repositories --region $region --repository-names $name --query 'repositories[].repositoryName' 2>/dev/null|jq '.[]'|jq '.'` | |
if [[ -z $EXISTINGREPO ]] | |
then | |
create_repo "$name" "$region" | |
echo "The repo with name '$name' is created in region '$region'." | |
else | |
echo "The repo with name '$name' already exists in region '$region'." | |
fi | |
# push to ecr via docker | |
push_to_ecr "$name" "$tag" $region | |
} | |
CHARTNAME=$1 | |
CHARTTAG=$2 | |
if [[ -z $CHARTNAME ]] || [[ -z $CHARTTAG ]] | |
then | |
echo "pls specify CHARTNAME and CHARTTAG." | |
exit -1 | |
fi | |
export -f push_chart create_repo push_to_ecr | |
export HELM_EXPERIMENTAL_OCI=1 | |
aws ec2 describe-regions --query 'Regions[].RegionName' --output json | jq '.[]'|jq '.'|xargs -I {} -n 1 bash -c 'push_chart "$@"' _ "$CHARTNAME" "$CHARTTAG" {} |
HEllo i try to push argocd chart to my private repository. it's possible to do it with dependency ?
It's a case not covered. You have to push all dependencies manually, then update the repo of dependency.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
HEllo i try to push argocd chart to my private repository. it's possible to do it with dependency ?