Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use docker to run makefile tasks #4893

Merged
merged 1 commit into from
Jan 9, 2020
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
102 changes: 76 additions & 26 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,28 @@

.DEFAULT_GOAL:=help

.EXPORT_ALL_VARIABLES:

ifndef VERBOSE
.SILENT:
endif

# set default shell
SHELL = /bin/bash

# Use the 0.0 tag for testing, it shouldn't clobber any release builds
TAG ?= master
DOCKER ?= docker

# Use docker to run makefile tasks
USE_DOCKER ?= true

# Disable run docker tasks if running in prow.
# only checks the existence of the variable, not the value.
ifdef DIND_TASKS
USE_DOCKER=false
endif

# e2e settings
# Allow limiting the scope of the e2e tests. By default run everything
FOCUS ?= .*
Expand All @@ -31,12 +49,6 @@ SLOW_E2E_THRESHOLD ?= 50
# run e2e test suite with tests that check for memory leaks? (default is false)
E2E_CHECK_LEAKS ?=

# fix sed for osx
SED_I ?= sed -i
ifeq ($(GOHOSTOS),darwin)
SED_I=sed -i ''
endif

REPO_INFO ?= $(shell git config --get remote.origin.url)
GIT_COMMIT ?= git-$(shell git rev-parse --short HEAD)

Expand All @@ -54,27 +66,17 @@ MULTI_ARCH_IMAGE = $(REGISTRY)/nginx-ingress-controller-${ARCH}
GOHOSTOS ?= $(shell go env GOHOSTOS)
GOARCH = ${ARCH}
GOOS = linux

GOBUILD_FLAGS := -v

# fix sed for osx
SED_I ?= sed -i
ifeq ($(GOHOSTOS),darwin)
SED_I=sed -i ''
endif

# use vendor directory instead of go modules https://github.com/golang/go/wiki/Modules
GO111MODULE=off

export ARCH
export TAG
export PKG
export GOARCH
export GOOS
export GO111MODULE
export GIT_COMMIT
export GOBUILD_FLAGS
export REPO_INFO
export BUSTED_ARGS
export IMAGE
export E2E_NODES
export E2E_CHECK_LEAKS
export SLOW_E2E_THRESHOLD

# Set default base image dynamically for each arch
BASEIMAGE?=quay.io/kubernetes-ingress-controller/nginx-$(ARCH):422f554ba9cb291b4402306d77e218dff63ffab4

Expand All @@ -86,7 +88,6 @@ ifeq ($(ARCH),arm64)
endif

TEMP_DIR := $(shell mktemp -d)

DOCKERFILE := $(TEMP_DIR)/rootfs/Dockerfile

help: ## Display this help
Expand Down Expand Up @@ -154,39 +155,88 @@ push: .push-$(ARCH) ## Publish image for a particular arch.

.PHONY: build
build: ## Build ingress controller, debug tool and pre-stop hook.
ifeq ($(USE_DOCKER), true)
@build/run-in-docker.sh \
PKG=$(PKG) \
ARCH=$(PKG) \
GIT_COMMIT=$(GIT_COMMIT) \
REPO_INFO=$(REPO_INFO) \
TAG=$(TAG) \
GOBUILD_FLAGS=$(GOBUILD_FLAGS) \
build/build.sh
else
@build/build.sh
endif

.PHONY: build-plugin
build-plugin: ## Build ingress-nginx krew plugin.
ifeq ($(USE_DOCKER), true)
@build/run-in-docker.sh \
PKG=$(PKG) \
ARCH=$(PKG) \
GIT_COMMIT=$(GIT_COMMIT) \
REPO_INFO=$(REPO_INFO) \
TAG=$(TAG) \
GOBUILD_FLAGS=$(GOBUILD_FLAGS) \
build/build-plugin.sh
else
@build/build-plugin.sh
endif

.PHONY: clean
clean: ## Remove .gocache directory.
rm -rf bin/ .gocache/

.PHONY: static-check
static-check: ## Run verification script for boilerplate, codegen, gofmt, golint and lualint.
ifeq ($(USE_DOCKER), true)
@build/run-in-docker.sh \
build/static-check.sh
else
@build/static-check.sh
endif

.PHONY: test
test: ## Run go unit tests.
ifeq ($(USE_DOCKER), true)
@build/run-in-docker.sh \
PKG=$(PKG) \
ARCH=$(PKG) \
GIT_COMMIT=$(GIT_COMMIT) \
REPO_INFO=$(REPO_INFO) \
TAG=$(TAG) \
GOBUILD_FLAGS=$(GOBUILD_FLAGS) \
build/test.sh
else
@build/test.sh
endif

.PHONY: lua-test
lua-test: ## Run lua unit tests.
ifeq ($(USE_DOCKER), true)
@build/run-in-docker.sh \
BUSTED_ARGS=$(BUSTED_ARGS) \
build/test-lua.sh
else
@build/test-lua.sh
endif

.PHONY: e2e-test
e2e-test: ## Run e2e tests (expects access to a working Kubernetes cluster).
@build/run-e2e-suite.sh

.PHONY: e2e-test-image
e2e-test-image: e2e-test-binary ## Build image for e2e tests.
make -C test/e2e-image
@make -C test/e2e-image

.PHONY: e2e-test-binary
e2e-test-binary: ## Build ginkgo binary for e2e tests.
ifeq ($(USE_DOCKER), true)
@build/run-in-docker.sh \
ginkgo build ./test/e2e
else
@ginkgo build ./test/e2e
endif

.PHONY: cover
cover: ## Run go coverage unit tests.
Expand Down Expand Up @@ -217,7 +267,7 @@ dep-ensure: ## Update and vendo go dependencies.

.PHONY: dev-env
dev-env: ## Starts a local Kubernetes cluster using minikube, building and deploying the ingress controller.
@build/dev-env.sh
@USE_DOCKER=false build/dev-env.sh

.PHONY: live-docs
live-docs: ## Build and launch a local copy of the documentation website in http://localhost:3000
Expand All @@ -239,7 +289,7 @@ misspell: ## Check for spelling errors.

.PHONY: kind-e2e-test
kind-e2e-test: ## Run e2e tests using kind.
test/e2e/run.sh
@test/e2e/run.sh

.PHONY: run-ingress-controller
run-ingress-controller: ## Run the ingress controller locally using a kubectl proxy connection.
Expand Down
2 changes: 1 addition & 1 deletion build/test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -34,5 +34,5 @@ export GODEBUG=netdns=cgo+2
# use vendor directory instead of go modules https://github.com/golang/go/wiki/Modules
export GO111MODULE=off

go test -v -race \
go test -v \
$(go list "${PKG}/..." | grep -v vendor | grep -v '/test/e2e' | grep -v images | grep -v "docs/examples")
2 changes: 1 addition & 1 deletion images/httpbin/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ ARCH ?= $(shell go env GOARCH)
GOARCH = ${ARCH}

# Set default base image dynamically for each arch
BASEIMAGE?=quay.io/kubernetes-ingress-controller/debian-base-$(ARCH):0.1
BASEIMAGE=quay.io/kubernetes-ingress-controller/debian-base-$(ARCH):0.1

ALL_ARCH = amd64 arm arm64

Expand Down
1 change: 1 addition & 0 deletions test/e2e-image/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ RUN apk add -U --no-cache \
bash \
curl \
tzdata \
libc6-compat \
openssl

COPY --from=BASE /go/bin/ginkgo /usr/local/bin/
Expand Down
15 changes: 14 additions & 1 deletion test/e2e-image/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,22 @@ all: container

DIR:=$(shell dirname $(realpath $(firstword $(MAKEFILE_LIST))))

# Use docker to run makefile tasks
USE_DOCKER ?= true

# Disable run docker tasks if running in prow.
# only checks the existence of the variable, not the value.
ifdef DIND_TASKS
USE_DOCKER=false
endif

.PHONY: container
container:
${DIR}/../../build/run-in-docker.sh make e2e-test-binary
ifeq ($(USE_DOCKER), true)
@${DIR}/../../build/run-in-docker.sh make e2e-test-binary
else
@make -C ${DIR}/../../ e2e-test-binary
endif

cp ../e2e/e2e.test .
cp ../e2e/wait-for-nginx.sh .
Expand Down