Skip to content

Commit

Permalink
feat(pdk) ability to run the Kong PDK test suite (#232)
Browse files Browse the repository at this point in the history
* chore(ci) ability to test PDK tests

* chore(ci) cleanup the docker image size

* chore(ci) applying patches can already fail

* chore(cache) build Kong in the openresty container so we have cached luarocks

* chore(ci) further improve the test docker image size

* chore(ci) ability to split the integration tests

* chore(ci) add valgrind to the testing toolset

* chore(openresty) build by default with debug flag set

BREAKING CHANGE: requires setting debug=0 environment variable

* chore(ci) add the psql client

* chore(ci) default to debug 0
  • Loading branch information
hutchic authored Mar 17, 2020
1 parent 860a2f5 commit 13e5cd9
Show file tree
Hide file tree
Showing 7 changed files with 64 additions and 49 deletions.
4 changes: 4 additions & 0 deletions Jenkinsfile
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ pipeline {
}
}
environment {
DEBUG = 0
PACKAGE_TYPE = "rpm"
RESTY_IMAGE_BASE = "rhel"
PATH = "/home/ubuntu/bin/:${env.PATH}"
Expand All @@ -114,6 +115,7 @@ pipeline {
}
}
environment {
DEBUG = 0
PACKAGE_TYPE = "rpm"
RESTY_IMAGE_BASE = "centos"
PATH = "/home/ubuntu/bin/:${env.PATH}"
Expand All @@ -134,6 +136,7 @@ pipeline {
}
}
environment {
DEBUG = 0
PACKAGE_TYPE = "deb"
RESTY_IMAGE_BASE = "debian"
PATH = "/home/ubuntu/bin/:${env.PATH}"
Expand All @@ -158,6 +161,7 @@ pipeline {
retry(2)
}
environment {
DEBUG = 0
PACKAGE_TYPE = "deb"
RESTY_IMAGE_BASE = "ubuntu"
PATH = "/home/ubuntu/bin/:${env.PATH}"
Expand Down
29 changes: 14 additions & 15 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ KONG_NETTLE_VERSION ?= `grep KONG_NETTLE_VERSION $(KONG_SOURCE_LOCATION)/.requir
OPENRESTY_PATCHES ?= 1
LIBYAML_VERSION ?= 0.2.1
DOCKER_KONG_VERSION ?= master
DEBUG ?= 0

DOCKER_MACHINE_ARM64_NAME?=docker-machine-arm64-${USER}

Expand Down Expand Up @@ -69,9 +70,9 @@ BUILD_TOOLS_SHA=$$(git rev-parse --short HEAD)
KONG_SHA=$$(git --git-dir=$(KONG_SOURCE_LOCATION)/.git rev-parse --short HEAD)

DOCKER_BASE_SUFFIX=${BUILD_TOOLS_SHA}${CACHE_BUSTER}
DOCKER_OPENRESTY_SUFFIX=${BUILD_TOOLS_SHA}-${REQUIREMENTS_SHA}${OPENRESTY_PATCHES}-${CACHE_BUSTER}
DOCKER_KONG_SUFFIX=${BUILD_TOOLS_SHA}${OPENRESTY_PATCHES}-${KONG_VERSION}-${KONG_SHA}-${CACHE_BUSTER}
DOCKER_TEST_SUFFIX=${BUILD_TOOLS_SHA}-${KONG_SHA}-${CACHE_BUSTER}
DOCKER_OPENRESTY_SUFFIX=${BUILD_TOOLS_SHA}-${REQUIREMENTS_SHA}${OPENRESTY_PATCHES}${DEBUG}-${CACHE_BUSTER}
DOCKER_KONG_SUFFIX=${BUILD_TOOLS_SHA}${OPENRESTY_PATCHES}${DEBUG}-${KONG_VERSION}-${KONG_SHA}-${CACHE_BUSTER}
DOCKER_TEST_SUFFIX=${BUILD_TOOLS_SHA}-${DEBUG}-${KONG_SHA}-${CACHE_BUSTER}

CACHE?=true

Expand All @@ -88,7 +89,7 @@ else
UPDATE_CACHE_COMMAND?=false
endif

DOCKER_REPOSITORY=mashape/kong-build-tools
DOCKER_REPOSITORY?=mashape/kong-build-tools

debug:
@echo ${CACHE}
Expand All @@ -98,6 +99,7 @@ debug:
@echo ${UPDATE_CACHE_COMMAND}
@echo ${DOCKER_COMMAND}
@echo ${BUILDX_INFO}
@echo ${DEBUG}

setup-ci:
ifneq ($(RESTY_IMAGE_BASE),src)
Expand Down Expand Up @@ -156,6 +158,8 @@ build-openresty:
ifeq ($(RESTY_IMAGE_BASE),src)
@echo "nothing to be done"
else
-rm -rf kong
-cp -R $(KONG_SOURCE_LOCATION) kong
$(CACHE_COMMAND) $(DOCKER_REPOSITORY):openresty-$(RESTY_IMAGE_BASE)-$(RESTY_IMAGE_TAG)-$(DOCKER_OPENRESTY_SUFFIX) || \
( $(MAKE) build-base ; \
$(DOCKER_COMMAND) -f dockerfiles/Dockerfile.openresty \
Expand All @@ -173,19 +177,10 @@ else
--build-arg KONG_GMP_VERSION=$(KONG_GMP_VERSION) \
--build-arg KONG_NETTLE_VERSION=$(KONG_NETTLE_VERSION) \
--build-arg OPENRESTY_PATCHES=$(OPENRESTY_PATCHES) \
--build-arg DEBUG=$(DEBUG) \
-t $(DOCKER_REPOSITORY):openresty-$(RESTY_IMAGE_BASE)-$(RESTY_IMAGE_TAG)-$(DOCKER_OPENRESTY_SUFFIX) . )
-$(UPDATE_CACHE_COMMAND) $(DOCKER_REPOSITORY):openresty-$(RESTY_IMAGE_BASE)-$(RESTY_IMAGE_TAG)-$(DOCKER_OPENRESTY_SUFFIX)
endif
ifeq ($(RESTY_IMAGE_TAG),'xenial')
exit 0
endif
ifeq ($(OPENRESTY_PATCHES),1)
docker run -t --rm $(DOCKER_REPOSITORY):openresty-$(RESTY_IMAGE_BASE)-$(RESTY_IMAGE_TAG)-$(DOCKER_OPENRESTY_SUFFIX) \
/bin/sh -c "test -f /work/openresty-$(RESTY_VERSION)/bundle/.patch_applied"
else
docker run -t --rm $(DOCKER_REPOSITORY):openresty-$(RESTY_IMAGE_BASE)-$(RESTY_IMAGE_TAG)-$(DOCKER_OPENRESTY_SUFFIX) \
/bin/sh -c "test -f /work/openresty-$(RESTY_VERSION)/bundle/.patch_applied || exit 0"
endif

ifeq ($(RESTY_IMAGE_BASE),src)
package-kong:
Expand All @@ -194,7 +189,11 @@ else
package-kong: actual-package-kong
endif

actual-package-kong: build-kong
actual-package-kong:
ifeq ($(DEBUG),1)
exit 1
endif
make build-kong
@$(DOCKER_COMMAND) -f dockerfiles/Dockerfile.package \
--build-arg RESTY_IMAGE_TAG="$(RESTY_IMAGE_TAG)" \
--build-arg RESTY_IMAGE_BASE=$(RESTY_IMAGE_BASE) \
Expand Down
7 changes: 6 additions & 1 deletion build-openresty.sh
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,11 @@ mkdir -p /tmp/build/usr/local/kong
mkdir -p /tmp/build/
mkdir -p /work

if [ "$DEBUG" == 1 ]
then
KONG_NGX_BUILD_ARGS="--debug"
fi

LUAROCKS_PREFIX=/usr/local \
LUAROCKS_DESTDIR=/tmp/build \
OPENRESTY_PREFIX=/usr/local/openresty \
Expand All @@ -43,7 +48,7 @@ EDITION=$EDITION \
--openssl $RESTY_OPENSSL_VERSION \
--luarocks $RESTY_LUAROCKS_VERSION \
--pcre $RESTY_PCRE_VERSION \
--work /work >> $BUILD_OUTPUT 2>&1
--work /work $KONG_NGX_BUILD_ARGS >> $BUILD_OUTPUT 2>&1

# The build finished without returning an error so dump a tail of the output
dump_output
Expand Down
11 changes: 11 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,18 @@ services:
privileged: true
network_mode: host
container_name: kong
depends_on:
cassandra:
condition: service_healthy
postgres:
condition: service_healthy
redis:
condition: service_healthy
# volumes:
# - ./kong:/kong
environment:
JOBS: 2
TEST_SPLIT: ${TEST_SPLIT:-all}
TEST_SUITE: ${TEST_SUITE:-integration}
KONG_DATABASE: ${TEST_DATABASE:-postgres}
KONG_TEST_DATABASE: ${TEST_DATABASE:-postgres}
Expand Down
3 changes: 2 additions & 1 deletion dockerfiles/Dockerfile.deb
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,5 @@ RUN DEBIAN_FRONTEND=noninteractive apt-get update \
git \
m4 \
file \
ssh
ssh \
valgrind
14 changes: 12 additions & 2 deletions dockerfiles/Dockerfile.openresty
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@ RUN curl -fsSLo /tmp/yaml-${LIBYAML_VERSION}.tar.gz https://pyyaml.org/download/
--includedir=/tmp/yaml-${LIBYAML_VERSION} \
&& make install \
&& ./configure --libdir=/usr/local/kong/lib \
&& make install
&& make install \
&& rm -rf /tmp/yaml-${LIBYAML_VERSION}

ARG KONG_GMP_VERSION=6.1.2
ENV KONG_GMP_VERSION $KONG_GMP_VERSION
Expand Down Expand Up @@ -134,7 +135,16 @@ ENV OPENRESTY_PATCHES="${OPENRESTY_PATCHES}"
COPY kong-licensing /enterprise/kong-licensing
COPY lua-kong-nginx-module /enterprise/lua-kong-nginx-module

RUN /tmp/build-openresty.sh
ARG DEBUG=1
RUN DEBUG="${DEBUG}" /tmp/build-openresty.sh \
&& rm -rf /work

WORKDIR /kong
COPY kong /kong
COPY id_rsa /root/id_rsa
COPY build-kong.sh /build-kong.sh

RUN /build-kong.sh && rm -rf /kong

RUN sed -i 's/\/tmp\/build//' `grep -l -I -r '\/tmp\/build' /tmp/build/` || true

45 changes: 15 additions & 30 deletions test/Dockerfile.test
Original file line number Diff line number Diff line change
Expand Up @@ -16,41 +16,20 @@ ENV LUA_CPATH=/root/.luarocks/lib/lua/5.1/?.so;/usr/local/lib/lua/5.1/?.so;./?.s
COPY --from=KONG /tmp/build/ /tmp/build
RUN cp -R /tmp/build/* /
RUN rm -rf /usr/local/bin/kong
RUN apt-get update && apt-get install -y \
RUN ln -fs /usr/share/zoneinfo/America/New_York /etc/localtime && \
apt-get update && apt-get install -y \
tzdata \
vim \
jq \
httpie \
iputils-ping \
net-tools
net-tools \
valgrind \
net-tools && \
dpkg-reconfigure --frontend noninteractive tzdata && \
apt-get install -y postgresql

ENV GOLANG_VERSION 1.13.5

RUN set -eux; \
dpkgArch="$(dpkg --print-architecture || echo amd64)"; \
case "${dpkgArch##*-}" in \
amd64) goRelArch='linux-amd64'; goRelSha256='512103d7ad296467814a6e3f635631bd35574cab3369a97a323c9a585ccaa569' ;; \
armhf) goRelArch='linux-armv6l'; goRelSha256='26259f61d52ee2297b1e8feef3a0fc82144b666a2b95512402c31cc49713c133' ;; \
arm64) goRelArch='linux-arm64'; goRelSha256='227b718923e20c846460bbecddde9cb86bad73acc5fb6f8e1a96b81b5c84668b' ;; \
*) goRelArch='src'; goRelSha256='27d356e2a0b30d9983b60a788cf225da5f914066b37a6b4f69d457ba55a626ff'; \
echo >&2; echo >&2 "warning: current architecture ($dpkgArch) does not have a corresponding Go binary release; will be building from source"; echo >&2 ;; \
esac; \
\
url="https://golang.org/dl/go${GOLANG_VERSION}.${goRelArch}.tar.gz"; \
curl -fsSLo go.tgz "$url"; \
echo "${goRelSha256} *go.tgz" | sha256sum -c -; \
tar -C /usr/local -xzf go.tgz; \
rm go.tgz; \
\
if [ "$goRelArch" = 'src' ]; then \
echo >&2; \
echo >&2 'error: UNIMPLEMENTED'; \
echo >&2 'TODO install golang-any from jessie-backports for GOROOT_BOOTSTRAP (and uninstall after build)'; \
echo >&2; \
exit 1; \
fi; \
\
export PATH="/usr/local/go/bin:$PATH"; \
go version
COPY --from=KONG /usr/local/go /usr/local/go

ENV KONG_GO_PLUGINSERVER_VERSION=master
ENV GOPATH=/tmp/go
Expand All @@ -68,4 +47,10 @@ RUN chmod -R 777 /kong
WORKDIR /kong
RUN make dev

RUN curl -L https://cpanmin.us | perl - App::cpanminus \
&& cpanm --notest Test::Nginx \
&& cpanm --notest local::lib

RUN rm -rf /tmp/build

CMD ["sh", "-c", "cat /kong/spec/fixtures/hosts >> /etc/hosts; tail -f /dev/null"]

0 comments on commit 13e5cd9

Please sign in to comment.