|
| 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