diff --git a/DEVELOPER.md b/DEVELOPER.md new file mode 100644 index 0000000000..ae98f6ba6a --- /dev/null +++ b/DEVELOPER.md @@ -0,0 +1,31 @@ +# Developer documentation + +Envoy Gateway is built using a [make](https://www.gnu.org/software/make/)-based +build system. Our CI is based on [Github Actions](https://docs.github.com/en/actions) (see: [workflows](.github/workflows)) + +## Prerequisites + +### go +* Version: 1.18.2 +* Installation Guide: https://go.dev/doc/install to + +### make +* Recommended Version: 4.3 +* Installation Guide: https://www.gnu.org/software/make/). + +### docker +* Optional when you want to build a Docker image or run make inside Docker. +* Recommened Version: 20.10.16 +* Installation Guide: https://docs.docker.com/engine/install/ + +### linters +* [TODO](https://github.com/envoyproxy/gateway/issues/73) + +* If you do not have these tools installed on your machine, +you can alternatively run `MAKE_IN_DOCKER=1 make ` to run `make` inside a Docker container which has all the +preinstalled tools needed to support all the `make` targets. + +## Quick start + +[TODO](https://github.com/envoyproxy/gateway/issues/101) Run `make help` to see all the available targets to build, test +and run `envoy-gateway`. diff --git a/Makefile b/Makefile index 30a87792a2..1e23087f5e 100644 --- a/Makefile +++ b/Makefile @@ -1,38 +1,28 @@ -# 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) - -.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 - -.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) - +# 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 envioronment variable to run `make` inside +# a Docker container with preinstalled tools. + +DOCKER_BUILDER_IMAGE ?= envoyproxy/gateway-dev-builder +DOCKER_BUILDER_TAG ?= latest +DOCKER_BUILD_CMD ?= DOCKER_BUILDKIT=1 docker build +DOCKER_RUN_CMD ?= docker run \ + --rm \ + -it \ + -v /var/run/docker.sock:/var/run/docker.sock \ + -v ${PWD}:/workspace + +%: +ifeq ($(MAKE_IN_DOCKER), 1) +# Build builder image + @$(DOCKER_BUILD_CMD) -t $(DOCKER_BUILDER_IMAGE):$(DOCKER_BUILDER_TAG) - < tools/Dockerfile.builder +# 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 $@ +else +# Run make locally + @$(MAKE) -f Makefile.targets.mk $@ +endif diff --git a/Makefile.targets.mk b/Makefile.targets.mk new file mode 100644 index 0000000000..75f76ca77e --- /dev/null +++ b/Makefile.targets.mk @@ -0,0 +1,38 @@ +# 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) + +.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 + +.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) + diff --git a/tools/Dockerfile.builder b/tools/Dockerfile.builder new file mode 100644 index 0000000000..d58801f89e --- /dev/null +++ b/tools/Dockerfile.builder @@ -0,0 +1,11 @@ +# Make sure the tooling versions are same as defined in the +# CI https://github.com/envoyproxy/gateway/blob/main/.github/workflows/build_and_test.yaml +# as well as in the Developer docs - https://github.com/envoyproxy/gateway/blob/main/DEVELOPER.md#prerequisites + +# go +FROM golang:1.18.2 as builder +# docker CLI +RUN curl -fsSL https://get.docker.com | VERSION=20.10.16 sh + +WORKDIR /workspace +ENTRYPOINT ["make"]