Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion DEVELOPMENT.md
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ export SERVICE_ACCOUNT_ROLE_ARN=$(eksctl get iamserviceaccount \
```sh
export KO_DOCKER_REPO=$(./scripts/get-cfn-stack-output.sh "${DEV_INFRASTRUCTURE_STACK_NAME}" RepositoryBaseURI)

./scripts/docker-login-ecr.sh
make ecr-login
```

## 6. Build and deploy controller to EKS cluster
Expand Down
27 changes: 22 additions & 5 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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`^
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Elegant solution! This assumes that HEAD is the location of the release tag, which is the same assumption that GitHub will make about where to cut the release, so I like it.


.PHONY: repo-full-name
repo-full-name: ## Get the full name of the GitHub repository for Node Termination Handler.
Expand All @@ -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.
55 changes: 52 additions & 3 deletions scripts/docker-login-ecr.sh
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}"
95 changes: 95 additions & 0 deletions scripts/sync-readme-to-ecr-public.sh
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"