klen / muffin-docker

Docker images for Muffin Framework

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

tests build dockerhub

muffin-docker

Docker image with Muffin managed by Gunicorn

Supported images

How to use

  • You don't need to clone the GitHub repo. You can use this image as a base image for other images, using this in your Dockerfile:
FROM horneds/muffin:latest

COPY ./app /app

It will expect a file at /app/app.py.

Or otherwise a file at /app/main.py.

And will expect it to contain a variable app with your "ASGI" application.

Then you can build your image from the directory that has your Dockerfile, e.g:

docker build -t myimage ./
  • Run a container based on your image:
docker run -d --name mycontainer -p 80:80 myimage

You should be able to check it in your Docker container's URL, for example: http://127.0.0.1/ (or equivalent, using your Docker host).

Dependencies and packages

You will probably also want to add any dependencies for your app and pin them to a specific version, probably including Uvicorn and Gunicorn.

This way you can make sure your app always works as expected.

You could install packages with pip commands in your Dockerfile, using a requirements.txt, or even using Poetry.

Using PIP

Here's a small example of one of the ways you could install your dependencies making sure you have a pinned version for each package.

Let's say you have a your dependencies in a file requirements.txt.

Then you could have a Dockerfile like:

FROM horneds/muffin:latest

# Copy and install dependencies
COPY ./requirements.txt /app/requirements.txt
RUN pip install -r /app/requirements.txt

COPY ./app /app

That will:

  • Copy your application requirements.
  • Install the dependencies.
  • Then copy your app code.

Advanced usage

Environment variables

  • MODULE_NAME (app, main, app.app, app.main) -- python module that contains Muffin application

  • VARIABLE_NAME (app) -- The variable inside of the Python module that contains the Muffin application

  • SETUP_SCRIPT -- Optional setup script to run before start gunicorn

  • GWORKER_CLASS (uvicorn.workers.UvicornWorker) -- Gunicorn Worker Class

  • GWORKERS (num of CPU) -- Number of gunicorn workers

  • HOST (0.0.0.0) -- Host to bind the server

  • PORT (80) -- Port to bind the server

  • GBIND (0.0.0.0:80) -- Address (host:port) to bind the server inside the container. If the variable is set, the variables $HOST, $PORT will be ignored.

  • GLOG_LEVEL (info) -- Gunicorn log level

  • GUNICORN_CMD_ARGS -- Optional Gunicorn command arguments

License

This project is licensed under the terms of the MIT license.

About

Docker images for Muffin Framework

License:MIT License


Languages

Language:Python 34.1%Language:Makefile 25.7%Language:Dockerfile 24.8%Language:Shell 15.4%