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
31 changes: 31 additions & 0 deletions DEVELOPER.md
Original file line number Diff line number Diff line change
@@ -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 <target>` 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`.
66 changes: 28 additions & 38 deletions Makefile
Original file line number Diff line number Diff line change
@@ -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
38 changes: 38 additions & 0 deletions Makefile.targets.mk
Original file line number Diff line number Diff line change
@@ -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)

11 changes: 11 additions & 0 deletions tools/Dockerfile.builder
Original file line number Diff line number Diff line change
@@ -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"]