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

Reduce Shaka Packager official docker image size #535

Closed
kqyang opened this issue Dec 19, 2018 · 3 comments
Closed

Reduce Shaka Packager official docker image size #535

kqyang opened this issue Dec 19, 2018 · 3 comments
Assignees
Labels
status: archived Archived and locked; will not be updated type: enhancement New feature or request
Milestone

Comments

@kqyang
Copy link
Collaborator

kqyang commented Dec 19, 2018

Our docker images are more than 1 GB each.

There are a number of ways we can reduce our docker image size:

  • Keep only the result binaries. The intermediate artifacts like source code, compilation objects does not need to be present in the final image. This can be achieved using docker's multi-stage builds: https://docs.docker.com/develop/develop-images/multistage-build/.
  • Use a smaller base image. We can use scratch or alpine.
    • Scratch has a zero-byte base size. It requires the application to be a static binary with zero dependencies. It is more useful if we want to include only one binary in the image.
    • Alpine is a lightweight Linux distribution with <5MB base size. Since we want to include both packager and mpd_generator in our image, we will go with Alpine. It also allows us to include our pssh tool later.
@kqyang kqyang added the type: enhancement New feature or request label Dec 19, 2018
@kqyang kqyang added this to the v2.3 milestone Dec 19, 2018
@amotl
Copy link
Contributor

amotl commented Dec 19, 2018

Hi there,

while using Alpine Linux inside a Docker container recently, I became aware of the fact that it is based on musl libc instead of glibc. As I haven't been that much into this specific details of Alpine-based containers yet, this has been new to me but perfectly made sense to me regarding their goal of size squeezing after coming from uclibc already.

However, I believe completely switching to a non-glibc distribution would not be universal enough to make it easy for others to build upon Shaka Packager's official image as baseline image to do other general purpose things with it. Especially when it comes to cross-platform support, the straight Debian distribution is still the most powerful thing around, see also:

# Explicitly use Debian for maximum cross-architecture compatibility
FROM debian:stretch-slim

-- https://github.com/docker-library/hello-world/blob/master/Dockerfile.build

This is actually so true and I experienced it on my own workbench when trying to do cross-compilation with Rust against MIPS inside a Docker container the other day: Debian just shines with multiarch support, so I had to switch the Dockerfile from Ubuntu to Debian stretch and haven't looked back.

While I have to admit running Shaka Packager on ARM or MIPS will not be its primary target, some people might want to do it nevertheless and then will be able to simply use the canonical/official Docker image for running the build process even against non-amd64 architectures.

You might have got it already: I just personally prefer Debian even more over other distributions after Ubuntu occasionally made me feel bad.

So, other reasons aside, I would definitively try to use plain Debian as a primary candidate to base the Docker image upon and optimize image size by other means if possible. Saying this, I didn't hear about debian:stretch-slim before, the baseline seems to be around 12 MB instead of 25 MB for the regular image. This would be totally ok for me for a software like Shaka Packager.

Just my two cents.

Cheers,
Andreas.

@kqyang
Copy link
Collaborator Author

kqyang commented Dec 19, 2018

@amotl Thanks for your comments, but I am not sure if I completely understand your points.

Especially when it comes to cross-platform support, the straight Debian distribution is still the most powerful thing around

Yes, absolutely. However, to do cross compilation in the docker container for Shaka Packager, we'll need to include the source code in the image, which is what we have now. The image size is more than 1GB, which is unnecessarily big, as for most users, it is sufficient to just have the application binaries.

For this use case, I think it is actually simpler for the user to pull in the code directly from GitHub. We provide docker files for various platforms in https://github.com/google/shaka-packager/tree/master/packager/testing/dockers, which users can reuse to create their own container. If it helps, we can also create Shaka Packager dev images with source code on DockerHub.

For the docker image with just the application binaries, I don't see a difference in functionality with using Debian or Alpine as the base.

Let me know if I missed anything.

@kqyang kqyang self-assigned this Dec 19, 2018
@amotl
Copy link
Contributor

amotl commented Dec 19, 2018

To do cross compilation in the docker container for Shaka Packager, we'll need to include the source code in the image, which is what we have now. The image size is more than 1GB, which is unnecessarily big, as for most users, it is sufficient to just have the application binaries.

Ah, i see. Sure.

We provide docker files for various platforms in https://github.com/google/shaka-packager/tree/master/packager/testing/dockers, which users can reuse to create their own container.

Ah, i see again. I haven't been aware of that armada of Docker support files for different platforms. Perfect!

If it helps, we can also create Shaka Packager dev images with source code on DockerHub.

Right, I was thinking about something like that, if there would be actually demand for that.

Thanks for sharing your insights and sorry for the noise!

@shaka-bot shaka-bot added the status: archived Archived and locked; will not be updated label Feb 18, 2019
@shaka-project shaka-project locked and limited conversation to collaborators Feb 18, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
status: archived Archived and locked; will not be updated type: enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

3 participants