Skip to content

Commit

Permalink
Add script to check go version and fix output directory permissions (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
aledbf authored Jan 9, 2020
1 parent fcd3a58 commit 42351d3
Show file tree
Hide file tree
Showing 3 changed files with 65 additions and 13 deletions.
30 changes: 17 additions & 13 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -154,11 +154,11 @@ push: .push-$(ARCH) ## Publish image for a particular arch.
$(DOCKER) push $(MULTI_ARCH_IMAGE):$(TAG)

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

.PHONY: build-plugin
build-plugin: ## Build ingress-nginx krew plugin.
build-plugin: check-go-version ## Build ingress-nginx krew plugin.
ifeq ($(USE_DOCKER), true)
@build/run-in-docker.sh \
PKG=$(PKG) \
ARCH=$(PKG) \
ARCH=$(ARCH) \
GIT_COMMIT=$(GIT_COMMIT) \
REPO_INFO=$(REPO_INFO) \
TAG=$(TAG) \
Expand All @@ -197,11 +197,11 @@ else
endif

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

.PHONY: e2e-test
e2e-test: ## Run e2e tests (expects access to a working Kubernetes cluster).
e2e-test: check-go-version ## 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

.PHONY: e2e-test-binary
e2e-test-binary: ## Build ginkgo binary for e2e tests.
e2e-test-binary: check-go-version ## Build ginkgo binary for e2e tests.
ifeq ($(USE_DOCKER), true)
@build/run-in-docker.sh \
ginkgo build ./test/e2e
Expand All @@ -239,7 +239,7 @@ else
endif

.PHONY: cover
cover: ## Run go coverage unit tests.
cover: check-go-version ## Run go coverage unit tests.
@build/cover.sh
echo "Uploading coverage results..."
@curl -s https://codecov.io/bash | bash
Expand All @@ -260,13 +260,13 @@ check_dead_links: ## Check if the documentation contains dead links.
--allow-redirect $(shell find $$PWD -mindepth 1 -name "*.md" -printf '%P\n' | grep -v vendor | grep -v Changelog.md)

.PHONY: dep-ensure
dep-ensure: ## Update and vendo go dependencies.
dep-ensure: check-go-version ## Update and vendo go dependencies.
go mod tidy -v
find vendor -name '*_test.go' -delete
go mod vendor

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

.PHONY: live-docs
Expand All @@ -280,17 +280,21 @@ build-docs: ## Build documentation (output in ./site directory).
@docker run --rm -v ${PWD}:/docs ingress-nginx/mkdocs build

.PHONY: misspell
misspell: ## Check for spelling errors.
misspell: check-go-version ## Check for spelling errors.
@go get github.com/client9/misspell/cmd/misspell
misspell \
-locale US \
-error \
cmd/* internal/* deploy/* docs/* design/* test/* README.md

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

.PHONY: run-ingress-controller
run-ingress-controller: ## Run the ingress controller locally using a kubectl proxy connection.
@build/run-ingress-controller.sh

.PHONY: check-go-version
check-go-version:
@hack/check-go-version.sh
3 changes: 3 additions & 0 deletions build/run-in-docker.sh
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,9 @@ if [ ! -d "${MINIKUBE_PATH}" ]; then
MINIKUBE_VOLUME=""
fi

# create output directory as current user to avoid problem with docker.
mkdir -p "${KUBE_ROOT}/bin" "${KUBE_ROOT}/bin/${ARCH}"

docker run \
--tty \
--rm \
Expand Down
45 changes: 45 additions & 0 deletions hack/check-go-version.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
#!/bin/bash

# Copyright 2020 The Kubernetes Authors.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

if [ -n "$DEBUG" ]; then
set -x
fi

set -o errexit
set -o nounset
set -o pipefail

MINIMUM_GO_VERSION=go1.13

if [[ -z "$(command -v go)" ]]; then
echo "
Can't find 'go' in PATH, please fix and retry.
See http://golang.org/doc/install for installation instructions.
"
exit 1
fi

IFS=" " read -ra go_version <<< "$(go version)"

if [[ "${MINIMUM_GO_VERSION}" != $(echo -e "${MINIMUM_GO_VERSION}\n${go_version[2]}" | sort -s -t. -k 1,1 -k 2,2n -k 3,3n | head -n1) && "${go_version[2]}" != "devel" ]]; then
echo "
Detected go version: ${go_version[*]}.
ingress-nginx requires ${MINIMUM_GO_VERSION} or greater.
Please install ${MINIMUM_GO_VERSION} or later.
"
exit 1
fi

0 comments on commit 42351d3

Please sign in to comment.