Use docker to build go binaries

This commit is contained in:
Manuel de Brito Fontes 2018-07-05 23:23:27 -04:00 committed by Manuel Alejandro de Brito Fontes
parent 5827c981af
commit 479a519630
No known key found for this signature in database
GPG key ID: 786136016A8BA02A
14 changed files with 411 additions and 107 deletions

33
build/Dockerfile Normal file
View file

@ -0,0 +1,33 @@
# Copyright 2018 The Kubernetes Authors. All rights reserved.
#
# 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.
FROM golang:1.10.3-stretch
RUN apt update \
&& apt install -y --no-install-recommends \
luarocks \
&& apt-get clean -y \
&& rm -rf \
/var/cache/debconf/* \
/var/lib/apt/lists/* \
/var/log/* \
/tmp/* \
/var/tmp/*
RUN luarocks install luacheck \
&& luarocks install busted 2.0.rc12 \
&& luarocks install lua-cjson 2.1.0-1
RUN go get github.com/onsi/ginkgo/ginkgo \
&& go get golang.org/x/lint/golint

53
build/build.sh Executable file
View file

@ -0,0 +1,53 @@
#!/bin/bash
# Copyright 2018 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.
set -o errexit
set -o nounset
set -o pipefail
if [ -z "${PKG}" ]; then
echo "PKG must be set"
exit 1
fi
if [ -z "${ARCH}" ]; then
echo "ARCH must be set"
exit 1
fi
if [ -z "${GIT_COMMIT}" ]; then
echo "GIT_COMMIT must be set"
exit 1
fi
if [ -z "${REPO_INFO}" ]; then
echo "REPO_INFO must be set"
exit 1
fi
if [ -z "${TAG}" ]; then
echo "TAG must be set"
exit 1
fi
if [ -z "${TAG}" ]; then
echo "TAG must be set"
exit 1
fi
export CGO_ENABLED=0
go build -a -installsuffix cgo \
-ldflags "-s -w \
-X ${PKG}/version.RELEASE=${TAG} \
-X ${PKG}/version.COMMIT=${GIT_COMMIT} \
-X ${PKG}/version.REPO=${REPO_INFO}" \
-o bin/${ARCH}/nginx-ingress-controller ${PKG}/cmd/nginx

35
build/cover.sh Executable file
View file

@ -0,0 +1,35 @@
#!/bin/bash
# Copyright 2018 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.
set -o errexit
set -o nounset
set -o pipefail
if [ -z "${PKG}" ]; then
echo "PKG must be set"
exit 1
fi
rm -rf coverage.txt
for d in `go list ${PKG}/... | grep -v vendor | grep -v '/test/e2e' | grep -v images`; do
t=$(date +%s);
go test -coverprofile=cover.out -covermode=atomic $d || exit 1;
echo "Coverage test $d took $(($(date +%s)-$t)) seconds";
if [ -f cover.out ]; then
cat cover.out >> coverage.txt;
rm cover.out;
fi;
done

54
build/dev-env.sh Executable file
View file

@ -0,0 +1,54 @@
#!/bin/bash
# Copyright 2018 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.
set -o errexit
set -o nounset
set -o pipefail
SKIP_MINIKUBE_START=${SKIP_MINIKUBE_START:-}
NAMESPACE="${NAMESPACE:-ingress-nginx}"
echo "NAMESPACE is set to ${NAMESPACE}"
export TAG=dev
export ARCH=amd64
export REGISTRY=${REGISTRY:-ingress-controller}
DEV_IMAGE=${REGISTRY}/nginx-ingress-controller:${TAG}
echo "[dev-env] building container"
make build container
if [ -z "${SKIP_MINIKUBE_START}" ]; then
test $(minikube status | grep Running | wc -l) -eq 2 && $(minikube status | grep -q 'Correctly Configured') || minikube start \
--extra-config=kubelet.sync-frequency=1s \
--extra-config=apiserver.authorization-mode=RBAC
fi
docker save "${DEV_IMAGE}" | (eval $(minikube docker-env) && docker load) || true
echo "[dev-env] installing kubectl"
kubectl version || brew install kubectl
echo "[dev-env] deploying NGINX Ingress controller in namespace $NAMESPACE"
cat ./deploy/mandatory.yaml | kubectl apply --namespace=$NAMESPACE -f -
cat ./deploy/provider/baremetal/service-nodeport.yaml | kubectl apply --namespace=$NAMESPACE -f -
echo "updating image..."
kubectl set image \
deployments \
--namespace ingress-nginx \
--selector app=ingress-nginx \
nginx-ingress-controller=${DEV_IMAGE}

66
build/e2e-tests.sh Executable file
View file

@ -0,0 +1,66 @@
#!/bin/bash
# Copyright 2018 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.
set -o errexit
set -o nounset
set -o pipefail
if [ -z "${PKG}" ]; then
echo "PKG must be set"
exit 1
fi
if [ -z "${FOCUS}" ]; then
echo "FOCUS must be set"
exit 1
fi
if [ -z "${E2E_NODES}" ]; then
echo "E2E_NODES must be set"
exit 1
fi
SCRIPT_ROOT=$(dirname ${BASH_SOURCE})/..
mkdir -p ${SCRIPT_ROOT}/test/binaries
TEST_BINARIES=$( cd "${SCRIPT_ROOT}/test/binaries" ; pwd -P )
export PATH=${TEST_BINARIES}:$PATH
if ! [ -x "$(command -v kubectl)" ]; then
echo "downloading kubectl..."
curl -sSLo ${TEST_BINARIES}/kubectl \
https://storage.googleapis.com/kubernetes-release/release/v1.11.0/bin/linux/amd64/kubectl
chmod +x ${TEST_BINARIES}/kubectl
fi
if ! [ -x "$(command -v minikube)" ]; then
echo "downloading minikube..."
curl -sSLo ${TEST_BINARIES}/minikube \
https://storage.googleapis.com/minikube/releases/latest/minikube-linux-amd64
chmod +x ${TEST_BINARIES}/minikube
fi
ginkgo build ./test/e2e
ginkgo \
-randomizeSuites \
-randomizeAllSpecs \
-flakeAttempts=2 \
--focus=${FOCUS} \
-p \
-trace \
-nodes=${E2E_NODES} \
test/e2e/e2e.test

79
build/go-in-docker.sh Executable file
View file

@ -0,0 +1,79 @@
#!/bin/bash
# Copyright 2018 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.
set -o errexit
set -o nounset
set -o pipefail
if [ -z "${PKG}" ]; then
echo "PKG must be set"
exit 1
fi
if [ -z "${ARCH}" ]; then
echo "ARCH must be set"
exit 1
fi
if [ -z "${GIT_COMMIT}" ]; then
echo "GIT_COMMIT must be set"
exit 1
fi
if [ -z "${REPO_INFO}" ]; then
echo "REPO_INFO must be set"
exit 1
fi
if [ -z "${TAG}" ]; then
echo "TAG must be set"
exit 1
fi
if [ -z "${HOME}" ]; then
echo "HOME must be set"
exit 1
fi
DOCKER_OPTS=${DOCKER_OPTS:-""}
docker build -t ingress-nginx:build build
FLAGS=$@
tee .env << EOF
PKG=${PKG:-""}
ARCH=${ARCH:-""}
GIT_COMMIT=${GIT_COMMIT:-""}
E2E_NODES=${E2E_NODES:-3}
FOCUS=${FOCUS:-.*}
TAG=${TAG:-"0.0"}
HOME=${HOME:-/root}
KUBECONFIG=${HOME}/.kube/config
GOARCH=${GOARCH}
PWD=${PWD}
BUSTED_ARGS=${BUSTED_ARGS:-""}
REPO_INFO=${REPO_INFO:-local}
EOF
docker run \
--tty \
--rm \
${DOCKER_OPTS} \
-v ${HOME}/.kube:/${HOME}/.kube \
-v ${HOME}/.minikube:${HOME}/.minikube \
-v ${PWD}:/go/src/${PKG} \
-v ${PWD}/bin/${ARCH}:/go/bin/linux_${ARCH} \
-w /go/src/${PKG} \
--env-file .env \
ingress-nginx:build ${FLAGS}
rm .env

28
build/static-check.sh Executable file
View file

@ -0,0 +1,28 @@
#!/bin/bash
# Copyright 2018 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.
set -o errexit
set -o nounset
set -o pipefail
if [ -z "${PKG}" ]; then
echo "PKG must be set"
exit 1
fi
hack/verify-all.sh
luacheck -q rootfs/etc/nginx/lua/

21
build/test-lua.sh Executable file
View file

@ -0,0 +1,21 @@
#!/bin/bash
# Copyright 2018 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.
set -o errexit
set -o nounset
set -o pipefail
busted ${BUSTED_ARGS} ./rootfs/etc/nginx/lua/test;

27
build/test.sh Executable file
View file

@ -0,0 +1,27 @@
#!/bin/bash
# Copyright 2018 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.
set -o errexit
set -o nounset
set -o pipefail
if [ -z "${PKG}" ]; then
echo "PKG must be set"
exit 1
fi
go test -v -race -tags "cgo" \
$(go list ${PKG}/... | grep -v vendor | grep -v '/test/e2e' | grep -v images | grep -v "docs/examples")