Official Alpine Docker image

I would like to suggest having an official Crystal Alpine docker image available on DockerHub, like Ruby does

I found this unofficial image, which seems to work, but it would be nice to have something more formal.

Also, as a side note - I am not sure what are the minimum requirements by DockerHub to become an official library repository, but it would be nice if Crystal is accepted as an official library repo, rather than a repo of the “crystallang” user. So we can FROM crystal:alpine in our Dockerfiles.

4 Likes

Yes, we should provide an official Alpine image.
The thing is, it should not depend on the Crystal package in aports to avoid release delays. So we need to build it ourselves, which technically is not an issue, but the details of making it ready for distribution.

I’m waiting for feedback in https://github.com/crystal-lang/distribution-scripts/pull/29

This is also very relevant for running CI against musl (https://github.com/crystal-lang/crystal/issues/2275 and https://github.com/crystal-lang/crystal/issues/6943).

1 Like

Alpine-based docker images are now available starting with 0.32.1-alpine.

2 Likes

The image size is 115.55 MB. Shouldn’t it be much smaller for alpine?

The heaviest package by far is gcc. We obviously don’t need the entire compiler collection. But it provides the linker. I don’t know if there are any alternatives with less baggage.

Ah, I see. I’ve just meant the Crystal binary itself is less that 30Mb and alpine like 5Mb.

I tried to start splitting the libstdc++-dev from the gcc package, without success https://github.com/alpinelinux/aports/pull/9517 (needed for static linking). There are current limitations on the Alpine package build system.

Also, using lld can be an option.

Maybe a (separate?) multi-stage Docker build? (e.g.: one for ‘crystal-compiler’ w/ all the parts for those who need it and one for ‘crystal-binary’ w/ bare minimum to use for those who just need the bin file)

There are already separate images: crystallang/crystal:0.32.1-alpine and crystallang/crystal:0.32.1-alpine-build. The latter contains additional dependencies for building the crystal compiler and is usually not required unless you’re building the compiler. The former is almost the bare minimum for everyone just using the compiler to build their code. There are a few dependencies for stdlib libraries included which are not necessary in 100% of use cases but are very common (such as libyaml for example). They’re also pretty light-weight, so not to worry about.

2 Likes

@drhuffman12 there is a good example of multi stage / minimal Docker builds here: https://github.com/spider-gazelle/spider-gazelle/blob/master/Dockerfile

That’s what we use to deploy micoservices in AWS Fargate for example - results in a ~20mb image for our reasonably large APIs

3 Likes