From df085f82abe947fdb43688bbc1ba836d908cd162 Mon Sep 17 00:00:00 2001 From: Colin Hutchinson Date: Tue, 15 Jan 2019 15:13:28 -0500 Subject: [PATCH] feat(docker) separate out the ability to build a docker image (#16) --- Makefile | 11 ++++++++++- README.md | 9 +++++++++ test/build_container.sh | 31 +++++++++++++++++++++++++++++++ test/run_tests.sh | 34 +--------------------------------- 4 files changed, 51 insertions(+), 34 deletions(-) create mode 100755 test/build_container.sh diff --git a/Makefile b/Makefile index 44b5909d680d..8080bda50dd3 100644 --- a/Makefile +++ b/Makefile @@ -22,6 +22,7 @@ KONG_LICENSE?="ASL 2.0" KONG_SOURCE_LOCATION?="$$PWD/../kong/" KONG_VERSION?="0.0.0" PRIVATE_REPOSITORY?=true +KONG_TEST_CONTAINER_NAME?=localhost:5000/kong release-kong: test RESTY_IMAGE_BASE=$(RESTY_IMAGE_BASE) \ @@ -101,7 +102,7 @@ else endif .PHONY: test -test: +test: build_test_container [[ -d helm ]] || git clone --single-branch -b kong/1.0 https://github.com/hutchic/charts.git helm RESTY_IMAGE_BASE=$(RESTY_IMAGE_BASE) \ RESTY_IMAGE_TAG=$(RESTY_IMAGE_TAG) \ @@ -109,6 +110,14 @@ test: KONG_PACKAGE_NAME=$(KONG_PACKAGE_NAME) \ test/run_tests.sh +build_test_container: + RESTY_IMAGE_BASE=$(RESTY_IMAGE_BASE) \ + RESTY_IMAGE_TAG=$(RESTY_IMAGE_TAG) \ + KONG_VERSION=$(KONG_VERSION) \ + KONG_PACKAGE_NAME=$(KONG_PACKAGE_NAME) \ + KONG_TEST_CONTAINER_NAME=$(KONG_TEST_CONTAINER_NAME) \ + test/build_container.sh + cleanup_tests: -sudo minikube delete diff --git a/README.md b/README.md index dd19d269ca50..ffd816e2bff7 100644 --- a/README.md +++ b/README.md @@ -43,6 +43,15 @@ export REDHAT_USERNAME=rhuser export REDHAT_PASSWORD=password ``` +## Building a Container + +Sometimes it's useful to have a docker image with the Kong asset installed that you just built. + +``` +export KONG_TEST_CONTAINER_NAME=kong:testing +make build_test_container +``` + ## Testing *Prerequisites:* diff --git a/test/build_container.sh b/test/build_container.sh new file mode 100755 index 000000000000..3aa2106b6acc --- /dev/null +++ b/test/build_container.sh @@ -0,0 +1,31 @@ +RHEL=false +if [ "$RESTY_IMAGE_BASE" == "alpine" ]; then + DOCKER_FILE="Dockerfile.alpine" +elif [ "$RESTY_IMAGE_BASE" == "ubuntu" ] || [ "$RESTY_IMAGE_BASE" == "debian" ]; then + DOCKER_FILE="Dockerfile.deb" +elif [ "$RESTY_IMAGE_BASE" == "centos" ]; then + DOCKER_FILE="Dockerfile.rpm" + cp output/${KONG_PACKAGE_NAME}-${KONG_VERSION}.el${RESTY_IMAGE_TAG}.noarch.rpm output/kong.rpm +elif [ "$RESTY_IMAGE_BASE" == "amazonlinux" ]; then + DOCKER_FILE="Dockerfile.rpm" + cp output/${KONG_PACKAGE_NAME}-${KONG_VERSION}.aws.rpm output/kong.rpm +elif [ "$RESTY_IMAGE_BASE" == "rhel" ]; then + docker pull registry.access.redhat.com/rhel${RESTY_IMAGE_TAG} + docker tag registry.access.redhat.com/rhel${RESTY_IMAGE_TAG} rhel:${RESTY_IMAGE_TAG} + DOCKER_FILE="Dockerfile.rpm" + RHEL=true +else + echo "Unrecognized base image $RESTY_IMAGE_BASE" + exit 1 +fi + +docker build \ +--build-arg RESTY_IMAGE_BASE=$RESTY_IMAGE_BASE \ +--build-arg RESTY_IMAGE_TAG=$RESTY_IMAGE_TAG \ +--build-arg KONG_VERSION=$KONG_VERSION \ +--build-arg KONG_PACKAGE_NAME=$KONG_PACKAGE_NAME \ +--build-arg RHEL=$RHEL \ +--build-arg REDHAT_USERNAME=$REDHAT_USERNAME \ +--build-arg REDHAT_PASSWORD=$REDHAT_PASSWORD \ +-f test/$DOCKER_FILE \ +-t $KONG_TEST_CONTAINER_NAME . \ No newline at end of file diff --git a/test/run_tests.sh b/test/run_tests.sh index 18fff26889ce..167c5a5351f3 100755 --- a/test/run_tests.sh +++ b/test/run_tests.sh @@ -8,39 +8,7 @@ curl -L https://github.com/Faithlife/minikube-registry-proxy/raw/master/docker-c while [[ "$(curl -s -o /dev/null -w ''%{http_code}'' localhost:5000)" != 200 ]]; do sleep 5; echo "waiting for registry to be ready" -done - -RHEL=false -if [ "$RESTY_IMAGE_BASE" == "alpine" ]; then - DOCKER_FILE="Dockerfile.alpine" -elif [ "$RESTY_IMAGE_BASE" == "ubuntu" ] || [ "$RESTY_IMAGE_BASE" == "debian" ]; then - DOCKER_FILE="Dockerfile.deb" -elif [ "$RESTY_IMAGE_BASE" == "centos" ]; then - DOCKER_FILE="Dockerfile.rpm" - cp output/${KONG_PACKAGE_NAME}-${KONG_VERSION}.el${RESTY_IMAGE_TAG}.noarch.rpm output/kong.rpm -elif [ "$RESTY_IMAGE_BASE" == "amazonlinux" ]; then - DOCKER_FILE="Dockerfile.rpm" - cp output/${KONG_PACKAGE_NAME}-${KONG_VERSION}.aws.rpm output/kong.rpm -elif [ "$RESTY_IMAGE_BASE" == "rhel" ]; then - docker pull registry.access.redhat.com/rhel${RESTY_IMAGE_TAG} - docker tag registry.access.redhat.com/rhel${RESTY_IMAGE_TAG} rhel:${RESTY_IMAGE_TAG} - DOCKER_FILE="Dockerfile.rpm" - RHEL=true -else - echo "Unrecognized base image $RESTY_IMAGE_BASE" - exit 1 -fi - -docker build \ ---build-arg RESTY_IMAGE_BASE=$RESTY_IMAGE_BASE \ ---build-arg RESTY_IMAGE_TAG=$RESTY_IMAGE_TAG \ ---build-arg KONG_VERSION=$KONG_VERSION \ ---build-arg KONG_PACKAGE_NAME=$KONG_PACKAGE_NAME \ ---build-arg RHEL=$RHEL \ ---build-arg REDHAT_USERNAME=$REDHAT_USERNAME \ ---build-arg REDHAT_PASSWORD=$REDHAT_PASSWORD \ --f test/$DOCKER_FILE \ --t localhost:5000/kong . +done docker push localhost:5000/kong