Skip to content

Commit

Permalink
Merge pull request #4299 from aledbf/cleanup
Browse files Browse the repository at this point in the history
Fix scripts to be able to run tests in docker
  • Loading branch information
k8s-ci-robot authored Jul 17, 2019
2 parents a54ab33 + d5c7fa8 commit 84af99b
Show file tree
Hide file tree
Showing 8 changed files with 45 additions and 41 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -47,3 +47,5 @@ gh-pages
/bin/

test/e2e-image/wait-for-nginx\.sh

.cache
23 changes: 6 additions & 17 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ PKG = k8s.io/ingress-nginx

ARCH ?= $(shell go env GOARCH)
GOARCH = ${ARCH}
DUMB_ARCH = ${ARCH}


GOBUILD_FLAGS := -v

Expand All @@ -56,13 +56,9 @@ BUSTED_ARGS =-v --pattern=_test

GOOS = linux

IMGNAME = nginx-ingress-controller
IMAGE = $(REGISTRY)/$(IMGNAME)

MULTI_ARCH_IMG = ${IMAGE}-${ARCH}
MULTI_ARCH_IMAGE = $(REGISTRY)/nginx-ingress-controller-${ARCH}

export ARCH
export DUMB_ARCH
export TAG
export PKG
export GOARCH
Expand Down Expand Up @@ -116,7 +112,6 @@ container: clean-container .container-$(ARCH)
cp -RP ./* $(TEMP_DIR)
$(SED_I) "s|BASEIMAGE|$(BASEIMAGE)|g" $(DOCKERFILE)
$(SED_I) "s|QEMUARCH|$(QEMUARCH)|g" $(DOCKERFILE)
$(SED_I) "s|DUMB_ARCH|$(DUMB_ARCH)|g" $(DOCKERFILE)

ifeq ($(ARCH),amd64)
# When building "normally" for amd64, remove the whole line, it has no part in the amd64 image
Expand All @@ -127,16 +122,13 @@ else
$(SED_I) "s/CROSS_BUILD_//g" $(DOCKERFILE)
endif

@$(DOCKER) build --no-cache --pull -t $(MULTI_ARCH_IMG):$(TAG) $(TEMP_DIR)/rootfs
echo "Building docker image..."
$(DOCKER) build --no-cache --pull -t $(MULTI_ARCH_IMAGE):$(TAG) $(TEMP_DIR)/rootfs

ifeq ($(ARCH), amd64)
# This is for maintaining backward compatibility
@$(DOCKER) tag $(MULTI_ARCH_IMG):$(TAG) $(IMAGE):$(TAG)
endif

.PHONY: clean-container
clean-container:
@$(DOCKER) rmi -f $(MULTI_ARCH_IMG):$(TAG) || true
@$(DOCKER) rmi -f $(MULTI_ARCH_IMAGE):$(TAG) || true

.PHONY: register-qemu
register-qemu:
Expand All @@ -148,10 +140,7 @@ push: .push-$(ARCH)

.PHONY: .push-$(ARCH)
.push-$(ARCH):
$(DOCKER) push $(MULTI_ARCH_IMG):$(TAG)
ifeq ($(ARCH), amd64)
$(DOCKER) push $(IMAGE):$(TAG)
endif
$(DOCKER) push $(MULTI_ARCH_IMAGE):$(TAG)

.PHONY: build
build:
Expand Down
39 changes: 25 additions & 14 deletions build/run-in-docker.sh
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,20 @@ set -o errexit
set -o nounset
set -o pipefail

# temporal directory for the fake SSL certificate
SSL_VOLUME=$(mktemp -d)

function cleanup {
rm -rf "${SSL_VOLUME}"
}
trap cleanup EXIT

E2E_IMAGE=quay.io/kubernetes-ingress-controller/e2e:v06262019-ecce3fd7b

DOCKER_OPTS=${DOCKER_OPTS:-}

KUBE_ROOT=$(cd $(dirname "${BASH_SOURCE}")/.. && pwd -P)

FLAGS=$@

PKG=k8s.io/ingress-nginx
Expand All @@ -34,20 +44,21 @@ ARCH=$(go env GOARCH)
MINIKUBE_PATH=${HOME}/.minikube
MINIKUBE_VOLUME="-v ${MINIKUBE_PATH}:${MINIKUBE_PATH}"
if [ ! -d "${MINIKUBE_PATH}" ]; then
echo "Minikube directory not found! Volume will be excluded from docker build."
MINIKUBE_VOLUME=""
echo "Minikube directory not found! Volume will be excluded from docker build."
MINIKUBE_VOLUME=""
fi

docker run \
--tty \
--rm \
${DOCKER_OPTS} \
-v "${HOME}/.kube:${HOME}/.kube" \
-v "${PWD}:/go/src/${PKG}" \
-v "${PWD}/.gocache:${HOME}/.cache/go-build" \
-v "${PWD}/bin/${ARCH}:/go/bin/linux_${ARCH}" \
-v "/var/run/docker.sock:/var/run/docker.sock" \
${MINIKUBE_VOLUME} \
-w "/go/src/${PKG}" \
-u $(id -u ${USER}):$(id -g ${USER}) \
docker run \
--tty \
--rm \
${DOCKER_OPTS} \
-e GOCACHE="/go/src/${PKG}/.cache" \
-v "${HOME}/.kube:${HOME}/.kube" \
-v "${KUBE_ROOT}:/go/src/${PKG}" \
-v "${KUBE_ROOT}/bin/${ARCH}:/go/bin/linux_${ARCH}" \
-v "/var/run/docker.sock:/var/run/docker.sock" \
-v "${SSL_VOLUME}:/etc/ingress-controller/ssl/" \
${MINIKUBE_VOLUME} \
-w "/go/src/${PKG}" \
-u $(id -u ${USER}):$(id -g ${USER}) \
${E2E_IMAGE} /bin/bash -c "${FLAGS}"
3 changes: 2 additions & 1 deletion build/run-ingress-controller.sh
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ POD_NAMESPACE="invalid-namespace"
POD_NAME="invalid-namespace"

export TAG=local
export IMAGE

if [[ "${ARCH}" != "amd64" ]]; then
echo -e "${BGREEN}Register ${RED}/usr/bin/qemu-ARCH-static${BGREEN} as the handler for binaries in multiple platforms${NC}"
Expand Down Expand Up @@ -102,7 +103,7 @@ docker run \
-v "${SSL_VOLUME}:/etc/ingress-controller/ssl/" \
-v "${HOME}/.kube:${HOME}/.kube:ro" \
${MINIKUBE_VOLUME} \
"${IMAGE}-${ARCH}:local" /nginx-ingress-controller \
"${IMAGE}:${TAG}" /nginx-ingress-controller \
--update-status=false \
--v=2 \
--apiserver-host=http://0.0.0.0:8001 \
Expand Down
1 change: 0 additions & 1 deletion images/custom-error-pages/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ endif

ARCH ?= $(shell go env GOARCH)
GOARCH = ${ARCH}
DUMB_ARCH = ${ARCH}

BASEIMAGE?=alpine:3.9

Expand Down
4 changes: 2 additions & 2 deletions internal/ingress/controller/nginx_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -262,14 +262,14 @@ func TestConfigureDynamically(t *testing.T) {
func TestConfigureCertificates(t *testing.T) {
listener, err := net.Listen("unix", nginx.StatusSocket)
if err != nil {
t.Errorf("crating unix listener: %s", err)
t.Fatalf("crating unix listener: %s", err)
}
defer listener.Close()
defer os.Remove(nginx.StatusSocket)

streamListener, err := net.Listen("unix", nginx.StreamSocket)
if err != nil {
t.Errorf("crating unix listener: %s", err)
t.Fatalf("crating unix listener: %s", err)
}
defer streamListener.Close()
defer os.Remove(nginx.StreamSocket)
Expand Down
11 changes: 5 additions & 6 deletions test/e2e-image/Makefile
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
IMAGE=nginx-ingress-controller:e2e

.PHONY: all container getbins clean

.PHONY: all
all: container

.PHONY: container
container:
make -C ../../ e2e-test-binary

Expand All @@ -12,8 +10,9 @@ container:
cp -r ../../deploy/cloud-generic .
cp -r ../../deploy/cluster-wide .

docker build -t $(IMAGE) .
docker build -t nginx-ingress-controller:e2e .

.PHONY: clean
clean:
rm -rf _cache e2e.test kubectl cluster ginkgo
docker rmi -f $(IMAGE) || true
docker rmi -f nginx-ingress-controller:e2e || true
3 changes: 3 additions & 0 deletions test/e2e/run.sh
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,9 @@ echo "[dev-env] building container"
make -C ${DIR}/../../ build container
make -C ${DIR}/../../ e2e-test-image

# Remove after https://github.com/kubernetes/ingress-nginx/pull/4271 is merged
docker tag ${REGISTRY}/nginx-ingress-controller-${ARCH}:${TAG} ${REGISTRY}/nginx-ingress-controller:${TAG}

echo "[dev-env] copying docker images to cluster..."
kind load docker-image --name="${KIND_CLUSTER_NAME}" nginx-ingress-controller:e2e
kind load docker-image --name="${KIND_CLUSTER_NAME}" ${REGISTRY}/nginx-ingress-controller:${TAG}
Expand Down

0 comments on commit 84af99b

Please sign in to comment.