-
Notifications
You must be signed in to change notification settings - Fork 287
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: add more commands and refactor makefiles (#113)
* chore: add more commands and refactor build command Signed-off-by: Xunzhuo <mixdeers@gmail.com>
- Loading branch information
Showing
14 changed files
with
363 additions
and
179 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,153 +1,123 @@ | ||
# Golang variables | ||
GOOS ?= $(shell go env GOOS) | ||
GOARCH ?= $(shell go env GOARCH) | ||
|
||
# Docker variables | ||
# REGISTRY is the image registry to use for build and push image targets. | ||
REGISTRY ?= docker.io/envoyproxy | ||
# IMAGE is the image URL for build and push image targets. | ||
IMAGE ?= ${REGISTRY}/gateway-dev | ||
# REV is the short git sha of latest commit. | ||
REV=$(shell git rev-parse --short HEAD) | ||
# Tag is the tag to use for build and push image targets. | ||
TAG ?= $(REV) | ||
# ENVTEST_K8S_VERSION refers to the version of kubebuilder assets to be downloaded by envtest binary. | ||
ENVTEST_K8S_VERSION = 1.23 | ||
|
||
# Get the currently used golang install path (in GOPATH/bin, unless GOBIN is set) | ||
ifeq (,$(shell go env GOBIN)) | ||
GOBIN=$(shell go env GOPATH)/bin | ||
else | ||
GOBIN=$(shell go env GOBIN) | ||
endif | ||
|
||
# Setting SHELL to bash allows bash commands to be executed by recipes. | ||
# This is a requirement for 'setup-envtest.sh' in the test target. | ||
# Options are set to exit when a recipe line exits non-zero or a piped command fails. | ||
SHELL = /usr/bin/env bash -o pipefail | ||
.SHELLFLAGS = -ec | ||
|
||
##@ General | ||
|
||
# The help target prints out all targets with their descriptions organized | ||
# beneath their categories. The categories are represented by '##@' and the | ||
# target descriptions by '##'. The awk commands is responsible for reading the | ||
# entire set of makefiles included in this invocation, looking for lines of the | ||
# file as xyz: ## something, and then pretty-format the target and help. Then, | ||
# if there's a line with ##@ something, that gets pretty-printed as a category. | ||
# More info on the usage of ANSI control characters for terminal formatting: | ||
# https://en.wikipedia.org/wiki/ANSI_escape_code#SGR_parameters | ||
# More info on the awk command: | ||
# http://linuxcommand.org/lc3_adv_awk.php | ||
|
||
.PHONY: help | ||
help: ## Display this help | ||
@echo Envoy Gateway is an open source project for managing Envoy Proxy as a standalone or Kubernetes-based application gateway | ||
@echo | ||
@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) | ||
|
||
##@ Build | ||
|
||
# ==================================================================================================== | ||
# ROOT Options: | ||
# ==================================================================================================== | ||
|
||
ROOT_PACKAGE=github.com/envoyproxy/gateway | ||
|
||
# ==================================================================================================== | ||
# Includes: | ||
# ==================================================================================================== | ||
include tools/make/common.mk | ||
include tools/make/golang.mk | ||
include tools/make/image.mk | ||
include tools/make/lint.mk | ||
|
||
# ==================================================================================================== | ||
# Targets: | ||
# ==================================================================================================== | ||
|
||
# ==================================================================================================== | ||
## build: Build envoy-gateway for host platform. See Option PLATFORM and BINS. | ||
# ==================================================================================================== | ||
.PHONY: build | ||
build: ## Build the envoy-gateway binary | ||
@CGO_ENABLED=0 go build -a -o ./bin/${GOOS}/${GOARCH}/ github.com/envoyproxy/gateway/cmd/envoy-gateway | ||
|
||
build-linux-amd64: | ||
@GOOS=linux GOARCH=amd64 $(MAKE) build | ||
|
||
build-linux-arm64: | ||
@GOOS=linux GOARCH=arm64 $(MAKE) build | ||
|
||
build-all: build-linux-amd64 build-linux-arm64 | ||
build: | ||
@$(MAKE) go.build | ||
|
||
# ==================================================================================================== | ||
## image: Build docker images for host platform. See Option PLATFORM and BINS. | ||
# ==================================================================================================== | ||
.PHONY: image | ||
image: | ||
@$(MAKE) image.build | ||
|
||
# ==================================================================================================== | ||
## push: Push docker images to registry. | ||
# ==================================================================================================== | ||
.PHONY: push | ||
push: | ||
@$(MAKE) image.push | ||
|
||
# ==================================================================================================== | ||
## build.multiarch: Build envoy-gateway for multiple platforms. See Option PLATFORMS and IMAGES. | ||
# ==================================================================================================== | ||
.PHONY: build.multiarch | ||
build.multiarch: | ||
@$(MAKE) go.build.multiarch | ||
|
||
# ==================================================================================================== | ||
## image.multiarch: Build docker images for multiple platforms. See Option PLATFORMS and IMAGES. | ||
# ==================================================================================================== | ||
.PHONY: image.multiarch | ||
image.multiarch: | ||
@$(MAKE) image.build.multiarch | ||
|
||
# ==================================================================================================== | ||
## push.multiarch: Push docker images for multiple platforms to registry. | ||
# ==================================================================================================== | ||
.PHONY: push.multiarch | ||
push.multiarch: | ||
@$(MAKE) image.push.multiarch | ||
|
||
# ==================================================================================================== | ||
## lint: Run all linter of code sources, including golint, yamllint and codespell. | ||
# ==================================================================================================== | ||
.PHONY: lint | ||
lint: | ||
@$(MAKE) lint.golint lint.yamllint lint.codespell | ||
|
||
# ==================================================================================================== | ||
## test: Run all Go test of code sources. | ||
# ==================================================================================================== | ||
.PHONY: test | ||
test: | ||
@go test ./... | ||
|
||
.PHONY: docker-build | ||
docker-build: build-all ## Build the envoy-gateway docker image. | ||
@DOCKER_BUILDKIT=1 docker build -t $(IMAGE):$(TAG) -f Dockerfile bin | ||
|
||
.PHONY: docker-push | ||
docker-push: ## Push the docker image for envoy-gateway. | ||
@docker push $(IMAGE):$(TAG) | ||
|
||
.PHONY: lint | ||
lint: ## Run lint checks | ||
lint: lint-golint lint-yamllint lint-codespell | ||
|
||
.PHONY: lint-golint | ||
lint-golint: | ||
@echo Running Go linter ... | ||
@golangci-lint run --build-tags=e2e --config=tools/golangci-lint/.golangci.yml | ||
|
||
.PHONY: lint-yamllint | ||
lint-yamllint: | ||
@echo Running YAML linter ... | ||
## TODO(lianghao208): add other directories later | ||
@yamllint --config-file=tools/yamllint/.yamllint changelogs/ | ||
|
||
.PHONY: lint-codespell | ||
lint-codespell: CODESPELL_SKIP := $(shell cat tools/codespell/.codespell.skip | tr \\n ',') | ||
lint-codespell: | ||
@codespell --skip $(CODESPELL_SKIP) --ignore-words tools/codespell/.codespell.ignorewords --check-filenames --check-hidden -q2 | ||
|
||
##@ 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 | ||
|
||
##@ 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 - | ||
|
||
##@ 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 | ||
test: | ||
@$(MAKE) go.test.unit | ||
|
||
# ==================================================================================================== | ||
## format: Format codes style with mod tidy, gofmt and goimports. | ||
# ==================================================================================================== | ||
.PHONY: format | ||
format: | ||
@$(MAKE) go.format | ||
|
||
# ==================================================================================================== | ||
## clean: Remove all files that are created by building. | ||
# ==================================================================================================== | ||
.PHONY: clean | ||
clean: | ||
@$(MAKE) go.clean | ||
|
||
# ==================================================================================================== | ||
# Usage | ||
# ==================================================================================================== | ||
|
||
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 | ||
# ==================================================================================================== | ||
|
||
## help: Show this help info. | ||
.PHONY: help | ||
help: Makefile | ||
@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:" | ||
@sed -n 's/^##//p' $< | column -t -s ':' | sed -e 's/^/ /' | ||
@echo "$$USAGE_OPTIONS" |
Oops, something went wrong.