diff --git a/python2.7-alpine3.8/Dockerfile b/python2.7-alpine3.8/Dockerfile new file mode 100644 index 00000000..38c93026 --- /dev/null +++ b/python2.7-alpine3.8/Dockerfile @@ -0,0 +1,49 @@ +FROM tiangolo/uwsgi-nginx:python2.7-alpine3.8 + +LABEL maintainer="Sebastian Ramirez " + +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"] diff --git a/python2.7-alpine3.8/app/main.py b/python2.7-alpine3.8/app/main.py new file mode 100644 index 00000000..f5c90623 --- /dev/null +++ b/python2.7-alpine3.8/app/main.py @@ -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) diff --git a/python2.7-alpine3.8/app/prestart.sh b/python2.7-alpine3.8/app/prestart.sh new file mode 100644 index 00000000..9ccb1dab --- /dev/null +++ b/python2.7-alpine3.8/app/prestart.sh @@ -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 +" diff --git a/python2.7-alpine3.8/app/uwsgi.ini b/python2.7-alpine3.8/app/uwsgi.ini new file mode 100644 index 00000000..327bbb23 --- /dev/null +++ b/python2.7-alpine3.8/app/uwsgi.ini @@ -0,0 +1,3 @@ +[uwsgi] +module = main +callable = app diff --git a/python2.7-alpine3.8/entrypoint.sh b/python2.7-alpine3.8/entrypoint.sh new file mode 100644 index 00000000..4e4bd6a7 --- /dev/null +++ b/python2.7-alpine3.8/entrypoint.sh @@ -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 "$@" \ No newline at end of file diff --git a/python2.7-alpine3.8/start.sh b/python2.7-alpine3.8/start.sh new file mode 100644 index 00000000..8626c151 --- /dev/null +++ b/python2.7-alpine3.8/start.sh @@ -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 diff --git a/python3.6-alpine3.8/Dockerfile b/python3.6-alpine3.8/Dockerfile new file mode 100644 index 00000000..d3e21f52 --- /dev/null +++ b/python3.6-alpine3.8/Dockerfile @@ -0,0 +1,49 @@ +FROM tiangolo/uwsgi-nginx:python3.6-alpine3.8 + +LABEL maintainer="Sebastian Ramirez " + +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"] diff --git a/python3.6-alpine3.8/app/main.py b/python3.6-alpine3.8/app/main.py new file mode 100644 index 00000000..b74aad5b --- /dev/null +++ b/python3.6-alpine3.8/app/main.py @@ -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) diff --git a/python3.6-alpine3.8/app/prestart.sh b/python3.6-alpine3.8/app/prestart.sh new file mode 100644 index 00000000..9ccb1dab --- /dev/null +++ b/python3.6-alpine3.8/app/prestart.sh @@ -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 +" diff --git a/python3.6-alpine3.8/app/uwsgi.ini b/python3.6-alpine3.8/app/uwsgi.ini new file mode 100644 index 00000000..327bbb23 --- /dev/null +++ b/python3.6-alpine3.8/app/uwsgi.ini @@ -0,0 +1,3 @@ +[uwsgi] +module = main +callable = app diff --git a/python3.6-alpine3.8/entrypoint.sh b/python3.6-alpine3.8/entrypoint.sh new file mode 100644 index 00000000..d7f45f95 --- /dev/null +++ b/python3.6-alpine3.8/entrypoint.sh @@ -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 "$@" \ No newline at end of file diff --git a/python3.6-alpine3.8/start.sh b/python3.6-alpine3.8/start.sh new file mode 100644 index 00000000..8626c151 --- /dev/null +++ b/python3.6-alpine3.8/start.sh @@ -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 diff --git a/python3.7-alpine3.8/Dockerfile b/python3.7-alpine3.8/Dockerfile new file mode 100644 index 00000000..eb33ad95 --- /dev/null +++ b/python3.7-alpine3.8/Dockerfile @@ -0,0 +1,49 @@ +FROM tiangolo/uwsgi-nginx:python3.7-alpine3.8 + +LABEL maintainer="Sebastian Ramirez " + +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"] diff --git a/python3.7-alpine3.8/app/main.py b/python3.7-alpine3.8/app/main.py new file mode 100644 index 00000000..ad90cf58 --- /dev/null +++ b/python3.7-alpine3.8/app/main.py @@ -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) diff --git a/python3.7-alpine3.8/app/prestart.sh b/python3.7-alpine3.8/app/prestart.sh new file mode 100644 index 00000000..9ccb1dab --- /dev/null +++ b/python3.7-alpine3.8/app/prestart.sh @@ -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 +" diff --git a/python3.7-alpine3.8/app/uwsgi.ini b/python3.7-alpine3.8/app/uwsgi.ini new file mode 100644 index 00000000..327bbb23 --- /dev/null +++ b/python3.7-alpine3.8/app/uwsgi.ini @@ -0,0 +1,3 @@ +[uwsgi] +module = main +callable = app diff --git a/python3.7-alpine3.8/entrypoint.sh b/python3.7-alpine3.8/entrypoint.sh new file mode 100644 index 00000000..9a8db710 --- /dev/null +++ b/python3.7-alpine3.8/entrypoint.sh @@ -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.7/site-packages:/usr/lib/python3.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 "$@" \ No newline at end of file diff --git a/python3.7-alpine3.8/start.sh b/python3.7-alpine3.8/start.sh new file mode 100644 index 00000000..8626c151 --- /dev/null +++ b/python3.7-alpine3.8/start.sh @@ -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