Skip to content

Commit

Permalink
feat(docker) separate out the ability to build a docker image (#16)
Browse files Browse the repository at this point in the history
  • Loading branch information
hutchic authored Jan 15, 2019
1 parent 6784826 commit df085f8
Show file tree
Hide file tree
Showing 4 changed files with 51 additions and 34 deletions.
11 changes: 10 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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) \
Expand Down Expand Up @@ -101,14 +102,22 @@ 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) \
KONG_VERSION=$(KONG_VERSION) \
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

Expand Down
9 changes: 9 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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:*
Expand Down
31 changes: 31 additions & 0 deletions test/build_container.sh
Original file line number Diff line number Diff line change
@@ -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 .
34 changes: 1 addition & 33 deletions test/run_tests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down

0 comments on commit df085f8

Please sign in to comment.