Skip to content

Commit 25f28d4

Browse files
authored
add build-and-push-images.sh script (#693)
1 parent e9614ff commit 25f28d4

File tree

2 files changed

+79
-0
lines changed

2 files changed

+79
-0
lines changed

Makefile

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@ KODATA = \
1515
cmd/webhook/kodata/refs
1616
CODECOVERAGE_OUT = $(PROJECT_DIR)/coverprofile.out
1717
GITHUB_REPO_FULL_NAME = "aws/aws-node-termination-handler"
18+
ECR_PUBLIC_REGISTRY ?= "public.ecr.aws/aws-ec2"
19+
ECR_PUBLIC_REPOSITORY_ROOT = "aws-node-termination-handler-2"
1820

1921
# Image URL to use all building/pushing image targets
2022
IMG ?= controller:latest
@@ -125,6 +127,10 @@ delete: ## Delete controller from current kubernetes cluster.
125127

126128
##@ Release
127129

130+
.PHONY: build-and-push-images
131+
build-and-push-images: $(KO) $(KODATA) ## Build controller and webhook images and push to ECR public repository.
132+
@PATH="$(BIN_DIR):$(PATH)" $(PROJECT_DIR)/scripts/build-and-push-images.sh -r "$(ECR_PUBLIC_REGISTRY)/$(ECR_PUBLIC_REPOSITORY_ROOT)"
133+
128134
.PHONY: create-release-prep-pr
129135
create-release-prep-pr: $(GUM) ## Update version numbers in documents and open a PR.
130136
@PATH="$(BIN_DIR):$(PATH)" $(PROJECT_DIR)/scripts/prepare-for-release.sh
@@ -141,3 +147,5 @@ latest-release-tag: ## Get tag of most recent release.
141147
repo-full-name: ## Get the full name of the GitHub repository for Node Termination Handler.
142148
@echo "$(GITHUB_REPO_FULL_NAME)"
143149

150+
.PHONY: version
151+
version: latest-release-tag ## Get the most recent release version.

scripts/build-and-push-images.sh

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
#!/usr/bin/env bash
2+
3+
set -euo pipefail
4+
5+
repo_root_path="$(cd "$(dirname "$0")"; cd ..; pwd -P)"
6+
makefile_path="${repo_root_path}/Makefile"
7+
8+
if ! command -v ko >/dev/null; then
9+
echo "error: required executable 'ko' not found" >&2
10+
exit 1
11+
fi
12+
13+
version="$(make -s -f "${makefile_path}" version)"
14+
platforms="linux/amd64"
15+
image_repository="${KO_DOCKER_REPO}"
16+
goproxy="direct|https://proxy.golang.org"
17+
18+
usage=$(cat << EOM
19+
usage: $(basename $0) -h | [-p PLATFORMS] [-r REPOSITORY] [-v VERSION]
20+
21+
Build and push Docker images for each platform.
22+
23+
Optional:
24+
-h Display this help message then exit.
25+
-g GOPROXY See documentation in "go help environment". Defaults to "${goproxy}".
26+
-p PLATFORMS Comma separated list of OS and Arch identifiers, e.g. "linux/amd64,linux/arm64". Defaults to "${platforms}".
27+
-r REPOSITORY Image repository to push the built images. Defaults to "${image_repository}".
28+
-v VERSION Version to include in tag of docker image. Defaults "${version}".
29+
30+
EOM
31+
)
32+
33+
while getopts "g:p:r:v:h" opt; do
34+
case "${opt}" in
35+
g ) goproxy="${OPTARG}"
36+
;;
37+
p ) platforms="${OPTARG}"
38+
;;
39+
r ) image_repository="${OPTARG}"
40+
;;
41+
v ) version="${OPTARG}"
42+
;;
43+
h ) echo "${usage}"
44+
exit 0
45+
;;
46+
\?) echo "${usage}" >&2
47+
exit 1
48+
;;
49+
esac
50+
done
51+
52+
assert_not_empty() {
53+
if [[ -z "${!1}" ]]; then
54+
echo "error: missing argument ${1}" >&2
55+
echo "${usage}" >&2
56+
exit 1
57+
fi
58+
}
59+
60+
assert_not_empty goproxy
61+
assert_not_empty platforms
62+
assert_not_empty image_repository
63+
assert_not_empty version
64+
65+
for app in "controller" "webhook"; do
66+
GOPROXY="${goproxy}" KO_DOCKER_REPO="${image_repository}" ko publish \
67+
--base-import-paths \
68+
--tags "${version}" \
69+
--platform "${platforms}" \
70+
"github.com/aws/aws-node-termination-handler/cmd/${app}"
71+
done

0 commit comments

Comments
 (0)