encode / apistar

The Web API toolkit. 🛠
https://docs.apistar.com
BSD 3-Clause "New" or "Revised" License
5.57k stars 411 forks source link

Building an apistar microservice in an Alpine Linux container #614

Closed Midnighter closed 6 years ago

Midnighter commented 6 years ago

I tried to create a docker image using Alpine Linux and deploying the app with gunicorn and uvicorn support. However, compilation of uvtools and httptools failed for me. I might raise issues there but they both seem like rather immature packages so maybe there are other alternatives?

Combinations I have tried for building the Alpine image:

FROM python:3.6-alpine3.7
# Add the compiler dependency.
RUN pip install gunicorn uvicorn apistar

I also tried with a Debian base but again uvloop and httptools do not provide wheels and need to be compiled.

FROM python:3.6-slim
# ...

So to bring this issue back to API Star, what are successful combinations of dependencies and ASGI to run API Star asynchronously? Does anyone have a sample Dockerfile? Thanks in advance.

tomchristie commented 6 years ago

Okay, mostly we just need to change the uvicorn setup.py around a bit.

It’ll work with just ‘click’ and ‘h11’ installed. Anything else (httptools, uvloop, websockets, wsproto) is all optional.

Midnighter commented 6 years ago

Thanks for the reply. Since docker is the tool for me to run things in production, not having an optimized server would be a blocker for me. Luckily, I got it up and running using the Python slim Debian image. You can see the Dockerfile in this gist.

This image's size is ~ 210 MB (depending on your other dependencies) rather than the ~ 800 MB of the full Python 3.6 image.

I will try a bit more with Alpine Linux but I'm not super hopeful. I'll close this issue but will post back if I am successful.

Midnighter commented 6 years ago

Not sure what my problem was the other day. This Dockerfile shows how to build an image with Alpine Linux and it works just fine. Must have been tired or something.