hackoregon / devops-17

deployment tools for Hack Oregon projects
4 stars 3 forks source link

[Future] Try the Alpine Linux base image for backend Docker containers #42

Open MikeTheCanuck opened 7 years ago

MikeTheCanuck commented 7 years ago

In the backend projects' Dockerfile, the first instruction usually says FROM python:3.4. For those that don't know, this is telling the Docker engine to start with the official Python docker image, in this case the one that includes Python 3.4.

In investigating what it would take to use the latest Python (hint: FROM python:latest currently gets us Python 3.6), I also stumbled across the Alpine Linux images (e.g. FROM python:3.4-alpine).

I gave the Budget Team's backend one try (see this Travis build) with the python:alpine tag and got the following (not unexpected) error:

    writing manifest file 'pip-egg-info/psycopg2.egg-info/SOURCES.txt'
    warning: manifest_maker: standard file '-c' not found

    Error: pg_config executable not found.

    Please add the directory containing pg_config to the PATH
    or specify the full executable path with the option:

        python setup.py build_ext --pg-config /path/to/pg_config build ...

    or with the pg_config option in 'setup.cfg'.

This implies that the alpine image includes python 3.6 but doesn't include one of {postgresql, postgresql-devel}. And there will likely be other dependencies we take for granted from the standard python images that are stripped out of the alpine image.

Benefit

According to the usage example it could shave up to ~200 MB off the resulting container image, which could make developers happier and might slightly speed up build time. [Storage space in AWS or Docker Hub aren't a concern, assuming they don't charge for the size of the images that get stored there.]

Tradeoff

This could in fact measurably slow down the build time if we end up having to pip install more packages. That would also require some sort of pre-install automation e.g. a requirements-docker.txt that would have to be installed before requirements.txt.

Probably not worth it unless storage assumptions change.

znmeb commented 7 years ago

For PostGIS we probably need the Debian PostgreSQL image - I wasn't able to find Alpine packages for PostGIS in a quick search. But if there's no PostGIS requirement, just PostgreSQL, the Alpine image should work. There's an Alpine-based PostgreSQL image in the "Docker Store". You only need the PostgreSQL client libraries in the Python image.

That said, proliferation of options this late in the project life cycle is probably not a good idea. The more other peoples' stuff we have to test, the less of our own code we can troubleshoot.

MikeTheCanuck commented 7 years ago

Yep, agreed. I'll annotate this as another [Future] idea.