-
-
Notifications
You must be signed in to change notification settings - Fork 608
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
18 changed files
with
447 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
FROM tiangolo/uwsgi-nginx:python2.7-alpine3.8 | ||
|
||
LABEL maintainer="Sebastian Ramirez <[email protected]>" | ||
|
||
RUN pip install flask | ||
|
||
# By default, allow unlimited file sizes, modify it to limit the file sizes | ||
# To have a maximum of 1 MB (Nginx's default) change the line to: | ||
# ENV NGINX_MAX_UPLOAD 1m | ||
ENV NGINX_MAX_UPLOAD 0 | ||
|
||
# By default, Nginx listens on port 80. | ||
# To modify this, change LISTEN_PORT environment variable. | ||
# (in a Dockerfile or with an option for `docker run`) | ||
ENV LISTEN_PORT 80 | ||
|
||
# Which uWSGI .ini file should be used, to make it customizable | ||
ENV UWSGI_INI /app/uwsgi.ini | ||
|
||
# URL under which static (not modified by Python) files will be requested | ||
# They will be served by Nginx directly, without being handled by uWSGI | ||
ENV STATIC_URL /static | ||
# Absolute path in where the static files wil be | ||
ENV STATIC_PATH /app/static | ||
|
||
# If STATIC_INDEX is 1, serve / with /static/index.html directly (or the static URL configured) | ||
# ENV STATIC_INDEX 1 | ||
ENV STATIC_INDEX 0 | ||
|
||
# Add demo app | ||
COPY ./app /app | ||
WORKDIR /app | ||
|
||
# Make /app/* available to be imported by Python globally to better support several use cases like Alembic migrations. | ||
ENV PYTHONPATH=/app | ||
|
||
# Copy start.sh script that will check for a /app/prestart.sh script and run it before starting the app | ||
COPY start.sh /start.sh | ||
RUN chmod +x /start.sh | ||
|
||
# Copy the entrypoint that will generate Nginx additional configs | ||
COPY entrypoint.sh /entrypoint.sh | ||
RUN chmod +x /entrypoint.sh | ||
|
||
ENTRYPOINT ["/entrypoint.sh"] | ||
|
||
# Run the start script, it will check for an /app/prestart.sh script (e.g. for migrations) | ||
# And then will start Supervisor, which in turn will start Nginx and uWSGI | ||
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,12 @@ | ||
from flask import Flask | ||
app = Flask(__name__) | ||
|
||
|
||
@app.route("/") | ||
def hello(): | ||
return "Hello World from Flask in a uWSGI Nginx Docker container with \ | ||
Python 2.7 (default)" | ||
|
||
|
||
if __name__ == "__main__": | ||
app.run(host='0.0.0.0', debug=True, port=80) |
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,3 @@ | ||
[uwsgi] | ||
module = main | ||
callable = 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,58 @@ | ||
#! /usr/bin/env sh | ||
set -e | ||
# Get the maximum upload file size for Nginx, default to 0: unlimited | ||
USE_NGINX_MAX_UPLOAD=${NGINX_MAX_UPLOAD:-0} | ||
# Generate Nginx config for maximum upload file size | ||
echo "client_max_body_size $USE_NGINX_MAX_UPLOAD;" > /etc/nginx/conf.d/upload.conf | ||
|
||
# Get the number of workers for Nginx, default to 1 | ||
USE_NGINX_WORKER_PROCESSES=${NGINX_WORKER_PROCESSES:-1} | ||
# Modify the number of worker processes in Nginx config | ||
sed -i "/worker_processes\s/c\worker_processes ${USE_NGINX_WORKER_PROCESSES};" /etc/nginx/nginx.conf | ||
|
||
# Set the max number of connections per worker for Nginx, if requested | ||
# Cannot exceed worker_rlimit_nofile, see NGINX_WORKER_OPEN_FILES below | ||
if [ -n "$NGINX_WORKER_CONNECTIONS" ] ; then | ||
sed -i "/worker_connections\s/c\ worker_connections ${NGINX_WORKER_CONNECTIONS};" /etc/nginx/nginx.conf | ||
fi | ||
|
||
# Set the max number of open file descriptors for Nginx workers, if requested | ||
if [ -n "$NGINX_WORKER_OPEN_FILES" ] ; then | ||
echo "worker_rlimit_nofile ${NGINX_WORKER_OPEN_FILES};" >> /etc/nginx/nginx.conf | ||
fi | ||
|
||
# Get the URL for static files from the environment variable | ||
USE_STATIC_URL=${STATIC_URL:-'/static'} | ||
# Get the absolute path of the static files from the environment variable | ||
USE_STATIC_PATH=${STATIC_PATH:-'/app/static'} | ||
# Get the listen port for Nginx, default to 80 | ||
USE_LISTEN_PORT=${LISTEN_PORT:-80} | ||
|
||
# Explicitly add installed Python packages and uWSGI Python packages to PYTHONPATH | ||
# Otherwise uWSGI can't import Flask | ||
export PYTHONPATH=$PYTHONPATH:/usr/local/lib/python2.7/site-packages:/usr/lib/python2.7/site-packages | ||
|
||
# Generate Nginx config first part using the environment variables | ||
echo "server { | ||
listen ${USE_LISTEN_PORT}; | ||
location / { | ||
try_files \$uri @app; | ||
} | ||
location @app { | ||
include uwsgi_params; | ||
uwsgi_pass unix:///tmp/uwsgi.sock; | ||
} | ||
location $USE_STATIC_URL { | ||
alias $USE_STATIC_PATH; | ||
}" > /etc/nginx/conf.d/nginx.conf | ||
|
||
# If STATIC_INDEX is 1, serve / with /static/index.html directly (or the static URL configured) | ||
if [[ $STATIC_INDEX == 1 ]] ; then | ||
echo " location = / { | ||
index $USE_STATIC_URL/index.html; | ||
}" >> /etc/nginx/conf.d/nginx.conf | ||
fi | ||
# Finish the Nginx config file | ||
echo "}" >> /etc/nginx/conf.d/nginx.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,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" | ||
source $PRE_START_PATH | ||
else | ||
echo "There is no script $PRE_START_PATH" | ||
fi | ||
|
||
# Start Supervisor, with Nginx and uWSGI | ||
exec /usr/bin/supervisord |
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,49 @@ | ||
FROM tiangolo/uwsgi-nginx:python3.6-alpine3.8 | ||
|
||
LABEL maintainer="Sebastian Ramirez <[email protected]>" | ||
|
||
RUN pip install flask | ||
|
||
# By default, allow unlimited file sizes, modify it to limit the file sizes | ||
# To have a maximum of 1 MB (Nginx's default) change the line to: | ||
# ENV NGINX_MAX_UPLOAD 1m | ||
ENV NGINX_MAX_UPLOAD 0 | ||
|
||
# By default, Nginx listens on port 80. | ||
# To modify this, change LISTEN_PORT environment variable. | ||
# (in a Dockerfile or with an option for `docker run`) | ||
ENV LISTEN_PORT 80 | ||
|
||
# Which uWSGI .ini file should be used, to make it customizable | ||
ENV UWSGI_INI /app/uwsgi.ini | ||
|
||
# URL under which static (not modified by Python) files will be requested | ||
# They will be served by Nginx directly, without being handled by uWSGI | ||
ENV STATIC_URL /static | ||
# Absolute path in where the static files wil be | ||
ENV STATIC_PATH /app/static | ||
|
||
# If STATIC_INDEX is 1, serve / with /static/index.html directly (or the static URL configured) | ||
# ENV STATIC_INDEX 1 | ||
ENV STATIC_INDEX 0 | ||
|
||
# Add demo app | ||
COPY ./app /app | ||
WORKDIR /app | ||
|
||
# Make /app/* available to be imported by Python globally to better support several use cases like Alembic migrations. | ||
ENV PYTHONPATH=/app | ||
|
||
# Copy start.sh script that will check for a /app/prestart.sh script and run it before starting the app | ||
COPY start.sh /start.sh | ||
RUN chmod +x /start.sh | ||
|
||
# Copy the entrypoint that will generate Nginx additional configs | ||
COPY entrypoint.sh /entrypoint.sh | ||
RUN chmod +x /entrypoint.sh | ||
|
||
ENTRYPOINT ["/entrypoint.sh"] | ||
|
||
# Run the start script, it will check for an /app/prestart.sh script (e.g. for migrations) | ||
# And then will start Supervisor, which in turn will start Nginx and uWSGI | ||
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,12 @@ | ||
from flask import Flask | ||
app = Flask(__name__) | ||
|
||
|
||
@app.route("/") | ||
def hello(): | ||
return "Hello World from Flask in a uWSGI Nginx Docker container with \ | ||
Python 3.6 (default)" | ||
|
||
|
||
if __name__ == "__main__": | ||
app.run(host='0.0.0.0', debug=True, port=80) |
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,3 @@ | ||
[uwsgi] | ||
module = main | ||
callable = 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,58 @@ | ||
#! /usr/bin/env sh | ||
set -e | ||
# Get the maximum upload file size for Nginx, default to 0: unlimited | ||
USE_NGINX_MAX_UPLOAD=${NGINX_MAX_UPLOAD:-0} | ||
# Generate Nginx config for maximum upload file size | ||
echo "client_max_body_size $USE_NGINX_MAX_UPLOAD;" > /etc/nginx/conf.d/upload.conf | ||
|
||
# Get the number of workers for Nginx, default to 1 | ||
USE_NGINX_WORKER_PROCESSES=${NGINX_WORKER_PROCESSES:-1} | ||
# Modify the number of worker processes in Nginx config | ||
sed -i "/worker_processes\s/c\worker_processes ${USE_NGINX_WORKER_PROCESSES};" /etc/nginx/nginx.conf | ||
|
||
# Set the max number of connections per worker for Nginx, if requested | ||
# Cannot exceed worker_rlimit_nofile, see NGINX_WORKER_OPEN_FILES below | ||
if [ -n "$NGINX_WORKER_CONNECTIONS" ] ; then | ||
sed -i "/worker_connections\s/c\ worker_connections ${NGINX_WORKER_CONNECTIONS};" /etc/nginx/nginx.conf | ||
fi | ||
|
||
# Set the max number of open file descriptors for Nginx workers, if requested | ||
if [ -n "$NGINX_WORKER_OPEN_FILES" ] ; then | ||
echo "worker_rlimit_nofile ${NGINX_WORKER_OPEN_FILES};" >> /etc/nginx/nginx.conf | ||
fi | ||
|
||
# Get the URL for static files from the environment variable | ||
USE_STATIC_URL=${STATIC_URL:-'/static'} | ||
# Get the absolute path of the static files from the environment variable | ||
USE_STATIC_PATH=${STATIC_PATH:-'/app/static'} | ||
# Get the listen port for Nginx, default to 80 | ||
USE_LISTEN_PORT=${LISTEN_PORT:-80} | ||
|
||
# Explicitly add installed Python packages and uWSGI Python packages to PYTHONPATH | ||
# Otherwise uWSGI can't import Flask | ||
export PYTHONPATH=$PYTHONPATH:/usr/local/lib/python3.6/site-packages:/usr/lib/python3.6/site-packages | ||
|
||
# Generate Nginx config first part using the environment variables | ||
echo "server { | ||
listen ${USE_LISTEN_PORT}; | ||
location / { | ||
try_files \$uri @app; | ||
} | ||
location @app { | ||
include uwsgi_params; | ||
uwsgi_pass unix:///tmp/uwsgi.sock; | ||
} | ||
location $USE_STATIC_URL { | ||
alias $USE_STATIC_PATH; | ||
}" > /etc/nginx/conf.d/nginx.conf | ||
|
||
# If STATIC_INDEX is 1, serve / with /static/index.html directly (or the static URL configured) | ||
if [[ $STATIC_INDEX == 1 ]] ; then | ||
echo " location = / { | ||
index $USE_STATIC_URL/index.html; | ||
}" >> /etc/nginx/conf.d/nginx.conf | ||
fi | ||
# Finish the Nginx config file | ||
echo "}" >> /etc/nginx/conf.d/nginx.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,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" | ||
source $PRE_START_PATH | ||
else | ||
echo "There is no script $PRE_START_PATH" | ||
fi | ||
|
||
# Start Supervisor, with Nginx and uWSGI | ||
exec /usr/bin/supervisord |
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,49 @@ | ||
FROM tiangolo/uwsgi-nginx:python3.7-alpine3.8 | ||
|
||
LABEL maintainer="Sebastian Ramirez <[email protected]>" | ||
|
||
RUN pip install flask | ||
|
||
# By default, allow unlimited file sizes, modify it to limit the file sizes | ||
# To have a maximum of 1 MB (Nginx's default) change the line to: | ||
# ENV NGINX_MAX_UPLOAD 1m | ||
ENV NGINX_MAX_UPLOAD 0 | ||
|
||
# By default, Nginx listens on port 80. | ||
# To modify this, change LISTEN_PORT environment variable. | ||
# (in a Dockerfile or with an option for `docker run`) | ||
ENV LISTEN_PORT 80 | ||
|
||
# Which uWSGI .ini file should be used, to make it customizable | ||
ENV UWSGI_INI /app/uwsgi.ini | ||
|
||
# URL under which static (not modified by Python) files will be requested | ||
# They will be served by Nginx directly, without being handled by uWSGI | ||
ENV STATIC_URL /static | ||
# Absolute path in where the static files wil be | ||
ENV STATIC_PATH /app/static | ||
|
||
# If STATIC_INDEX is 1, serve / with /static/index.html directly (or the static URL configured) | ||
# ENV STATIC_INDEX 1 | ||
ENV STATIC_INDEX 0 | ||
|
||
# Add demo app | ||
COPY ./app /app | ||
WORKDIR /app | ||
|
||
# Make /app/* available to be imported by Python globally to better support several use cases like Alembic migrations. | ||
ENV PYTHONPATH=/app | ||
|
||
# Copy start.sh script that will check for a /app/prestart.sh script and run it before starting the app | ||
COPY start.sh /start.sh | ||
RUN chmod +x /start.sh | ||
|
||
# Copy the entrypoint that will generate Nginx additional configs | ||
COPY entrypoint.sh /entrypoint.sh | ||
RUN chmod +x /entrypoint.sh | ||
|
||
ENTRYPOINT ["/entrypoint.sh"] | ||
|
||
# Run the start script, it will check for an /app/prestart.sh script (e.g. for migrations) | ||
# And then will start Supervisor, which in turn will start Nginx and uWSGI | ||
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,12 @@ | ||
from flask import Flask | ||
app = Flask(__name__) | ||
|
||
|
||
@app.route("/") | ||
def hello(): | ||
return "Hello World from Flask in a uWSGI Nginx Docker container with \ | ||
Python 3.7 (default)" | ||
|
||
|
||
if __name__ == "__main__": | ||
app.run(host='0.0.0.0', debug=True, port=80) |
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,3 @@ | ||
[uwsgi] | ||
module = main | ||
callable = app |
Oops, something went wrong.