Skip to content

Commit 2fb9c6f

Browse files
committed
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.
1 parent ddb7993 commit 2fb9c6f

6 files changed

Lines changed: 61 additions & 28 deletions

File tree

.dockerignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,4 @@
22
.gitignore
33
.git
44
Dockerfile
5-
Dockerfile.centos7
5+
Dockerfile.centos

.travis.yml

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,32 +6,40 @@ sudo: false
66

77
matrix:
88
include:
9-
# test on docker+centos7
9+
# test on docker+centos
1010
- os: linux
1111
compiler: clang
1212
services:
1313
- docker
1414
sudo: true
15-
dist: trusty
16-
env: DOCKERFILE=Dockerfile.centos7
15+
dist: bionic
16+
env: DOCKERFILE=Dockerfile.centos
1717
before_install: []
18+
# build the builder image separately to run the tests
1819
install:
20+
- docker build -t tippecanoe-image-builder -f ${DOCKERFILE} . --target=builder
1921
- docker build -t tippecanoe-image -f ${DOCKERFILE} .
22+
# run tippecanoe --help to make sure runtime libs are correct
2023
script:
21-
- docker run -it tippecanoe-image
24+
- docker run -it tippecanoe-image-builder
25+
- docker run -it tippecanoe-image tippecanoe --help
2226
# test on docker+ubuntu
2327
- os: linux
2428
compiler: clang
2529
services:
2630
- docker
2731
sudo: true
28-
dist: trusty
32+
dist: bionic
2933
env: DOCKERFILE=Dockerfile
3034
before_install: []
35+
# build the builder image separately to run the tests
3136
install:
37+
- docker build -t tippecanoe-image-builder -f ${DOCKERFILE} . --target=builder
3238
- docker build -t tippecanoe-image -f ${DOCKERFILE} .
39+
# run tippecanoe --help to make sure runtime libs are correct
3340
script:
34-
- docker run -it tippecanoe-image
41+
- docker run -it tippecanoe-image-builder
42+
- docker run -it tippecanoe-image tippecanoe --help
3543
# debug+integer-santizer build
3644
- os: linux
3745
compiler: clang

Dockerfile

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
1+
# Allow setting version as an argument
2+
ARG UBUNTU_VERSION=20.04
3+
14
# Start from ubuntu
2-
FROM ubuntu:16.04
5+
FROM ubuntu:${UBUNTU_VERSION} as builder
36

47
# Update repos and install dependencies
58
RUN apt-get update \
6-
&& apt-get -y upgrade \
7-
&& apt-get -y install build-essential libsqlite3-dev zlib1g-dev
9+
&& apt-get -y install make gcc g++ libsqlite3-dev zlib1g-dev
810

9-
# Create a directory and copy in all files
10-
RUN mkdir -p /tmp/tippecanoe-src
11+
# Copy in all files
1112
WORKDIR /tmp/tippecanoe-src
1213
COPY . /tmp/tippecanoe-src
1314

@@ -17,3 +18,15 @@ RUN make \
1718

1819
# Run the tests
1920
CMD make test
21+
22+
# Build final image
23+
FROM ubuntu:${UBUNTU_VERSION}
24+
25+
# Install runtime dependencies
26+
RUN apt-get update \
27+
&& apt-get install -y libsqlite3-0 zlib1g \
28+
&& apt-get clean \
29+
&& rm -rf /var/lib/apt/lists/*
30+
31+
# Copy built files into final image
32+
COPY --from=builder /usr/local/ /usr/local/

Dockerfile.centos

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
ARG CENTOS_VERSION=8
2+
3+
# Start from centos
4+
FROM centos:${CENTOS_VERSION} as builder
5+
6+
# Intall dependencies
7+
RUN yum install -y make sqlite-devel zlib-devel gcc-c++ diffutils
8+
9+
# Copy in all files
10+
WORKDIR /tmp/tippecanoe-src
11+
COPY . /tmp/tippecanoe-src
12+
13+
# Build tippecanoe
14+
RUN make \
15+
&& make install
16+
17+
# Run the tests
18+
CMD make test
19+
20+
# Build final image
21+
FROM centos:${CENTOS_VERSION}
22+
23+
# Install runtime dependencies
24+
RUN yum install -y sqlite-libs zlib
25+
26+
# Copy built files into final image
27+
COPY --from=builder /usr/local/ /usr/local/

Dockerfile.centos7

Lines changed: 0 additions & 15 deletions
This file was deleted.

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -673,7 +673,7 @@ uses md2man (`gem install md2man`).
673673

674674
Linux:
675675

676-
sudo apt-get install build-essential libsqlite3-dev zlib1g-dev
676+
sudo apt-get install gcc g++ make libsqlite3-dev zlib1g-dev
677677

678678
Then build:
679679

0 commit comments

Comments
 (0)