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
40 changes: 17 additions & 23 deletions .github/workflows/build_and_test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -20,31 +20,25 @@ jobs:
build-and-test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Check out code
uses: actions/checkout@v3
- name: Run yamllint
run: |
MAKE_IN_DOCKER=1 make lint-yamllint
- name: Run Codespell
uses: codespell-project/actions-codespell@master
with:
# can't reuse tools/codespell/.codespell.skip, shell is not supported
skip: .git,*.png,*.woff,*.woff2,*.eot,*.ttf,*.jpg,*.ico,*.svg,go.mod,go.sum
ignore_words_file: 'tools/codespell/.codespell.ignorewords'
check_filenames: true
check_hidden: true
- uses: actions/setup-go@v3
MAKE_IN_DOCKER=1 make lint.yamllint
- name: Run codespell
run: |
MAKE_IN_DOCKER=1 make lint.codespell
- name: Run golangci-lint
run: |
MAKE_IN_DOCKER=1 make lint.golint
- name: Set up Go
uses: actions/setup-go@v3
with:
go-version: ${{ env.GO_VERSION }}
cache: true
- name: Run golangci-lint
uses: golangci/golangci-lint-action@v2
with:
version: v1.46.2
args: --build-tags=e2e
- name: Build
run: make build-all
- name: Build Binaries
run: make build.multiarch
- name: Test and report coverage
run: go test ./... -race -coverprofile=coverage.xml -covermode=atomic
run: make go.test.coverage
- name: Upload coverage to Codecov
uses: codecov/codecov-action@v2
with:
Expand All @@ -54,10 +48,10 @@ jobs:
verbose: true
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v2
- name: Build
- name: Build Docker Image
uses: docker/build-push-action@v3
with:
file: ./Dockerfile
file: ./tools/docker/envoy-gateway/Dockerfile
context: bin
platforms: linux/amd64
tags: ${{ env.ENVOY_GATEWAY_DEV_IMAGE }}:${{ github.sha }}
Expand All @@ -73,7 +67,7 @@ jobs:
if: github.event_name == 'push' && github.ref == 'refs/heads/main'
uses: docker/build-push-action@v3
with:
file: ./Dockerfile
file: ./tools/docker/envoy-gateway/Dockerfile
context: bin
platforms: linux/amd64,linux/arm64
push: true
Expand Down
21 changes: 18 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,8 +1,23 @@
# 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
#
# All make targets must be defined in Makefile.targets.mk

# Set MAKE_IN_DOCKER=1 as an environment variable to run `make` inside
# a Docker container with preinstalled tools.

Expand All @@ -18,7 +33,7 @@ DOCKER_RUN_CMD ?= docker run \
%:
ifeq ($(MAKE_IN_DOCKER), 1)
# Build builder image
@$(DOCKER_BUILD_CMD) -t $(DOCKER_BUILDER_IMAGE):$(DOCKER_BUILDER_TAG) - < tools/docker/Dockerfile
@$(DOCKER_BUILD_CMD) -t $(DOCKER_BUILDER_IMAGE):$(DOCKER_BUILDER_TAG) - < tools/docker/builder/Dockerfile
# Run make inside the builder image
# Run with MAKE_IN_DOCKER=0 to eliminate an infinite loop
@$(DOCKER_RUN_CMD) $(DOCKER_BUILDER_IMAGE):$(DOCKER_BUILDER_TAG) MAKE_IN_DOCKER=0 $@
Expand Down
270 changes: 120 additions & 150 deletions Makefile.targets.mk
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"
Loading