Skip to content

Commit

Permalink
feat(cache) aggressively cache the kong development / test image (#247)
Browse files Browse the repository at this point in the history
* feat(cache) aggressively cache the kong development / test image

* chore(squash) TIL docker build --squash

* Revert "chore(squash) TIL docker build --squash"

This reverts commit 3c6aa17.
  • Loading branch information
hutchic authored Mar 25, 2020
1 parent a5fcd9b commit 80de082
Show file tree
Hide file tree
Showing 3 changed files with 61 additions and 64 deletions.
21 changes: 14 additions & 7 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -247,16 +247,23 @@ actual-build-kong:

kong-test-container:
ifneq ($(RESTY_IMAGE_BASE),src)
$(CACHE_COMMAND) $(DOCKER_REPOSITORY):test-$(DOCKER_TEST_SUFFIX) || \
( $(MAKE) build-kong && $(DOCKER_COMMAND) -f test/Dockerfile.test \
-rm -rf kong
-cp -R $(KONG_SOURCE_LOCATION) kong

$(CACHE_COMMAND) $(DOCKER_REPOSITORY):test-$(DOCKER_OPENRESTY_SUFFIX) || \
( $(MAKE) build-openresty && \
docker tag $(DOCKER_REPOSITORY):openresty-$(RESTY_IMAGE_BASE)-$(RESTY_IMAGE_TAG)-$(DOCKER_OPENRESTY_SUFFIX) \
$(DOCKER_REPOSITORY):test-$(DOCKER_OPENRESTY_SUFFIX) )

$(DOCKER_COMMAND) -f test/Dockerfile.test \
--build-arg KONG_GO_PLUGINSERVER_VERSION=$(KONG_GO_PLUGINSERVER_VERSION) \
--build-arg DOCKER_KONG_SUFFIX=$(DOCKER_KONG_SUFFIX) \
--build-arg DOCKER_BASE_SUFFIX=$(DOCKER_BASE_SUFFIX) \
--build-arg DOCKER_REPOSITORY=$(DOCKER_REPOSITORY) \
--build-arg KONG_SHA=${KONG_SHA} \
-t $(DOCKER_REPOSITORY):test-$(DOCKER_TEST_SUFFIX) . )
-$(UPDATE_CACHE_COMMAND) $(DOCKER_REPOSITORY):test-$(DOCKER_TEST_SUFFIX)
--build-arg DOCKER_OPENRESTY_SUFFIX=$(DOCKER_OPENRESTY_SUFFIX) \
-t $(DOCKER_REPOSITORY):test-$(DOCKER_TEST_SUFFIX) .

docker tag $(DOCKER_REPOSITORY):test-$(DOCKER_TEST_SUFFIX) $(DOCKER_REPOSITORY):test
docker tag $(DOCKER_REPOSITORY):test $(DOCKER_REPOSITORY):test-$(DOCKER_OPENRESTY_SUFFIX)
-$(UPDATE_CACHE_COMMAND) $(DOCKER_REPOSITORY):test-$(DOCKER_OPENRESTY_SUFFIX)
endif

test-kong: kong-test-container
Expand Down
1 change: 0 additions & 1 deletion dockerfiles/Dockerfile.openresty
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,6 @@ RUN DEBUG="${DEBUG}" /tmp/build-openresty.sh \

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
Expand Down
103 changes: 47 additions & 56 deletions test/Dockerfile.test
Original file line number Diff line number Diff line change
@@ -1,56 +1,47 @@
ARG RESTY_IMAGE_BASE="ubuntu"
ARG RESTY_IMAGE_TAG="bionic"
ARG DOCKER_KONG_SUFFIX
ARG DOCKER_BASE_SUFFIX
ARG KONG_SHA
ARG DOCKER_REPOSITORY

FROM ${DOCKER_REPOSITORY}:kong-${RESTY_IMAGE_BASE}-${RESTY_IMAGE_TAG}-${DOCKER_KONG_SUFFIX} as KONG

FROM ${DOCKER_REPOSITORY}:${RESTY_IMAGE_BASE}-${RESTY_IMAGE_TAG}-${DOCKER_BASE_SUFFIX}

ENV PATH=$PATH:/kong/bin:/usr/local/openresty/bin/:/usr/local/kong/bin/:/usr/local/openresty/nginx/sbin/
ENV LUA_PATH=/kong/?.lua;/kong/?/init.lua;/root/.luarocks/share/lua/5.1/?.lua;/root/.luarocks/share/lua/5.1/?/init.lua;/usr/local/share/lua/5.1/?.lua;/usr/local/share/lua/5.1/?/init.lua;./?.lua;/usr/local/openresty/luajit/share/luajit-2.1.0-beta3/?.lua;/usr/local/openresty/luajit/share/lua/5.1/?.lua;/usr/local/openresty/luajit/share/lua/5.1/?/init.lua
ENV LUA_CPATH=/root/.luarocks/lib/lua/5.1/?.so;/usr/local/lib/lua/5.1/?.so;./?.so;/usr/local/openresty/luajit/lib/lua/5.1/?.so;/usr/local/lib/lua/5.1/loadall.so

COPY --from=KONG /tmp/build/ /tmp/build
RUN cp -R /tmp/build/* /
RUN rm -rf /usr/local/bin/kong
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 \
valgrind \
net-tools && \
dpkg-reconfigure --frontend noninteractive tzdata && \
apt-get install -y postgresql

COPY --from=KONG /usr/local/go /usr/local/go

ENV KONG_GO_PLUGINSERVER_VERSION=master
ENV GOPATH=/tmp/go
ENV PATH $GOPATH/bin:/usr/local/go/bin:$PATH

RUN mkdir -p /tmp/go/src/github.com/kong/ \
&& git clone --branch ${KONG_GO_PLUGINSERVER_VERSION} https://github.com/Kong/go-pluginserver.git /tmp/go/src/github.com/kong/go-pluginserver \
&& cd /tmp/go/src/github.com/kong/go-pluginserver \
&& go mod tidy


COPY kong /kong
RUN mkdir -p /kong/servroot/logs
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"]
ARG DOCKER_OPENRESTY_SUFFIX
ARG DOCKER_REPOSITORY

FROM ${DOCKER_REPOSITORY}:test-${DOCKER_OPENRESTY_SUFFIX}

ENV PATH=$PATH:/kong/bin:/usr/local/openresty/bin/:/usr/local/kong/bin/:/usr/local/openresty/nginx/sbin/
ENV LUA_PATH=/kong/?.lua;/kong/?/init.lua;/root/.luarocks/share/lua/5.1/?.lua;/root/.luarocks/share/lua/5.1/?/init.lua;/usr/local/share/lua/5.1/?.lua;/usr/local/share/lua/5.1/?/init.lua;./?.lua;/usr/local/openresty/luajit/share/luajit-2.1.0-beta3/?.lua;/usr/local/openresty/luajit/share/lua/5.1/?.lua;/usr/local/openresty/luajit/share/lua/5.1/?/init.lua
ENV LUA_CPATH=/root/.luarocks/lib/lua/5.1/?.so;/usr/local/lib/lua/5.1/?.so;./?.so;/usr/local/openresty/luajit/lib/lua/5.1/?.so;/usr/local/lib/lua/5.1/loadall.so

RUN cp -R /tmp/build/* / || true
RUN rm -rf /usr/local/bin/kong
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 \
valgrind \
net-tools && \
dpkg-reconfigure --frontend noninteractive tzdata && \
apt-get install -y postgresql

ENV KONG_GO_PLUGINSERVER_VERSION=master
ENV GOPATH=/tmp/go
ENV PATH $GOPATH/bin:/usr/local/go/bin:$PATH

RUN rm -rf /tmp/go/src/github.com/kong/ \
&& mkdir -p /tmp/go/src/github.com/kong/ \
&& git clone --branch ${KONG_GO_PLUGINSERVER_VERSION} https://github.com/Kong/go-pluginserver.git /tmp/go/src/github.com/kong/go-pluginserver \
&& cd /tmp/go/src/github.com/kong/go-pluginserver \
&& go mod tidy

COPY kong /kong
RUN mkdir -p /kong/servroot/logs
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 80de082

Please sign in to comment.