generated from amazon-archives/__template_Apache-2.0
-
Notifications
You must be signed in to change notification settings - Fork 277
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 all commits
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
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 |
|---|---|---|
|
|
@@ -15,9 +15,10 @@ KODATA = \ | |
| cmd/webhook/kodata/HEAD \ | ||
| cmd/webhook/kodata/refs | ||
| CODECOVERAGE_OUT = $(PROJECT_DIR)/coverprofile.out | ||
| GITHUB_REPO_FULL_NAME = "aws/aws-node-termination-handler" | ||
| ECR_PUBLIC_REGISTRY ?= "public.ecr.aws/aws-ec2" | ||
| ECR_PUBLIC_REPOSITORY_ROOT = "aws-node-termination-handler-2" | ||
| GITHUB_REPO_FULL_NAME = aws/aws-node-termination-handler | ||
| ECR_PUBLIC_REGION = us-east-1 | ||
| ECR_PUBLIC_REGISTRY ?= public.ecr.aws/aws-ec2 | ||
| ECR_PUBLIC_REPOSITORY_ROOT = aws-node-termination-handler-2 | ||
|
|
||
| # Image URL to use all building/pushing image targets | ||
| IMG ?= controller:latest | ||
|
|
@@ -129,10 +130,14 @@ apply: $(KO) $(KODATA) ## Deploy the controller into the current kubernetes clus | |
| delete: ## Delete controller from current kubernetes cluster. | ||
| helm uninstall dev --namespace ${CLUSTER_NAMESPACE} | ||
|
|
||
| .PHONY: ecr-login | ||
| ecr-login: ## Login to default AWS ECR repository. | ||
| @$(PROJECT_DIR)/scripts/docker-login-ecr.sh | ||
|
|
||
| ##@ Release | ||
|
|
||
| .PHONY: build-and-push-images | ||
| build-and-push-images: $(KO) $(KODATA) ## Build controller and webhook images and push to ECR public repository. | ||
| build-and-push-images: $(KO) $(KODATA) ecr-public-login ## Build controller and webhook images and push to ECR public repository. | ||
| @PATH="$(BIN_DIR):$(PATH)" $(PROJECT_DIR)/scripts/build-and-push-images.sh -r "$(ECR_PUBLIC_REGISTRY)/$(ECR_PUBLIC_REPOSITORY_ROOT)" | ||
|
|
||
| .PHONY: create-release-prep-pr | ||
|
|
@@ -143,13 +148,21 @@ create-release-prep-pr: $(GUM) ## Update version numbers in documents and open a | |
| create-release-prep-pr-draft: $(GUM) ## Update version numbers in documents and open a draft PR. | ||
| @PATH="$(BIN_DIR):$(PATH)" $(PROJECT_DIR)/scripts/prepare-for-release.sh -d | ||
|
|
||
| .PHONY: ecr-public-login | ||
| ecr-public-login: ## Login to the AWS ECR public repository. | ||
| @$(PROJECT_DIR)/scripts/docker-login-ecr.sh -g "$(ECR_PUBLIC_REGION)" -r "$(ECR_PUBLIC_REGISTRY)/$(ECR_PUBLIC_REPOSITORY_ROOT)" | ||
|
|
||
| .PHONY: upload-resources-to-github | ||
| upload-resources-to-github: ## Upload contents of resources/ as part of the most recent published release. | ||
| @$(PROJECT_DIR)/scripts/upload-resources-to-github.sh | ||
|
|
||
| .PHONY: latest-release-tag | ||
| latest-release-tag: ## Get tag of most recent release. | ||
| @git describe --tags --abbrev=0 v2 | ||
| @git describe --tags --abbrev=0 `git rev-parse --abbrev-ref HEAD` | ||
|
|
||
| .PHONY: previous-release-tag | ||
| previous-release-tag: ## Get tag of second most recent release. | ||
| @git describe --tags --abbrev=0 `git rev-parse --abbrev-ref HEAD`^ | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Elegant solution! This assumes that |
||
|
|
||
| .PHONY: repo-full-name | ||
| repo-full-name: ## Get the full name of the GitHub repository for Node Termination Handler. | ||
|
|
@@ -159,5 +172,9 @@ repo-full-name: ## Get the full name of the GitHub repository for Node Terminati | |
| ekscharts-sync-release: $(GH) | ||
| @PATH="$(BIN_DIR):$(PATH)" $(PROJECT_DIR)/scripts/sync-to-aws-eks-charts.sh -n | ||
|
|
||
| .PHONY: sync-readme-to-ecr-public | ||
| sync-readme-to-ecr-public: ecr-public-login ## Upload the README.md to ECR public controller and webhook repositories. | ||
| @$(PROJECT_DIR)/scripts/sync-readme-to-ecr-public.sh -r "$(ECR_PUBLIC_REGISTRY)/$(ECR_PUBLIC_REPOSITORY_ROOT)" | ||
|
|
||
| .PHONY: version | ||
| version: latest-release-tag ## Get the most recent release version. | ||
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,95 @@ | ||
| #!/usr/bin/env bash | ||
|
|
||
| set -euo pipefail | ||
|
|
||
| repo_root_path="$(cd "$(dirname "$0")"; cd ..; pwd -P)" | ||
| makefile_path="${repo_root_path}/Makefile" | ||
|
|
||
| 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 | ||
|
|
||
| ################################################# | ||
|
|
||
| latest_release_tag="$(make -s -f "${makefile_path}" latest-release-tag)" | ||
| previous_release_tag="$(make -s -f "${makefile_path}" previous-release-tag)" | ||
|
|
||
| if ! (git --no-pager diff --name-only "${previous_release_tag}" "${latest_release_tag}" | grep 'README.md' >/dev/null); then | ||
| 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.