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
64 changes: 25 additions & 39 deletions .github/workflows/build_and_test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,68 +12,54 @@ on:
- "release-v*"
paths-ignore:
- "**/*.png"
env:
GO_VERSION: 1.18.2
ENVOY_GATEWAY_DEV_IMAGE: envoyproxy/gateway-dev
ENVOY_GATEWAY_DEV_TAG: latest
jobs:
lint:
runs-on: ubuntu-latest
Comment thread
LukeShu marked this conversation as resolved.
steps:
- uses: actions/checkout@v3
- uses: ./tools/github-actions/setup-deps

# lint
- run: make lint-deps
Comment thread
arkodg marked this conversation as resolved.
Outdated
- run: make -k lint

build-and-test:
runs-on: ubuntu-latest
steps:
- name: Check out code
uses: actions/checkout@v3
- name: Run whitenoise lint
run: |
MAKE_IN_DOCKER=1 make lint.whitenoise
- name: Run yamllint
run: |
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 }}
- name: Build Binaries
run: make build-multiarch
- name: Test and report coverage
run: make go.test.coverage
- uses: actions/checkout@v3
- uses: ./tools/github-actions/setup-deps

# build
- run: make build-multiarch

# test
- run: make go.test.coverage
- name: Upload coverage to Codecov
uses: codecov/codecov-action@v2
with:
fail_ci_if_error: true
files: ./coverage.xml
name: codecov-envoy-gateway
verbose: true
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v2
- name: Build Docker Image
uses: docker/build-push-action@v3
with:
file: ./tools/docker/envoy-gateway/Dockerfile
context: bin
platforms: linux/amd64
tags: ${{ env.ENVOY_GATEWAY_DEV_IMAGE }}:${{ github.sha }}
cache-from: type=gha
cache-to: type=gha,mode=max

# push
- name: Login to DockerHub
if: github.event_name == 'push'
uses: docker/login-action@v2
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_PASSWORD }}
- name: Push to envoyproxy/gateway-dev
- run: make push-multiarch
if: github.event_name == 'push'
- name: Push to :latest
if: github.event_name == 'push' && github.ref == 'refs/heads/main'
# TODO(lukeshu): Switch this to be a Make target
uses: docker/build-push-action@v3
with:
file: ./tools/docker/envoy-gateway/Dockerfile
context: bin
platforms: linux/amd64,linux/arm64
push: true
tags: ${{ env.ENVOY_GATEWAY_DEV_IMAGE }}:${{ github.sha }}, ${{ env.ENVOY_GATEWAY_DEV_IMAGE }}:${{ env.ENVOY_GATEWAY_DEV_TAG }}
tags: docker.io/envoyproxy/gateway-dev:latest
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.

we also want to tag and push with the SHA of the commit, can you please revert this

Copy link
Copy Markdown
Contributor Author

@LukeShu LukeShu Jul 6, 2022

Choose a reason for hiding this comment

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

The sha is already pushed by the earlier make push-multiarch (or, pre-this-pr: is already pushed by a different earlier docker/build-push-action@v3 call)

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.

ah thanks for pointing it out.
If we left this the way it is, it would be make the CI faster since its leveraging the same cache for the multiple build steps

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.

IMO, since everything should be doable without GHA, the better solution would be to go the other direction and move the :latest pushing to be a target in the Makefile, but I didn't have the appetite to do that in this PR.

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.

would prefer if this GHA remains the way it is, since the current changes doesn't improve the existing workflow and keep things consistent

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.

FTR, I tend to strongly believe that it should be a requirement that you can cut a release even if GHA is down, so I also believe that the push-to-:latest bit should move into a Makefile target.

Copy link
Copy Markdown
Contributor

@arkodg arkodg Jul 7, 2022

Choose a reason for hiding this comment

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

@kflynn that sounds like a valid case, prefer if we handle ^ Makefile target in a separate PR once completed so it does not overload this PR which is addressing #124

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.

@arkodg Completely agree that it should be a separate PR, yes. 🙂

cache-from: type=gha
cache-to: type=gha,mode=max
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
**/.DS_Store
.DS_Store
Comment thread
LukeShu marked this conversation as resolved.
bin/
25 changes: 8 additions & 17 deletions DEVELOPER.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,29 +10,20 @@ Envoy Gateway is built using a [make][make]-based build system. Our CI is based
* Installation Guide: https://go.dev/doc/install

### make
* Recommended Version: 4.3
* Installation Guide: https://www.gnu.org/software/make.
* Recommended Version: 4.0 or later
* Installation Guide: https://www.gnu.org/software/make

### docker
* Optional when you want to build a Docker image or run `make` inside Docker.
* Recommended Version: 20.10.16
* Installation Guide: https://docs.docker.com/engine/install

### golangci-lint
* Recommended Version: 1.46.2
* Installation Guide: https://github.com/golangci/golangci-lint#install

### yamllint
* Recommended Version: 1.24.2
* Installation Guide: https://yamllint.readthedocs.io/en/stable/quickstart.html#installing-yamllint

### codespell
* Recommended Version: 2.1.0
* Installation Guide: https://github.com/codespell-project/codespell#installation

__Note:__ 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.
### python3
* Need a `python3` program
* Must have a functioning `venv` module; this is part of the standard
library, but some distributions (such as Debian and Ubuntu) replace
it with a stub and require you to install a `python3-venv` package
separately.

## Quick start

Expand Down
39 changes: 14 additions & 25 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -3,29 +3,18 @@
# Supported Targets: (Run `make help` to see more information)
# ====================================================================================================

# This is a wrapper around `make` so it can run
# directly on the host or inside a container
#
# Set MAKE_IN_DOCKER=1 as an environment variable to run `make` inside
# a Docker container with preinstalled tools.
# This file is a wrapper around `make` so that we can force on the
# --warn-undefined-variables flag. Sure, you can set
# `MAKEFLAGS += --warn-undefined-variables` from inside of a Makefile,
# but then it won't turn on until the second phase (recipe execution),
# and won't actually be on during the initial phase (parsing).
# See: https://www.gnu.org/software/make/manual/make.html#Reading-Makefiles

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 \
-t \
-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/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 $@
else
# Run make locally
@$(MAKE) -f tools/make/common.mk $@
endif
# Have everything-else ("%") depend on _run (which uses
# $(MAKECMDGOALS) to decide what to run), rather than having
# everything else run $(MAKE) directly, since that'd end up running
# multiple sub-Makes if you give multiple targets on the CLI.
_run:
$(MAKE) --warn-undefined-variables -f tools/make/common.mk $(MAKECMDGOALS)
.PHONY: _run
$(if $(MAKECMDGOALS),$(MAKECMDGOALS): %: _run)
26 changes: 0 additions & 26 deletions tools/docker/builder/Dockerfile

This file was deleted.

12 changes: 12 additions & 0 deletions tools/github-actions/setup-deps/action.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
name: setup-deps
description: Install host system dependencies

runs:
using: composite
steps:
- uses: actions/setup-go@v3
with:
go-version: 1.18.2
cache: true
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v2
3 changes: 2 additions & 1 deletion tools/linter/codespell/.codespell.skip
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,5 @@
*.ico
*.svg
go.mod
go.sum
go.sum
bin
26 changes: 26 additions & 0 deletions tools/linter/codespell/matcher.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
{
Comment thread
LukeShu marked this conversation as resolved.
Outdated
"problemMatcher": [
{
"owner": "codespell-matcher-default",
"pattern": [
{
"regexp": "^(.+):(\\d+):\\s+(.+)$",
"file": 1,
"line": 2,
"message": 3
}
]
},
{
"owner": "codespell-matcher-specified",
"pattern": [
{
"regexp": "^(ERROR|WARNING):\\s+(.+):\\s+(.+?)\\s*$",
"file": 3,
"severity": 1,
"message": 2
}
]
}
]
}
27 changes: 20 additions & 7 deletions tools/make/common.mk
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,22 @@
# All make targets related to common variables are defined in this file.

# ====================================================================================================
# ROOT Options:
# Configure Make itself:
# ====================================================================================================

ROOT_PACKAGE=github.com/envoyproxy/gateway
# Turn off .INTERMEDIATE file removal by marking all files as
# .SECONDARY. .INTERMEDIATE file removal is a space-saving hack from
# a time when drives were small; on modern computers with plenty of
# storage, it causes nothing but headaches.
#
# https://news.ycombinator.com/item?id=16486331
.SECONDARY:

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

ROOT_PACKAGE=github.com/envoyproxy/gateway

# Set Root Directory Path
ifeq ($(origin ROOT_DIR),undefined)
Expand Down Expand Up @@ -66,6 +70,15 @@ ifeq (${BINS},)
$(error Could not determine BINS, set ROOT_DIR or run in source dir)
endif

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

# Log the running target
LOG_TARGET = echo "===========> Running $@..."
# Log debugging info
Expand Down
28 changes: 13 additions & 15 deletions tools/make/golang.mk
Original file line number Diff line number Diff line change
Expand Up @@ -20,36 +20,34 @@ go.build.%:
$(eval OS := $(word 1,$(subst _, ,$(PLATFORM))))
$(eval ARCH := $(word 2,$(subst _, ,$(PLATFORM))))
@$(call log, "Building binary $(COMMAND) with commit $(REV) in version $(VERSION) for $(OS) $(ARCH)")
@CGO_ENABLED=0 GOOS=$(OS) GOARCH=$(ARCH) go build -o $(OUTPUT_DIR)/$(OS)/$(ARCH)/$(COMMAND) $(ROOT_PACKAGE)/cmd/$(COMMAND)
CGO_ENABLED=0 GOOS=$(OS) GOARCH=$(ARCH) go build -o $(OUTPUT_DIR)/$(OS)/$(ARCH)/$(COMMAND) $(ROOT_PACKAGE)/cmd/$(COMMAND)

# Build the envoy-gateway binaries in the hosted platforms.
.PHONY: go.build
go.build:
@$(MAKE) $(addprefix go.build., $(addprefix $(PLATFORM)., $(BINS)))
Comment thread
arkodg marked this conversation as resolved.
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.
.PHONY: go.build.multiarch
go.build.multiarch:
@$(MAKE) $(foreach p,$(PLATFORMS),$(addprefix go.build., $(addprefix $(p)., $(BINS))))
go.build.multiarch: $(foreach p,$(PLATFORMS),$(addprefix go.build., $(addprefix $(p)., $(BINS))))

.PHONY: go.test.unit
go.test.unit: ## Run go unit tests
@go test ./...
go test ./...

.PHONY: go.test.coverage
go.test.coverage: envtest ## Run go unit tests in GitHub Actions
KUBEBUILDER_ASSETS="$(shell $(ENVTEST) use $(ENVTEST_K8S_VERSION) -p path)" go test ./... -race -coverprofile=coverage.xml -covermode=atomic
go.test.coverage: $(tools/setup-envtest) ## Run go unit tests in GitHub Actions
KUBEBUILDER_ASSETS="$(shell $(tools/setup-envtest) use $(ENVTEST_K8S_VERSION) -p path)" go test ./... -race -coverprofile=coverage.xml -covermode=atomic

.PHONY: go.clean
go.clean: ## Clean the building output files
@$(call log, "Cleaning all build output")
@rm -rf $(OUTPUT_DIR)
rm -rf $(OUTPUT_DIR)

.PHONY: go.tidy
go.tidy:
@$(LOG_TARGET)
@go mod tidy -compat=$(GO_VERSION)
go mod tidy -compat=$(GO_VERSION)
## ensure all changes have been committed
git diff --exit-code go.mod
git diff --exit-code go.sum
Expand All @@ -58,20 +56,20 @@ go.tidy:

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

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

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

.PHONY: format
format: ## Update dependences with mod tidy.
@$(MAKE) go.tidy
format: go.tidy

.PHONY: clean
clean: ## Remove all files that are created during builds.
@$(MAKE) go.clean
clean: go.clean
Loading