generated from amazon-archives/__template_Apache-2.0
-
Notifications
You must be signed in to change notification settings - Fork 278
add sync-readme-to-ecr-public.sh script #698
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 1 commit
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next
Next commit
add sync-readme-to-ecr-public.sh script
- Loading branch information
commit 890f7b0f0282f5ec0512c259c8042bdb42362a1f
There are no files selected for viewing
This file contains hidden or 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
This file contains hidden or 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 |
|---|---|---|
| @@ -1,8 +1,57 @@ | ||
| #!/usr/bin/env bash | ||
|
|
||
| aws ecr get-login-password \ | ||
| --region "${AWS_REGION:?AWS_REGION is undefined or empty}" | \ | ||
| set -euo pipefail | ||
|
|
||
| aws_region="${AWS_REGION:-}" | ||
| ecr_repository="${KO_DOCKER_REPO:-}" | ||
|
|
||
| usage=$(cat << EOM | ||
| usage: $(basename $0) -h | [-g REGION] [-p] [-r REPOSITORY] | ||
|
|
||
| Login to an AWS ECR repository. | ||
|
|
||
| Options: | ||
| -h Display this help message then exit. | ||
| -g REGION AWS Region. Defaults to "${aws_region}". | ||
| -r REPOSITORY ECR Registry. Defaults to "${ecr_repository}". | ||
|
|
||
| EOM | ||
| ) | ||
|
|
||
| while getopts "g:r:h" opt; do | ||
| case "${opt}" in | ||
| g ) aws_region="${OPTARG}" | ||
| ;; | ||
| r ) ecr_repository="${OPTARG}" | ||
| ;; | ||
| h ) echo "${usage}" | ||
| exit 0 | ||
| ;; | ||
| \?) echo "${usage}" >&2 | ||
| exit 1 | ||
| ;; | ||
| esac | ||
| done | ||
|
|
||
| function assert_not_empty { | ||
| if [[ -z "${!1}" ]]; then | ||
| echo "error: missing argument ${1}" >&2 | ||
| echo "${usage}" >&2 | ||
| exit 1 | ||
| fi | ||
| } | ||
|
|
||
| assert_not_empty aws_region | ||
| assert_not_empty ecr_repository | ||
|
|
||
| ecr_cmd="ecr" | ||
| if echo "${ecr_repository}" | grep '^public\.ecr\.aws' >/dev/null; then | ||
| ecr_cmd="ecr-public" | ||
| fi | ||
|
|
||
| aws ${ecr_cmd} get-login-password \ | ||
| --region "${aws_region}" | \ | ||
| docker login \ | ||
| --username AWS \ | ||
| --password-stdin \ | ||
| "${KO_DOCKER_REPO:?KO_DOCKER_REPO is undefined or empty}" | ||
| "${ecr_repository}" |
This file contains hidden or 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,91 @@ | ||
| #!/usr/bin/env bash | ||
|
|
||
| set -euo pipefail | ||
|
|
||
| repo_root_path="$(cd "$(dirname "$0")"; cd ..; pwd -P)" | ||
|
|
||
| if ! command -v jq; then | ||
| echo "command not found: jq" >&2 | ||
| exit 1 | ||
| fi | ||
|
|
||
| region="${AWS_REGION:-us-east-1}" | ||
| repo_root="${KO_DOCKER_REPO}" | ||
| version="$(make -s -f "${makefile_path}" version)" | ||
|
|
||
| usage=$(cat << EOM | ||
| usage: $(basename $0) -h | [-g REGION] [-r REPOSITORY] [-v VERSION] | ||
| Upload the README.md to the AWS ECR controller and webhook repositories. | ||
| Options: | ||
| -h Display this help message then exit. | ||
| -g REGION AWS Region of ECR image repository. Defaults to "${region}". | ||
| -r REPOSITORY Image repository to push the built images. Defaults to "${repo_root}". | ||
| -v VERSION Node Termination Handler version. Defaults to "${version}". | ||
| EOM | ||
| ) | ||
|
|
||
| while getopts "r:h" opt; do | ||
| case "${opt}" in | ||
| g ) region="${OPTARG}" | ||
| ;; | ||
| r ) repo_root="${OPTARG}" | ||
| ;; | ||
| v ) version="${OPTARG}" | ||
| ;; | ||
| h ) echo "${usage}" | ||
| exit 0 | ||
| ;; | ||
| \?) echo "${usage}" >&2 | ||
| exit 1 | ||
| ;; | ||
| esac | ||
| done | ||
|
|
||
| assert_not_empty() { | ||
| if [[ -z "${!1}" ]]; then | ||
| echo "error: missing argument ${1}" >&2 | ||
| echo "${usage}" >&2 | ||
| exit 1 | ||
| fi | ||
| } | ||
|
|
||
| assert_not_empty region | ||
| assert_not_empty repo_root | ||
| assert_not_empty version | ||
|
|
||
| ################################################# | ||
|
|
||
| if ! (git --no-pager diff --name-only HEAD^ HEAD | grep 'README.md' >/dev/null); then | ||
cjerad marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| echo -e "⚠️ README.md did not change in the last commit. Not taking any action." | ||
| exit 0 | ||
| fi | ||
|
|
||
| ################################################# | ||
|
|
||
| content=$(jq -n --arg msg "$(cat README.md)" '{"usageText": $msg}' | jq '.usageText' | sed 's/\\n/\ | ||
| /g') | ||
| if [[ ${#content} -gt 10240 ]]; then | ||
| truncation_msg="... | ||
| **truncated due to char limits**... | ||
| A complete version of the README can be found [here](https://github.com/aws/aws-node-termination-handler/blob/${version}/README.md).\"" | ||
| content="${content:0:$((10240-${#truncation_msg}))}" | ||
| content+="${truncation_msg}" | ||
| fi | ||
|
|
||
| for repo in "controller" "webhook"; do | ||
| if ! aws ecr-public put-repository-catalog-data \ | ||
| --region "${region}" \ | ||
| --repository-name="${repo_root}/${repo}" \ | ||
| --catalog-data aboutText="${content}",usageText="See About section" >/dev/null 2>&1; then | ||
| echo -e "❌ Failed to upload README.md to ${repo_root}/${repo}" >&2 | ||
| exit 1 | ||
| fi | ||
|
|
||
| echo -e "✅ Uploaded README.md to 'About' section of ${repo_root}/${repo}" | ||
| done | ||
|
|
||
| echo -e "✅ Finished sync'ing README.md to ECR Public" | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.