Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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
14 changes: 1 addition & 13 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,19 +1,7 @@
# All make targets should be defined in Makefile.targets.mk
# All make targets should be implemented in tools/make/*.mk
# ====================================================================================================
# Supported Targets: (Run `make help` to see more information)
# ====================================================================================================
## build: Build envoy-gateway for host platform. See Option PLATFORM and BINS.
## image: Build docker images for host platform. See Option PLATFORM and BINS.
## push: Push docker images to registry.
## build.multiarch: Build envoy-gateway for multiple platforms. See Option PLATFORMS and IMAGES.
## image.multiarch: Build docker images for multiple platforms. See Option PLATFORMS and IMAGES.
## push.multiarch: Push docker images for multiple platforms to registry.
## lint: Run all linter of code sources, including golint, yamllint and codespell.
## test: Run all Go test of code sources.
## format: Format codes style with mod tidy, gofmt and goimports.
## clean: Remove all files that are created by building.
# ====================================================================================================

# This is a wrapper around `make` so it can run
# directly on the host or inside a container
Expand All @@ -39,5 +27,5 @@ ifeq ($(MAKE_IN_DOCKER), 1)
@$(DOCKER_RUN_CMD) $(DOCKER_BUILDER_IMAGE):$(DOCKER_BUILDER_TAG) MAKE_IN_DOCKER=0 $@
else
# Run make locally
@$(MAKE) -f Makefile.targets.mk $@
@$(MAKE) -f tools/make/common.mk $@
endif
123 changes: 0 additions & 123 deletions Makefile.targets.mk

This file was deleted.

42 changes: 42 additions & 0 deletions tools/make/common.mk
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,20 @@
#
# All make targets related to common variables are defined in this file.

# ====================================================================================================
# ROOT Options:
# ====================================================================================================

ROOT_PACKAGE=github.com/envoyproxy/gateway

# ====================================================================================================
# Includes:
# ====================================================================================================
include tools/make/golang.mk
include tools/make/image.mk
include tools/make/lint.mk
include tools/make/kube.mk

# Set Root Directory Path
ifeq ($(origin ROOT_DIR),undefined)
ROOT_DIR := $(abspath $(shell pwd -P))
Expand Down Expand Up @@ -51,3 +65,31 @@ endif
ifeq (${BINS},)
$(error Could not determine BINS, set ROOT_DIR or run in source dir)
endif

define USAGE_OPTIONS

Options:
BINS The binaries to build. Default is all of cmd.
This option is available when using: make build/build.multiarch
Example: make build BINS="envoy-gateway"
IMAGES Backend images to make. Default is all of cmds.
This option is available when using: make image/image.multiarch/push/push.multiarch
Example: make image.multiarch IMAGES="envoy-gateway"
PLATFORM The specified platform to build.
This option is available when using: make build/image
Example: make build BINS="envoy-gateway" PLATFORM="linux_amd64"
Supported Platforms: linux_amd64 linux_arm64 darwin_amd64 darwin_arm64
PLATFORMS The multiple platforms to build.
This option is available when using: make build.multiarch
Example: make image.multiarch IMAGES="envoy-gateway" PLATFORMS="linux_amd64 linux_arm64"
Default is "linux_amd64 linux_arm64 darwin_amd64 darwin_arm64".
endef
export USAGE_OPTIONS

## help: Show this help info.
.PHONY: help
help:
@echo "Envoy Gateway is an open source project for managing Envoy Proxy as a standalone or Kubernetes-based application gateway\n"
@echo "Usage: make <Targets> <Options> ...\n\nTargets:"
@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)
@echo "$$USAGE_OPTIONS"
30 changes: 27 additions & 3 deletions tools/make/golang.mk
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# This is a wrapper to build and push golang binaries
# This is a wrapper to build golang binaries
#
# All make targets related to golang are defined in this file.

Expand All @@ -22,12 +22,14 @@ go.build.%:

# Build the envoy-gateway binaries in the hosted platforms.
.PHONY: go.build
go.build: $(addprefix go.build., $(addprefix $(PLATFORM)., $(BINS)))
go.build:
@$(MAKE) $(addprefix go.build., $(addprefix $(PLATFORM)., $(BINS)))
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What's the point of this change? In the other places that do $(MAKE) like this, I'd have made the reverse change.

(See also: Peter Miller's famous "Recursive Make Considered Harmful" article)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@LukeShu thanks for the review, I added that extra make because I was unable to work around it, here's the error

diff --git a/tools/make/golang.mk b/tools/make/golang.mk
index 7600d0a..9c7f1c3 100644
--- a/tools/make/golang.mk
+++ b/tools/make/golang.mk
@@ -22,8 +22,7 @@ go.build.%:
 
 # Build the envoy-gateway binaries in the hosted platforms.
 .PHONY: go.build
-go.build:
-       @$(MAKE) $(addprefix go.build., $(addprefix $(PLATFORM)., $(BINS)))
+go.build: $(addprefix go.build., $(addprefix $(PLATFORM)., $(BINS)))
 
 # Build the envoy-gateway binaries in multi platforms
 # It will build the linux/amd64, linux/arm64, darwin/amd64, darwin/arm64 binaries out.
🐳 ~/go-workspace/src/github.com/envoyproxy/gateway$ make build
make[3]: Nothing to be done for `go.build'.

hopefully some make magician can help iron this out, but for the time being shouldnt affect correctness


# Build the envoy-gateway binaries in multi platforms
# It will build the linux/amd64, linux/arm64, darwin/amd64, darwin/arm64 binaries out.
.PHONY: go.build.multiarch
go.build.multiarch: $(foreach p,$(PLATFORMS),$(addprefix go.build., $(addprefix $(p)., $(BINS))))
go.build.multiarch:
@$(MAKE) $(foreach p,$(PLATFORMS),$(addprefix go.build., $(addprefix $(p)., $(BINS))))

.PHONY: go.test.unit
go.test.unit: ## Run go unit tests
Expand Down Expand Up @@ -56,3 +58,25 @@ go.format: go.format.verify
@gofmt -s -w .
@goimports -w -local $(ROOT_PACKAGE) .
@go mod tidy

##@ Golang

.PHONY: build
build: ## Build envoy-gateway for host platform. See Option PLATFORM and BINS.
@$(MAKE) go.build

.PHONY: build.multiarch
build.multiarch: ## Build envoy-gateway for multiple platforms. See Option PLATFORMS and IMAGES.
@$(MAKE) go.build.multiarch

.PHONY: test
test: ## Run all Go test of code sources.
@$(MAKE) go.test.unit

.PHONY: format
format: ## Format codes style with mod tidy, gofmt and goimports.
@$(MAKE) go.format

.PHONY: clean
clean: ## Remove all files that are created during builds.
@$(MAKE) go.clean
24 changes: 22 additions & 2 deletions tools/make/image.mk
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,24 @@ ifeq (${IMAGES},)
$(error Could not determine IMAGES, set ROOT_DIR or run in source dir)
endif

##@ Image

.PHONY: image
image: ## Build docker images for host platform. See Option PLATFORM and BINS.
@$(MAKE) image.build

.PHONY: push
push: ## Push docker images to registry.
@$(MAKE) image.push

.PHONY: image.multiarch
image.multiarch: ## Build docker images for multiple platforms. See Option PLATFORMS and IMAGES.
@$(MAKE) image.build.multiarch

.PHONY: push.multiarch
push.multiarch: ## Push docker images for multiple platforms to registry.
@$(MAKE) image.push.multiarch

.PHONY: image.verify
image.verify:
$(eval API_VERSION := $(shell $(DOCKER) version | grep -E 'API version: {1,6}[0-9]' | head -n1 | awk '{print $$3} END { if (NR==0) print 0}' ))
Expand All @@ -34,10 +52,12 @@ image.verify:
fi

.PHONY: image.build
image.build: image.verify $(addprefix image.build., $(addprefix $(IMAGE_PLAT)., $(IMAGES)))
image.build: image.verify
@$(MAKE) $(addprefix image.build., $(addprefix $(IMAGE_PLAT)., $(IMAGES)))

.PHONY: image.build.multiarch
image.build.multiarch: image.verify $(foreach p,$(IMAGE_PLATFORMS),$(addprefix image.build., $(addprefix $(p)., $(IMAGES))))
image.build.multiarch: image.verify
# TODO: use buildx

.PHONY: image.build.%
image.build.%: go.build.%
Expand Down
60 changes: 60 additions & 0 deletions tools/make/kube.mk
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
##@ Kubernetes Development

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

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

.PHONY: kube-test
kube-test: manifests generate lint envtest ## Run Kubernetes provider tests.
KUBEBUILDER_ASSETS="$(shell $(ENVTEST) use $(ENVTEST_K8S_VERSION) -p path)" go test ./... -coverprofile cover.out


##@ Kubernetes Deployment

ifndef ignore-not-found
ignore-not-found = false
endif

.PHONY: kube-install
kube-install: manifests kustomize ## Install CRDs into the Kubernetes cluster specified in ~/.kube/config.
$(KUSTOMIZE) build pkg/provider/kubernetes/config/crd | kubectl apply -f -

.PHONY: kube-uninstall
kube-uninstall: manifests kustomize ## Uninstall CRDs from the K8s cluster specified in ~/.kube/config. Call with ignore-not-found=true to ignore resource not found errors during deletion.
$(KUSTOMIZE) build pkg/provider/kubernetes/config/crd | kubectl delete --ignore-not-found=$(ignore-not-found) -f -

##@ Kubernetes Build Dependencies

## Location to install dependencies to
LOCALBIN ?= $(shell pwd)/bin
$(LOCALBIN):
mkdir -p $(LOCALBIN)

## Tool Binaries
KUSTOMIZE ?= $(LOCALBIN)/kustomize
CONTROLLER_GEN ?= $(LOCALBIN)/controller-gen
ENVTEST ?= $(LOCALBIN)/setup-envtest

## Tool Versions
KUSTOMIZE_VERSION ?= v3.8.7
CONTROLLER_TOOLS_VERSION ?= v0.8.0

KUSTOMIZE_INSTALL_SCRIPT ?= "https://raw.githubusercontent.com/kubernetes-sigs/kustomize/master/hack/install_kustomize.sh"
.PHONY: kustomize
kustomize: $(KUSTOMIZE) ## Download kustomize locally if necessary.
$(KUSTOMIZE): $(LOCALBIN)
curl -s $(KUSTOMIZE_INSTALL_SCRIPT) | bash -s -- $(subst v,,$(KUSTOMIZE_VERSION)) $(LOCALBIN)

.PHONY: controller-gen
controller-gen: $(CONTROLLER_GEN) ## Download controller-gen locally if necessary.
$(CONTROLLER_GEN): $(LOCALBIN)
GOBIN=$(LOCALBIN) go install sigs.k8s.io/controller-tools/cmd/controller-gen@$(CONTROLLER_TOOLS_VERSION)

.PHONY: envtest
envtest: $(ENVTEST) ## Download envtest-setup locally if necessary.
$(ENVTEST): $(LOCALBIN)
GOBIN=$(LOCALBIN) go install sigs.k8s.io/controller-runtime/tools/setup-envtest@latest
7 changes: 7 additions & 0 deletions tools/make/lint.mk
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,12 @@
#
# All make targets related to lint are defined in this file.

##@ Lint

.PHONY: lint
lint: ## Run all linter of code sources, including golint, yamllint and codespell.
@$(MAKE) lint.golint lint.yamllint lint.codespell

.PHONY: lint.golint
lint.golint:
@echo Running Go linter ...
Expand All @@ -15,4 +21,5 @@ lint.yamllint:
.PHONY: lint.codespell
lint.codespell: CODESPELL_SKIP := $(shell cat tools/linter/codespell/.codespell.skip | tr \\n ',')
lint.codespell:
@echo Running Codespell linter ...
@codespell --skip $(CODESPELL_SKIP) --ignore-words tools/linter/codespell/.codespell.ignorewords --check-filenames --check-hidden -q2