Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
move tool download to script
  • Loading branch information
cjerad committed Feb 17, 2022
commit e0e0628d1a65faf18e1835bcad67a2462edbba86
2 changes: 1 addition & 1 deletion BUILD.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ git clone --branch v2 https://github.com/aws/aws-node-termination-handler.git
Install build tools

```sh
make controller-gen ko envtest
make toolchain
```

Configure image repository location
Expand Down
46 changes: 13 additions & 33 deletions src/Makefile
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
PROJECT_DIR := $(shell dirname $(abspath $(lastword $(MAKEFILE_LIST))))
CONTROLLER_GEN = $(PROJECT_DIR)/bin/controller-gen
KO = $(PROJECT_DIR)/bin/ko
ENVTEST = $(PROJECT_DIR)/bin/setup-envtest


# Image URL to use all building/pushing image targets
IMG ?= controller:latest
Expand Down Expand Up @@ -34,22 +39,26 @@ SHELL = /usr/bin/env bash -o pipefail
help: ## Display this help.
@awk 'BEGIN {FS = ":.*##"; printf "\nUsage:\n make \033[36m<target>\033[0m\n"} /^[a-zA-Z_0-9-]+:.*?##/ { printf " \033[36m%-15s\033[0m %s\n", $$1, $$2 } /^##@/ { printf "\n\033[1m%s\033[0m\n", substr($$0, 5) } ' $(MAKEFILE_LIST)

.PHONY: toolchain
toolchain: # Download additional tools.
@./scripts/toolchain.sh -d "$(PROJECT_DIR)/bin"

##@ Development

.PHONY: manifests
manifests: controller-gen ## Generate WebhookConfiguration, ClusterRole and CustomResourceDefinition objects.
manifests: # Generate WebhookConfiguration, ClusterRole and CustomResourceDefinition objects.
$(CONTROLLER_GEN) rbac:roleName=manager-role crd webhook paths="./..." output:crd:artifacts:config=config/crd/bases

.PHONY: generate
generate: controller-gen ## Generate code containing DeepCopy, DeepCopyInto, and DeepCopyObject method implementations.
generate: # Generate code containing DeepCopy, DeepCopyInto, and DeepCopyObject method implementations.
$(CONTROLLER_GEN) object:headerFile="hack/boilerplate.go.txt" paths="./..."

.PHONY: fmt
fmt: ## Run go fmt against code.
fmt: # Run go fmt against code.
go fmt ./...

.PHONY: vet
vet: ## Run go vet against code.
vet: # Run go vet against code.
go vet ./...

.PHONY: test
Expand All @@ -74,32 +83,3 @@ apply: # Deploy the controller into the current kubernetes cluster.
.PHONY: delete
delete: # Delete controller from current kubernetes cluster.
helm uninstall dev --namespace nthv2

CONTROLLER_GEN = $(shell pwd)/bin/controller-gen
.PHONY: controller-gen
controller-gen: ## Download controller-gen locally if necessary.
$(call go-get-tool,$(CONTROLLER_GEN),sigs.k8s.io/controller-tools/cmd/[email protected])

KO = $(shell pwd)/bin/ko
.PHONY: ko
ko: ## Download ko locally if necessary.
$(call go-get-tool,$(KO),github.com/google/[email protected])

ENVTEST = $(shell pwd)/bin/setup-envtest
.PHONY: envtest
envtest: ## Download envtest-setup locally if necessary.
$(call go-get-tool,$(ENVTEST),sigs.k8s.io/controller-runtime/tools/[email protected])

# go-get-tool will 'go get' any package $2 and install it to $1.
PROJECT_DIR := $(shell dirname $(abspath $(lastword $(MAKEFILE_LIST))))
define go-get-tool
@[ -f $(1) ] || { \
set -e ;\
TMP_DIR=$$(mktemp -d) ;\
cd $$TMP_DIR ;\
go mod init tmp ;\
echo "Downloading $(2)" ;\
GOBIN=$(PROJECT_DIR)/bin go get $(2) ;\
rm -rf $$TMP_DIR ;\
}
endef
52 changes: 52 additions & 0 deletions src/scripts/toolchain.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
#!/usr/bin/env bash

set -euo pipefail

usage=$(cat << EOM
usage: $(basename "$0") -h | -d PATH
Download tools to PATH.
Arguments:
-h Print usage message then exit.
-d PATH Destination directory for downloaded tools.
EOM
)

tools=(
"github.com/google/[email protected]"
"sigs.k8s.io/controller-tools/cmd/[email protected]"
# setup-envtest version specifiers:
# https://pkg.go.dev/sigs.k8s.io/controller-runtime/tools/setup-envtest/versions?tab=versions
"sigs.k8s.io/controller-runtime/tools/[email protected]"
)

bin_dir=""

while getopts "d:h" opt; do
case $opt in
d ) bin_dir="$OPTARG"
;;
* ) echo "$usage" 1>&2
exit 1
;;
esac
done

if [[ -z "$bin_dir" ]]; then
echo "error: missing destination path"
echo "$usage" 1>&2
exit 1
fi

tmp_dir="$(mktemp -d)"
trap "rm -rf \"$tmp_dir\"" EXIT

cd "$tmp_dir"
go mod init tmp >/dev/null 2>&1

for tool in ${tools[@]}; do
echo "Downloading $tool"
GOBIN="$bin_dir" go install "$tool"
done