-
-
Notifications
You must be signed in to change notification settings - Fork 59
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
25 changed files
with
194 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
FROM python:2.7 | ||
|
||
LABEL maintainer="Sebastian Ramirez <tiangolo@gmail.com>" | ||
|
||
RUN pip install meinheld gunicorn | ||
|
||
COPY ./entrypoint.sh /entrypoint.sh | ||
RUN chmod +x /entrypoint.sh | ||
|
||
COPY ./start.sh /start.sh | ||
RUN chmod +x /start.sh | ||
|
||
COPY ./gunicorn_conf.py /gunicorn_conf.py | ||
|
||
COPY ./app /app | ||
WORKDIR /app/ | ||
|
||
ENV PYTHONPATH=/app | ||
|
||
EXPOSE 80 | ||
|
||
ENTRYPOINT ["/entrypoint.sh"] | ||
|
||
# Run the start script, it will check for an /app/prestart.sh script (e.g. for migrations) | ||
# And then will start Gunicorn with Meinheld | ||
CMD ["/start.sh"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
import sys | ||
|
||
|
||
def app(env, start_response): | ||
version = "{}.{}".format(sys.version_info.major, sys.version_info.minor) | ||
start_response("200 OK", [("Content-Type", "text/plain")]) | ||
message = "Hello World from a default Python {} app in a Docker container, with Meinheld and Gunicorn (default)".format( | ||
version | ||
) | ||
return [message.encode("utf-8")] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
#! /usr/bin/env sh | ||
|
||
echo "Running inside /app/prestart.sh, you could add migrations to this file, e.g.:" | ||
|
||
echo " | ||
#! /usr/bin/env bash | ||
# Let the DB start | ||
sleep 10; | ||
# Run migrations | ||
alembic upgrade head | ||
" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
#!/usr/bin/env sh | ||
set -e | ||
|
||
if [ -f /app/app/main.py ]; then | ||
DEFAULT_MODULE_NAME=app.main | ||
elif [ -f /app/main.py ]; then | ||
DEFAULT_MODULE_NAME=main | ||
fi | ||
MODULE_NAME=${MODULE_NAME:-$DEFAULT_MODULE_NAME} | ||
VARIABLE_NAME=${VARIABLE_NAME:-app} | ||
export APP_MODULE=${APP_MODULE:-"$MODULE_NAME:$VARIABLE_NAME"} | ||
|
||
if [ -f /app/gunicorn_conf.py ]; then | ||
DEFAULT_GUNICORN_CONF=/app/gunicorn_conf.py | ||
elif [ -f /app/app/gunicorn_conf.py ]; then | ||
DEFAULT_GUNICORN_CONF=/app/app/gunicorn_conf.py | ||
else | ||
DEFAULT_GUNICORN_CONF=/gunicorn_conf.py | ||
fi | ||
export GUNICORN_CONF=${GUNICORN_CONF:-$DEFAULT_GUNICORN_CONF} | ||
|
||
exec "$@" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
from __future__ import print_function | ||
import json | ||
import multiprocessing | ||
import os | ||
|
||
workers_per_core_str = os.getenv("WORKERS_PER_CORE", "2") | ||
web_concurrency_str = os.getenv("WEB_CONCURRENCY", None) | ||
host = os.getenv("HOST", "0.0.0.0") | ||
port = os.getenv("PORT", "80") | ||
bind_env = os.getenv("BIND", None) | ||
use_loglevel = os.getenv("LOG_LEVEL", "info") | ||
if bind_env: | ||
use_bind = bind_env | ||
else: | ||
use_bind = "{host}:{port}".format(host=host, port=port) | ||
|
||
cores = multiprocessing.cpu_count() | ||
workers_per_core = float(workers_per_core_str) | ||
default_web_concurrency = workers_per_core * cores | ||
if web_concurrency_str: | ||
web_concurrency = int(web_concurrency_str) | ||
assert web_concurrency > 0 | ||
else: | ||
web_concurrency = int(default_web_concurrency) | ||
|
||
# Gunicorn config variables | ||
loglevel = use_loglevel | ||
workers = web_concurrency | ||
bind = use_bind | ||
keepalive = 120 | ||
errorlog = "-" | ||
|
||
# For debugging and testing | ||
log_data = { | ||
"loglevel": loglevel, | ||
"workers": workers, | ||
"bind": bind, | ||
# Additional, non-gunicorn variables | ||
"workers_per_core": workers_per_core, | ||
"host": host, | ||
"port": port, | ||
} | ||
print(json.dumps(log_data)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
#! /usr/bin/env sh | ||
set -e | ||
|
||
# If there's a prestart.sh script in the /app directory, run it before starting | ||
PRE_START_PATH=/app/prestart.sh | ||
echo "Checking for script in $PRE_START_PATH" | ||
if [ -f $PRE_START_PATH ] ; then | ||
echo "Running script $PRE_START_PATH" | ||
. "$PRE_START_PATH" | ||
else | ||
echo "There is no script $PRE_START_PATH" | ||
fi | ||
|
||
# Start Gunicorn | ||
exec gunicorn -k egg:meinheld#gunicorn_worker -c "$GUNICORN_CONF" "$APP_MODULE" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
FROM tiangolo/meinheld-gunicorn:python2.7 | ||
|
||
COPY ./app /app |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
FROM tiangolo/meinheld-gunicorn:python2.7 | ||
|
||
COPY ./app /app |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
FROM tiangolo/meinheld-gunicorn:python2.7 | ||
|
||
COPY ./app /app |
3 changes: 3 additions & 0 deletions
3
tests/test_02_app/package_app_custom_config/python2.7.dockerfile
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
FROM tiangolo/meinheld-gunicorn:python2.7 | ||
|
||
COPY ./app /app |
3 changes: 3 additions & 0 deletions
3
tests/test_02_app/package_app_sub_config/python2.7.dockerfile
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
FROM tiangolo/meinheld-gunicorn:python2.7 | ||
|
||
COPY ./app /app |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
FROM tiangolo/meinheld-gunicorn:python2.7 | ||
|
||
COPY ./app /app |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
FROM tiangolo/meinheld-gunicorn:python2.7 | ||
|
||
COPY ./app /app |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters