Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use multistage build to bring in pbf executable #263

Merged
merged 1 commit into from
Nov 2, 2021

Conversation

orangejulius
Copy link
Member

@orangejulius orangejulius commented Nov 1, 2021

The polylines Docker image is a bit of a large one currently, as it includes not just Node.js and a node_modules directory, but a full compiler toolchain, an install of the Go language, the dependencies of the pbf repository from https://github.com/missinglink/pbf, and the final pbf executable that comes from it.

All told, this brought the total image size to a whopping 950MB uncompressed.

This PR makes use of multi stage builds to run the compiling of the pbf executable in a separate container. After this, all the toolchain and dependencies needed can be thrown away, and only the small executable copied to the final image.

Using container-diff it looks like the image size, uncompressed, after pelias/docker-baseimage#23 as well, will be only 322MB. That's a nice 600MB savings!

Before pelias/docker-baseimage#23 the image size still drops to 500MB, also a healthy reduction.

Replaces #262

@orangejulius orangejulius changed the title feat(Dockerfile): Use multistage build to bring in pbf executable Use multistage build to bring in pbf executable Nov 1, 2021
@missinglink
Copy link
Member

Yeah very nice

@orangejulius
Copy link
Member Author

orangejulius commented Nov 1, 2021

Some quick notes:

  • this works great with pelias prepare polylines
  • I chose pelias/baseimage as the builder image for general consistency, and specifically to use a glibc-based environment. Alpine uses musl and incompatibilities between it and glibc can be real nasty.

The polylines Docker image is a bit of a large one currently, as it
includes not just Node.js and a `node_modules` directory, but a full
compiler toolchain, an install of the Go language, the dependencies of
the `pbf` repository from https://github.com/missinglink/pbf, and the
final `pbf` executable that comes from it.

All told, this brought the total image size to a whopping 950MB
uncompressed.

This PR makes use of multi stage builds to run the compiling of the
`pbf` executable in a separate container. After this, all the toolchain
and dependencies needed can be thrown away, and only the small
executable copied to the final image.

Using `container-diff` it looks like the image size, uncompressed, after
pelias/docker-baseimage#23 as well, will be only
322MB. That's a nice 600MB savings!

Before pelias/docker-baseimage#23 the image size
still drops to 500MB, still a healthy reduction.

Replaces #262
@orangejulius orangejulius merged commit cb0b382 into master Nov 2, 2021
@orangejulius orangejulius deleted the use-multistage-build branch November 2, 2021 14:15
orangejulius added a commit to pelias/libpostal-service that referenced this pull request Nov 2, 2021
…encies

After pelias/docker-baseimage#23, we will no
longer have a compiler toolchain in our Docker baseimage. However, due
to the way Docker images work and build upon each other, the biggest
wins come from ensuring we don't have a compiler toolchain _anywhere_ in
our images.

If you think about it, even a single image having a compiler toolchain
is the same as the baseimage having it, at least when comparing the
total size of all our images.

Thankfully, with multistage builds we can easily remove both the C++
compiler toolchain and Golang buildtime dependencies in the libpostal
service, similar to pelias/polylines#263.

This alone drops the total image size for the libpostal-service from
3.2GB to 2.8GB. Further improvements are possible in the libpostal
baseimage.
orangejulius added a commit to pelias/libpostal-service that referenced this pull request Nov 2, 2021
…encies

After pelias/docker-baseimage#23, we will no
longer have a compiler toolchain in our Docker baseimage. However, due
to the way Docker images work and build upon each other, the biggest
wins come from ensuring we don't have a compiler toolchain _anywhere_ in
our images.

If you think about it, even a single image having a compiler toolchain
is the same as the baseimage having it, at least when comparing the
total size of all our images.

Thankfully, with multistage builds we can easily remove both the C++
compiler toolchain and Golang buildtime dependencies in the libpostal
service, similar to pelias/polylines#263.

This alone drops the total image size for the libpostal-service from
3.2GB to 2.8GB. Further improvements are possible in the libpostal
baseimage.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants