This repository has been archived by the owner on Mar 19, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 16
/
Makefile
172 lines (142 loc) · 5 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
SHELL := /usr/bin/env bash -euo pipefail -c
REPO_NAME ?= $(shell basename "$(CURDIR)")
PRODUCT_NAME ?= $(REPO_NAME)
BIN_NAME ?= $(PRODUCT_NAME)
# Get local ARCH; on Intel Mac, 'uname -m' returns x86_64 which we turn into amd64.
# Not using 'go env GOOS/GOARCH' here so 'make docker' will work without local Go install.
ARCH = $(shell A=$$(uname -m); [ $$A = x86_64 ] && A=amd64; echo $$A)
OS = $(shell uname | tr [[:upper:]] [[:lower:]])
PLATFORM = $(OS)/$(ARCH)
DIST = dist/$(PLATFORM)
BIN = $(DIST)/$(BIN_NAME)
ifneq (,$(wildcard internal/version/version_ent.go))
VERSION = $(shell ./dev/version internal/version/version_ent.go)
else
VERSION = $(shell ./dev/version internal/version/version.go)
endif
# Get latest revision (no dirty check for now).
REVISION = $(shell git rev-parse HEAD)
# Kubernetes-specific stuff
CRD_OPTIONS ?= "crd:allowDangerousTypes=true"
################
# find or download goimports
# download goimports if necessary
.PHONY: goimports
goimports:
ifeq (, $(shell which goimports))
@go install golang.org/x/tools/cmd/goimports
endif
GOIMPORTS=$(shell which goimports)
.PHONY: fmt
fmt: goimports
@for d in $$(go list -f {{.Dir}} ./...); do ${GOIMPORTS} --local github.com/hashicorp/consul-api-gateway,github.com/hashicorp -w -l $$d/*.go; done
.PHONY: lint
lint:
ifeq (, $(shell which golangci-lint))
@go install github.com/golangci/golangci-lint/cmd/golangci-lint
endif
@$(shell which golangci-lint) run --verbose
.PHONY: test
test:
go test ./...
# Run e2e tests, takes an optional variable `consul_image` which specifies the consul image to test against
.PHONY: e2e
e2e:
E2E_APIGW_CONSUL_IMAGE=$(consul_image) ./scripts/e2e_local.sh
generate-golden-files:
GENERATE=true go test ./internal/adapters/consul
GENERATE=true go test ./internal/envoy
GENERATE=true go test ./internal/k8s/builder
.PHONY: gen
gen: generate-golden-files ctrl-generate ctrl-manifests fmt
ifeq (, $(shell which mockgen))
@go install github.com/golang/mock/mockgen
endif
ifeq (, $(shell which oapi-codegen))
@go install github.com/deepmap/oapi-codegen/cmd/oapi-codegen
endif
go generate ./...
.PHONY: changelog
changelog:
ifeq (, $(shell which changelog-build))
@go install github.com/hashicorp/go-changelog/cmd/changelog-build
endif
ifeq (, $(LAST_RELEASE_GIT_TAG))
@echo "Please set the LAST_RELEASE_GIT_TAG environment variable to generate a changelog section of notes since the last release."
else
@changelog-build -last-release ${LAST_RELEASE_GIT_TAG} -entries-dir .changelog/ -changelog-template .changelog/changelog.tmpl -note-template .changelog/release-note.tmpl -this-release $(shell git rev-parse HEAD)
endif
.PHONY: changelog-entry
changelog-entry:
ifeq (, $(shell which changelog-entry))
@go install github.com/hashicorp/go-changelog/cmd/changelog-entry
endif
changelog-entry -dir .changelog
.PHONY: changelog-check
changelog-check:
ifeq (, $(shell which changelog-check))
@go install github.com/hashicorp/go-changelog/cmd/changelog-check
endif
@changelog-check
# Run controller tests
.PHONY: ctrl-test
ENVTEST_ASSETS_DIR=$(shell pwd)/testbin
ctrl-test: ctrl-generate ctrl-manifests
ifeq (, $(shell which setup-envtest))
@go install sigs.k8s.io/controller-runtime/tools/setup-envtest
endif
setup-envtest use
# Generate manifests e.g. CRD, RBAC etc.
.PHONY: ctrl-manifests
ctrl-manifests: controller-gen
$(CONTROLLER_GEN) $(CRD_OPTIONS) rbac:roleName=consul-api-gateway-controller webhook paths="./..." output:crd:artifacts:config=config/crd/bases
# Generate code
.PHONY: ctrl-generate
ctrl-generate: controller-gen
$(CONTROLLER_GEN) object paths="./..."
# find or download controller-gen
# download controller-gen if necessary
.PHONY: controller-gen
controller-gen:
ifeq (, $(shell which controller-gen))
@go install sigs.k8s.io/controller-tools/cmd/controller-gen
endif
CONTROLLER_GEN=$(shell which controller-gen)
.PHONY: version
version:
@echo $(VERSION)
dist:
mkdir -p $(DIST)
echo '*' > dist/.gitignore
.PHONY: bin
bin: dist
GOARCH=$(ARCH) GOOS=$(OS) go build -o $(BIN)
# Docker Stuff.
export DOCKER_BUILDKIT=1
BUILD_ARGS = BIN_NAME=$(BIN_NAME) PRODUCT_VERSION=$(VERSION) PRODUCT_REVISION=$(REVISION)
TAG = $(PRODUCT_NAME)/$(TARGET):$(VERSION)
BA_FLAGS = $(addprefix --build-arg=,$(BUILD_ARGS))
FLAGS = --target $(TARGET) --platform $(PLATFORM) --tag $(TAG) $(BA_FLAGS)
# Set OS to linux for all docker/* targets.
docker/%: OS = linux
# DOCKER_TARGET is a macro that generates the build and run make targets
# for a given Dockerfile target.
# Args: 1) Dockerfile target name (required).
# 2) Build prerequisites (optional).
define DOCKER_TARGET
.PHONY: docker/$(1)
docker/$(1): TARGET=$(1)
docker/$(1): $(2)
docker build $$(FLAGS) .
@echo 'Image built; run "docker run --rm $$(TAG)" to try it out.'
.PHONY: docker/$(1)/run
docker/$(1)/run: TARGET=$(1)
docker/$(1)/run: docker/$(1)
docker run --rm $$(TAG)
endef
# Create docker/<target>[/run] targets.
$(eval $(call DOCKER_TARGET,dev,))
$(eval $(call DOCKER_TARGET,default,bin))
$(eval $(call DOCKER_TARGET,debian,bin))
.PHONY: docker
docker: docker/dev