From e4689b5ecf0495f436db1fedf4001bc62845aa76 Mon Sep 17 00:00:00 2001 From: Monty Taylor Date: Sun, 17 May 2020 08:56:05 -0500 Subject: [PATCH] Use builder images in dockerfiles The final tippecanoe image doesn't need the compiler in it. By using a builder image, we can install the compiler and build tippecanoe, then copy the results into a smaller final image. In Travis, run a build that stops on the builder image stage so that make test can be run in the script stage. In normal usage for a user that's not necessary. Update the travis image to bionic, as trusty is now in extended maint - and the only thing these jobs are doing is running docker. While we're in there, update centos to centos8 and ubuntu to 20.04, but add build args that allow overriding that if desired. Finally, ubuntu doesn't need build-essential, which pulls in all of the tools needed to build debian packages. Like centos it just needs gcc, g++ and make. --- .dockerignore | 2 +- .travis.yml | 20 ++++++++++++++------ Dockerfile | 23 ++++++++++++++++++----- Dockerfile.centos | 27 +++++++++++++++++++++++++++ Dockerfile.centos7 | 15 --------------- README.md | 2 +- 6 files changed, 61 insertions(+), 28 deletions(-) create mode 100644 Dockerfile.centos delete mode 100644 Dockerfile.centos7 diff --git a/.dockerignore b/.dockerignore index eccb374..0de7a1d 100644 --- a/.dockerignore +++ b/.dockerignore @@ -2,4 +2,4 @@ .gitignore .git Dockerfile -Dockerfile.centos7 +Dockerfile.centos diff --git a/.travis.yml b/.travis.yml index f27b0b2..db0bcc2 100644 --- a/.travis.yml +++ b/.travis.yml @@ -6,32 +6,40 @@ sudo: false matrix: include: - # test on docker+centos7 + # test on docker+centos - os: linux compiler: clang services: - docker sudo: true - dist: trusty - env: DOCKERFILE=Dockerfile.centos7 + dist: bionic + env: DOCKERFILE=Dockerfile.centos before_install: [] + # build the builder image separately to run the tests install: + - docker build -t tippecanoe-image-builder -f ${DOCKERFILE} . --target=builder - docker build -t tippecanoe-image -f ${DOCKERFILE} . + # run tippecanoe --help to make sure runtime libs are correct script: - - docker run -it tippecanoe-image + - docker run -it tippecanoe-image-builder + - docker run -it tippecanoe-image tippecanoe --help # test on docker+ubuntu - os: linux compiler: clang services: - docker sudo: true - dist: trusty + dist: bionic env: DOCKERFILE=Dockerfile before_install: [] + # build the builder image separately to run the tests install: + - docker build -t tippecanoe-image-builder -f ${DOCKERFILE} . --target=builder - docker build -t tippecanoe-image -f ${DOCKERFILE} . + # run tippecanoe --help to make sure runtime libs are correct script: - - docker run -it tippecanoe-image + - docker run -it tippecanoe-image-builder + - docker run -it tippecanoe-image tippecanoe --help # debug+integer-santizer build - os: linux compiler: clang diff --git a/Dockerfile b/Dockerfile index 1df89e5..0e17d02 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,13 +1,14 @@ +# Allow setting version as an argument +ARG UBUNTU_VERSION=20.04 + # Start from ubuntu -FROM ubuntu:16.04 +FROM ubuntu:${UBUNTU_VERSION} as builder # Update repos and install dependencies RUN apt-get update \ - && apt-get -y upgrade \ - && apt-get -y install build-essential libsqlite3-dev zlib1g-dev + && apt-get -y install make gcc g++ libsqlite3-dev zlib1g-dev -# Create a directory and copy in all files -RUN mkdir -p /tmp/tippecanoe-src +# Copy in all files WORKDIR /tmp/tippecanoe-src COPY . /tmp/tippecanoe-src @@ -17,3 +18,15 @@ RUN make \ # Run the tests CMD make test + +# Build final image +FROM ubuntu:${UBUNTU_VERSION} + +# Install runtime dependencies +RUN apt-get update \ + && apt-get install -y libsqlite3-0 zlib1g \ + && apt-get clean \ + && rm -rf /var/lib/apt/lists/* + +# Copy built files into final image +COPY --from=builder /usr/local/ /usr/local/ diff --git a/Dockerfile.centos b/Dockerfile.centos new file mode 100644 index 0000000..4e0a4b4 --- /dev/null +++ b/Dockerfile.centos @@ -0,0 +1,27 @@ +ARG CENTOS_VERSION=8 + +# Start from centos +FROM centos:${CENTOS_VERSION} as builder + +# Intall dependencies +RUN yum install -y make sqlite-devel zlib-devel gcc-c++ diffutils perl + +# Copy in all files +WORKDIR /tmp/tippecanoe-src +COPY . /tmp/tippecanoe-src + +# Build tippecanoe +RUN make \ + && make install + +# Run the tests +CMD make test + +# Build final image +FROM centos:${CENTOS_VERSION} + +# Install runtime dependencies +RUN yum install -y sqlite-libs zlib + +# Copy built files into final image +COPY --from=builder /usr/local/ /usr/local/ diff --git a/Dockerfile.centos7 b/Dockerfile.centos7 deleted file mode 100644 index c330de2..0000000 --- a/Dockerfile.centos7 +++ /dev/null @@ -1,15 +0,0 @@ -FROM centos:7 - -RUN yum install -y make sqlite-devel zlib-devel bash git gcc-c++ - -# Create a directory and copy in all files -RUN mkdir -p /tmp/tippecanoe-src -WORKDIR /tmp/tippecanoe-src -COPY . /tmp/tippecanoe-src - -# Build tippecanoe -RUN make \ - && make install - -# Run the tests -CMD make test diff --git a/README.md b/README.md index b841509..1b9515a 100644 --- a/README.md +++ b/README.md @@ -673,7 +673,7 @@ uses md2man (`gem install md2man`). Linux: - sudo apt-get install build-essential libsqlite3-dev zlib1g-dev + sudo apt-get install gcc g++ make libsqlite3-dev zlib1g-dev Then build: