-
Notifications
You must be signed in to change notification settings - Fork 424
/
Makefile
182 lines (149 loc) · 5.08 KB
/
Makefile
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
default: bin/aws-iam-authenticator
PKG ?= sigs.k8s.io/aws-iam-authenticator
GORELEASER := $(shell command -v goreleaser 2> /dev/null)
VERSION ?= $(shell $(shell pwd)/hack/get-version.sh)
GOOS ?= $(shell go env GOOS)
GOARCH ?= $(shell go env GOARCH)
GOPROXY ?= $(shell go env GOPROXY)
GIT_COMMIT ?= $(shell git rev-parse HEAD)
BUILD_DATE ?= $(shell date -u +"%Y-%m-%dT%H:%M:%SZ")
BUILD_DATE_STRIPPED := $(subst -,,$(subst :,,$(BUILD_DATE)))
OUTPUT ?= $(shell pwd)/_output
CHECKSUM_FILE ?= $(OUTPUT)/bin/authenticator_$(VERSION)_checksums.txt
# Architectures for binary builds
BIN_ARCH_LINUX ?= amd64 arm64
BIN_ARCH_WINDOWS ?= amd64
BIN_ARCH_DARWIN ?= amd64 arm64
#CI is defined in test-infra https://github.com/kubernetes/test-infra/blob/2e3dd84399745eb49cef69afc3ed5bded8a6580c/prow/pod-utils/downwardapi/jobspec.go#L89
# and passed in when running on github prow
CI ?= false
RUNNER ?= kops
ALL_LINUX_BIN_TARGETS = $(foreach arch,$(BIN_ARCH_LINUX),$(OUTPUT)/bin/aws-iam-authenticator_$(VERSION)_linux_$(arch))
ALL_WINDOWS_BIN_TARGETS = $(foreach arch,$(BIN_ARCH_WINDOWS),$(OUTPUT)/bin/aws-iam-authenticator_$(VERSION)_windows_$(arch).exe)
ALL_DARWIN_BIN_TARGETS = $(foreach arch,$(BIN_ARCH_DARWIN),$(OUTPUT)/bin/aws-iam-authenticator_$(VERSION)_darwin_$(arch))
ALL_BIN_TARGETS = $(ALL_LINUX_BIN_TARGETS) $(ALL_WINDOWS_BIN_TARGETS) $(ALL_DARWIN_BIN_TARGETS)
.PHONY: bin
bin:
ifeq ($(GOOS),windows)
$(MAKE) $(OUTPUT)/bin/aws-iam-authenticator.exe
else
$(MAKE) $(OUTPUT)/bin/aws-iam-authenticator
endif
# Function checksum
# Parameters:
# 1: Target file on which to perform checksum
# 2: Checksum file to append the result
# Note: the blank line at the end of the function is required.
define checksum
sha256sum $(1) | sed 's|$(OUTPUT)/bin/||' >> $(2)
endef
.PHONY: checksums
checksums: $(CHECKSUM_FILE)
$(CHECKSUM_FILE): build-all-bins
rm -f $(CHECKSUM_FILE)
@echo $(ALL_BIN_TARGETS)
$(foreach target,$(ALL_BIN_TARGETS),$(call checksum,$(target),$(CHECKSUM_FILE)))
$(OUTPUT)/bin/%:
GO111MODULE=on \
CGO_ENABLED=0 \
GOOS=$(GOOS) \
GOARCH=$(GOARCH) \
GOPROXY=$(GOPROXY) \
go build \
-trimpath \
--tags "$(GOTAGS)" \
-o=$@ \
-ldflags="-w -s -X $(PKG)/pkg.Version=$(VERSION) -X $(PKG)/pkg.BuildDate=$(BUILD_DATE) -X $(PKG)/pkg.CommitID=$(GIT_COMMIT)" \
./cmd/aws-iam-authenticator/
# Function build-bin
# Parameters:
# 1: Target OS
# 2: Target architecture
# 3: Target file extension
# Note: the blank line at the end of the function is required.
define build-bin
$(MAKE) $(OUTPUT)/bin/aws-iam-authenticator_$(VERSION)_$(1)_$(2)$(3) GOOS=$(1) GOARCH=$(2)
endef
# Function build-image
# Parameters:
# 1: Target architecture
define build-image
$(MAKE) .image-linux-$(1)
endef
.PHONY: build-all-bins
build-all-bins:
$(foreach arch,$(BIN_ARCH_LINUX),$(call build-bin,linux,$(arch),))
$(foreach arch,$(BIN_ARCH_WINDOWS),$(call build-bin,windows,$(arch),.exe))
$(foreach arch,$(BIN_ARCH_DARWIN),$(call build-bin,darwin,$(arch),))
.PHONY: build-all-images
build-all-images:
$(foreach arch,$(BIN_ARCH_LINUX),$(call build-image,$(arch)))
.PHONY: image
image: .image-linux-$(GOARCH)
.PHONY: .image-linux-%
.image-linux-%:
docker buildx build --output=type=docker --platform linux/$* \
--build-arg golang_image=$(shell hack/setup-go.sh) \
--tag aws-iam-authenticator:$(VERSION)_$(GIT_COMMIT)_$(BUILD_DATE_STRIPPED)-linux_$* .
.PHONY: goreleaser
goreleaser:
ifndef GORELEASER
$(error "goreleaser not found (`go get -u -v github.com/goreleaser/goreleaser` to fix)")
endif
$(GORELEASER) --skip-publish --rm-dist --snapshot
.PHONY: test
test:
./hack/test-unit.sh
.PHONY: integration
integration:
./hack/test-integration.sh
.PHONY: e2e
e2e: bin
ifeq ($(RUNNER),kops)
CI=$(CI) ./hack/e2e/run.sh
else ifeq ($(RUNNER),kind)
./hack/start-dev-env-dynamicfile.sh
CI=$(CI) ./hack/e2e-dynamicfile.sh
./hack/stop-dev-env.sh
else
echo "make e2e RUNNER=[kops|kind]"
endif
.PHONY: format
format:
test -z "$$(find . -path ./vendor -prune -type f -o -name '*.go' -exec gofmt -d {} + | tee /dev/stderr)" || \
test -z "$$(find . -path ./vendor -prune -type f -o -name '*.go' -exec gofmt -w {} + | tee /dev/stderr)"
.PHONY: codegen
codegen:
./hack/update-codegen.sh
.PHONY: clean
clean:
rm -rf $(shell pwd)/_output
.PHONY: clean-dev
clean-dev:
rm -rf $(shell pwd)/_output/dev
# Use make start-dev when you want to create a kind cluster for
# testing the authenticator. You must pass in the admin ARN and
# the image under test.
.PHONY: start-dev
start-dev: bin
./hack/start-dev-env.sh
.PHONY: stop-dev
stop-dev:
./hack/stop-dev-env.sh
.PHONY: start-dev-dynamicfile-e2e
start-dev-dynamicfile:
./hack/start-dev-env-dynamicfile.sh
.PHONY: stop-dev-dynamicfile-e2e
stop-dev-dynamicfile:
./hack/stop-dev-env.sh
# Use make kill-dev when you want to remove a dev environment
# and clean everything up in preparation for creating another
# in the future.
# This command will:
# 1. Delete the kind cluster created for testing.
# 2. Kill the authenticator container.
# 3. Delete the docker network created for our kind cluster.
# 4. Remove the _output/dev directory where all the generated
# config is stored.
.PHONY: kill-dev
kill-dev: stop-dev clean-dev