diff --git a/python2.7-alpine3.7/entrypoint.sh b/python2.7-alpine3.7/entrypoint.sh index 1907b933..20867bdd 100644 --- a/python2.7-alpine3.7/entrypoint.sh +++ b/python2.7-alpine3.7/entrypoint.sh @@ -14,26 +14,30 @@ USE_STATIC_PATH=${STATIC_PATH:-'/app/static'} # Get the listen port for Nginx, default to 80 USE_LISTEN_PORT=${LISTEN_PORT:-80} -content_server='server {\n' -content_server=$content_server" listen ${USE_LISTEN_PORT};\n" -content_server=$content_server' location / {\n' -content_server=$content_server' try_files $uri @app;\n' -content_server=$content_server' }\n' -content_server=$content_server' location @app {\n' -content_server=$content_server' include uwsgi_params;\n' -content_server=$content_server' uwsgi_pass unix:///tmp/uwsgi.sock;\n' -content_server=$content_server' }\n' -content_server=$content_server" location $USE_STATIC_URL {\n" -content_server=$content_server" alias $USE_STATIC_PATH;\n" -content_server=$content_server' }\n' -# If STATIC_INDEX is 1, serve / with /static/index.html directly (or the static URL configured) -if [ "$STATIC_INDEX" = 1 ] ; then - content_server=$content_server' location = / {\n' - content_server=$content_server" index $USE_STATIC_URL/index.html;\n" +if [ -f /app/nginx.conf ]; then + cp /app/nginx.conf /etc/nginx/nginx.conf +else + content_server='server {\n' + content_server=$content_server" listen ${USE_LISTEN_PORT};\n" + content_server=$content_server' location / {\n' + content_server=$content_server' try_files $uri @app;\n' content_server=$content_server' }\n' + content_server=$content_server' location @app {\n' + content_server=$content_server' include uwsgi_params;\n' + content_server=$content_server' uwsgi_pass unix:///tmp/uwsgi.sock;\n' + content_server=$content_server' }\n' + content_server=$content_server" location $USE_STATIC_URL {\n" + content_server=$content_server" alias $USE_STATIC_PATH;\n" + content_server=$content_server' }\n' + # If STATIC_INDEX is 1, serve / with /static/index.html directly (or the static URL configured) + if [ "$STATIC_INDEX" = 1 ] ; then + content_server=$content_server' location = / {\n' + content_server=$content_server" index $USE_STATIC_URL/index.html;\n" + content_server=$content_server' }\n' + fi + content_server=$content_server'}\n' + # Save generated server /etc/nginx/conf.d/nginx.conf + printf "$content_server" > /etc/nginx/conf.d/nginx.conf fi -content_server=$content_server'}\n' -# Save generated server /etc/nginx/conf.d/nginx.conf -printf "$content_server" > /etc/nginx/conf.d/nginx.conf exec "$@" diff --git a/python2.7-alpine3.8/entrypoint.sh b/python2.7-alpine3.8/entrypoint.sh index 1907b933..20867bdd 100644 --- a/python2.7-alpine3.8/entrypoint.sh +++ b/python2.7-alpine3.8/entrypoint.sh @@ -14,26 +14,30 @@ USE_STATIC_PATH=${STATIC_PATH:-'/app/static'} # Get the listen port for Nginx, default to 80 USE_LISTEN_PORT=${LISTEN_PORT:-80} -content_server='server {\n' -content_server=$content_server" listen ${USE_LISTEN_PORT};\n" -content_server=$content_server' location / {\n' -content_server=$content_server' try_files $uri @app;\n' -content_server=$content_server' }\n' -content_server=$content_server' location @app {\n' -content_server=$content_server' include uwsgi_params;\n' -content_server=$content_server' uwsgi_pass unix:///tmp/uwsgi.sock;\n' -content_server=$content_server' }\n' -content_server=$content_server" location $USE_STATIC_URL {\n" -content_server=$content_server" alias $USE_STATIC_PATH;\n" -content_server=$content_server' }\n' -# If STATIC_INDEX is 1, serve / with /static/index.html directly (or the static URL configured) -if [ "$STATIC_INDEX" = 1 ] ; then - content_server=$content_server' location = / {\n' - content_server=$content_server" index $USE_STATIC_URL/index.html;\n" +if [ -f /app/nginx.conf ]; then + cp /app/nginx.conf /etc/nginx/nginx.conf +else + content_server='server {\n' + content_server=$content_server" listen ${USE_LISTEN_PORT};\n" + content_server=$content_server' location / {\n' + content_server=$content_server' try_files $uri @app;\n' content_server=$content_server' }\n' + content_server=$content_server' location @app {\n' + content_server=$content_server' include uwsgi_params;\n' + content_server=$content_server' uwsgi_pass unix:///tmp/uwsgi.sock;\n' + content_server=$content_server' }\n' + content_server=$content_server" location $USE_STATIC_URL {\n" + content_server=$content_server" alias $USE_STATIC_PATH;\n" + content_server=$content_server' }\n' + # If STATIC_INDEX is 1, serve / with /static/index.html directly (or the static URL configured) + if [ "$STATIC_INDEX" = 1 ] ; then + content_server=$content_server' location = / {\n' + content_server=$content_server" index $USE_STATIC_URL/index.html;\n" + content_server=$content_server' }\n' + fi + content_server=$content_server'}\n' + # Save generated server /etc/nginx/conf.d/nginx.conf + printf "$content_server" > /etc/nginx/conf.d/nginx.conf fi -content_server=$content_server'}\n' -# Save generated server /etc/nginx/conf.d/nginx.conf -printf "$content_server" > /etc/nginx/conf.d/nginx.conf exec "$@" diff --git a/python2.7/entrypoint.sh b/python2.7/entrypoint.sh index c253ac4c..0f458269 100644 --- a/python2.7/entrypoint.sh +++ b/python2.7/entrypoint.sh @@ -10,26 +10,30 @@ USE_STATIC_PATH=${STATIC_PATH:-'/app/static'} # Get the listen port for Nginx, default to 80 USE_LISTEN_PORT=${LISTEN_PORT:-80} -content_server='server {\n' -content_server=$content_server" listen ${USE_LISTEN_PORT};\n" -content_server=$content_server' location / {\n' -content_server=$content_server' try_files $uri @app;\n' -content_server=$content_server' }\n' -content_server=$content_server' location @app {\n' -content_server=$content_server' include uwsgi_params;\n' -content_server=$content_server' uwsgi_pass unix:///tmp/uwsgi.sock;\n' -content_server=$content_server' }\n' -content_server=$content_server" location $USE_STATIC_URL {\n" -content_server=$content_server" alias $USE_STATIC_PATH;\n" -content_server=$content_server' }\n' -# If STATIC_INDEX is 1, serve / with /static/index.html directly (or the static URL configured) -if [ "$STATIC_INDEX" = 1 ] ; then - content_server=$content_server' location = / {\n' - content_server=$content_server" index $USE_STATIC_URL/index.html;\n" +if [ -f /app/nginx.conf ]; then + cp /app/nginx.conf /etc/nginx/nginx.conf +else + content_server='server {\n' + content_server=$content_server" listen ${USE_LISTEN_PORT};\n" + content_server=$content_server' location / {\n' + content_server=$content_server' try_files $uri @app;\n' content_server=$content_server' }\n' + content_server=$content_server' location @app {\n' + content_server=$content_server' include uwsgi_params;\n' + content_server=$content_server' uwsgi_pass unix:///tmp/uwsgi.sock;\n' + content_server=$content_server' }\n' + content_server=$content_server" location $USE_STATIC_URL {\n" + content_server=$content_server" alias $USE_STATIC_PATH;\n" + content_server=$content_server' }\n' + # If STATIC_INDEX is 1, serve / with /static/index.html directly (or the static URL configured) + if [ "$STATIC_INDEX" = 1 ] ; then + content_server=$content_server' location = / {\n' + content_server=$content_server" index $USE_STATIC_URL/index.html;\n" + content_server=$content_server' }\n' + fi + content_server=$content_server'}\n' + # Save generated server /etc/nginx/conf.d/nginx.conf + printf "$content_server" > /etc/nginx/conf.d/nginx.conf fi -content_server=$content_server'}\n' -# Save generated server /etc/nginx/conf.d/nginx.conf -printf "$content_server" > /etc/nginx/conf.d/nginx.conf exec "$@" diff --git a/python3.5/entrypoint.sh b/python3.5/entrypoint.sh index 9254a4c2..3d0372b5 100644 --- a/python3.5/entrypoint.sh +++ b/python3.5/entrypoint.sh @@ -10,26 +10,30 @@ USE_STATIC_PATH=${STATIC_PATH:-'/app/static'} # Get the listen port for Nginx, default to 80 USE_LISTEN_PORT=${LISTEN_PORT:-80} -content_server='server {\n' -content_server=$content_server" listen ${USE_LISTEN_PORT};\n" -content_server=$content_server' location / {\n' -content_server=$content_server' try_files $uri @app;\n' -content_server=$content_server' }\n' -content_server=$content_server' location @app {\n' -content_server=$content_server' include uwsgi_params;\n' -content_server=$content_server' uwsgi_pass unix:///tmp/uwsgi.sock;\n' -content_server=$content_server' }\n' -content_server=$content_server" location $USE_STATIC_URL {\n" -content_server=$content_server" alias $USE_STATIC_PATH;\n" -content_server=$content_server' }\n' -# If STATIC_INDEX is 1, serve / with /static/index.html directly (or the static URL configured) -if [ "$STATIC_INDEX" = 1 ] ; then - content_server=$content_server' location = / {\n' - content_server=$content_server" index $USE_STATIC_URL/index.html;\n" +if [ -f /app/nginx.conf ]; then + cp /app/nginx.conf /etc/nginx/nginx.conf +else + content_server='server {\n' + content_server=$content_server" listen ${USE_LISTEN_PORT};\n" + content_server=$content_server' location / {\n' + content_server=$content_server' try_files $uri @app;\n' content_server=$content_server' }\n' + content_server=$content_server' location @app {\n' + content_server=$content_server' include uwsgi_params;\n' + content_server=$content_server' uwsgi_pass unix:///tmp/uwsgi.sock;\n' + content_server=$content_server' }\n' + content_server=$content_server" location $USE_STATIC_URL {\n" + content_server=$content_server" alias $USE_STATIC_PATH;\n" + content_server=$content_server' }\n' + # If STATIC_INDEX is 1, serve / with /static/index.html directly (or the static URL configured) + if [ "$STATIC_INDEX" = 1 ] ; then + content_server=$content_server' location = / {\n' + content_server=$content_server" index $USE_STATIC_URL/index.html;\n" + content_server=$content_server' }\n' + fi + content_server=$content_server'}\n' + # Save generated server /etc/nginx/conf.d/nginx.conf + printf "$content_server" > /etc/nginx/conf.d/nginx.conf fi -content_server=$content_server'}\n' -# Save generated server /etc/nginx/conf.d/nginx.conf -printf "$content_server" > /etc/nginx/conf.d/nginx.conf exec "$@" diff --git a/python3.6-alpine3.7/entrypoint.sh b/python3.6-alpine3.7/entrypoint.sh index ad62bf3b..e933646a 100644 --- a/python3.6-alpine3.7/entrypoint.sh +++ b/python3.6-alpine3.7/entrypoint.sh @@ -14,26 +14,30 @@ USE_STATIC_PATH=${STATIC_PATH:-'/app/static'} # Get the listen port for Nginx, default to 80 USE_LISTEN_PORT=${LISTEN_PORT:-80} -content_server='server {\n' -content_server=$content_server" listen ${USE_LISTEN_PORT};\n" -content_server=$content_server' location / {\n' -content_server=$content_server' try_files $uri @app;\n' -content_server=$content_server' }\n' -content_server=$content_server' location @app {\n' -content_server=$content_server' include uwsgi_params;\n' -content_server=$content_server' uwsgi_pass unix:///tmp/uwsgi.sock;\n' -content_server=$content_server' }\n' -content_server=$content_server" location $USE_STATIC_URL {\n" -content_server=$content_server" alias $USE_STATIC_PATH;\n" -content_server=$content_server' }\n' -# If STATIC_INDEX is 1, serve / with /static/index.html directly (or the static URL configured) -if [ "$STATIC_INDEX" = 1 ] ; then - content_server=$content_server' location = / {\n' - content_server=$content_server" index $USE_STATIC_URL/index.html;\n" +if [ -f /app/nginx.conf ]; then + cp /app/nginx.conf /etc/nginx/nginx.conf +else + content_server='server {\n' + content_server=$content_server" listen ${USE_LISTEN_PORT};\n" + content_server=$content_server' location / {\n' + content_server=$content_server' try_files $uri @app;\n' content_server=$content_server' }\n' + content_server=$content_server' location @app {\n' + content_server=$content_server' include uwsgi_params;\n' + content_server=$content_server' uwsgi_pass unix:///tmp/uwsgi.sock;\n' + content_server=$content_server' }\n' + content_server=$content_server" location $USE_STATIC_URL {\n" + content_server=$content_server" alias $USE_STATIC_PATH;\n" + content_server=$content_server' }\n' + # If STATIC_INDEX is 1, serve / with /static/index.html directly (or the static URL configured) + if [ "$STATIC_INDEX" = 1 ] ; then + content_server=$content_server' location = / {\n' + content_server=$content_server" index $USE_STATIC_URL/index.html;\n" + content_server=$content_server' }\n' + fi + content_server=$content_server'}\n' + # Save generated server /etc/nginx/conf.d/nginx.conf + printf "$content_server" > /etc/nginx/conf.d/nginx.conf fi -content_server=$content_server'}\n' -# Save generated server /etc/nginx/conf.d/nginx.conf -printf "$content_server" > /etc/nginx/conf.d/nginx.conf exec "$@" diff --git a/python3.6-alpine3.8/entrypoint.sh b/python3.6-alpine3.8/entrypoint.sh index ad62bf3b..e933646a 100644 --- a/python3.6-alpine3.8/entrypoint.sh +++ b/python3.6-alpine3.8/entrypoint.sh @@ -14,26 +14,30 @@ USE_STATIC_PATH=${STATIC_PATH:-'/app/static'} # Get the listen port for Nginx, default to 80 USE_LISTEN_PORT=${LISTEN_PORT:-80} -content_server='server {\n' -content_server=$content_server" listen ${USE_LISTEN_PORT};\n" -content_server=$content_server' location / {\n' -content_server=$content_server' try_files $uri @app;\n' -content_server=$content_server' }\n' -content_server=$content_server' location @app {\n' -content_server=$content_server' include uwsgi_params;\n' -content_server=$content_server' uwsgi_pass unix:///tmp/uwsgi.sock;\n' -content_server=$content_server' }\n' -content_server=$content_server" location $USE_STATIC_URL {\n" -content_server=$content_server" alias $USE_STATIC_PATH;\n" -content_server=$content_server' }\n' -# If STATIC_INDEX is 1, serve / with /static/index.html directly (or the static URL configured) -if [ "$STATIC_INDEX" = 1 ] ; then - content_server=$content_server' location = / {\n' - content_server=$content_server" index $USE_STATIC_URL/index.html;\n" +if [ -f /app/nginx.conf ]; then + cp /app/nginx.conf /etc/nginx/nginx.conf +else + content_server='server {\n' + content_server=$content_server" listen ${USE_LISTEN_PORT};\n" + content_server=$content_server' location / {\n' + content_server=$content_server' try_files $uri @app;\n' content_server=$content_server' }\n' + content_server=$content_server' location @app {\n' + content_server=$content_server' include uwsgi_params;\n' + content_server=$content_server' uwsgi_pass unix:///tmp/uwsgi.sock;\n' + content_server=$content_server' }\n' + content_server=$content_server" location $USE_STATIC_URL {\n" + content_server=$content_server" alias $USE_STATIC_PATH;\n" + content_server=$content_server' }\n' + # If STATIC_INDEX is 1, serve / with /static/index.html directly (or the static URL configured) + if [ "$STATIC_INDEX" = 1 ] ; then + content_server=$content_server' location = / {\n' + content_server=$content_server" index $USE_STATIC_URL/index.html;\n" + content_server=$content_server' }\n' + fi + content_server=$content_server'}\n' + # Save generated server /etc/nginx/conf.d/nginx.conf + printf "$content_server" > /etc/nginx/conf.d/nginx.conf fi -content_server=$content_server'}\n' -# Save generated server /etc/nginx/conf.d/nginx.conf -printf "$content_server" > /etc/nginx/conf.d/nginx.conf exec "$@" diff --git a/python3.6/entrypoint.sh b/python3.6/entrypoint.sh index c253ac4c..0f458269 100644 --- a/python3.6/entrypoint.sh +++ b/python3.6/entrypoint.sh @@ -10,26 +10,30 @@ USE_STATIC_PATH=${STATIC_PATH:-'/app/static'} # Get the listen port for Nginx, default to 80 USE_LISTEN_PORT=${LISTEN_PORT:-80} -content_server='server {\n' -content_server=$content_server" listen ${USE_LISTEN_PORT};\n" -content_server=$content_server' location / {\n' -content_server=$content_server' try_files $uri @app;\n' -content_server=$content_server' }\n' -content_server=$content_server' location @app {\n' -content_server=$content_server' include uwsgi_params;\n' -content_server=$content_server' uwsgi_pass unix:///tmp/uwsgi.sock;\n' -content_server=$content_server' }\n' -content_server=$content_server" location $USE_STATIC_URL {\n" -content_server=$content_server" alias $USE_STATIC_PATH;\n" -content_server=$content_server' }\n' -# If STATIC_INDEX is 1, serve / with /static/index.html directly (or the static URL configured) -if [ "$STATIC_INDEX" = 1 ] ; then - content_server=$content_server' location = / {\n' - content_server=$content_server" index $USE_STATIC_URL/index.html;\n" +if [ -f /app/nginx.conf ]; then + cp /app/nginx.conf /etc/nginx/nginx.conf +else + content_server='server {\n' + content_server=$content_server" listen ${USE_LISTEN_PORT};\n" + content_server=$content_server' location / {\n' + content_server=$content_server' try_files $uri @app;\n' content_server=$content_server' }\n' + content_server=$content_server' location @app {\n' + content_server=$content_server' include uwsgi_params;\n' + content_server=$content_server' uwsgi_pass unix:///tmp/uwsgi.sock;\n' + content_server=$content_server' }\n' + content_server=$content_server" location $USE_STATIC_URL {\n" + content_server=$content_server" alias $USE_STATIC_PATH;\n" + content_server=$content_server' }\n' + # If STATIC_INDEX is 1, serve / with /static/index.html directly (or the static URL configured) + if [ "$STATIC_INDEX" = 1 ] ; then + content_server=$content_server' location = / {\n' + content_server=$content_server" index $USE_STATIC_URL/index.html;\n" + content_server=$content_server' }\n' + fi + content_server=$content_server'}\n' + # Save generated server /etc/nginx/conf.d/nginx.conf + printf "$content_server" > /etc/nginx/conf.d/nginx.conf fi -content_server=$content_server'}\n' -# Save generated server /etc/nginx/conf.d/nginx.conf -printf "$content_server" > /etc/nginx/conf.d/nginx.conf exec "$@" diff --git a/python3.7-alpine3.7/entrypoint.sh b/python3.7-alpine3.7/entrypoint.sh index 0219dd53..7ff34758 100644 --- a/python3.7-alpine3.7/entrypoint.sh +++ b/python3.7-alpine3.7/entrypoint.sh @@ -14,26 +14,30 @@ USE_STATIC_PATH=${STATIC_PATH:-'/app/static'} # Get the listen port for Nginx, default to 80 USE_LISTEN_PORT=${LISTEN_PORT:-80} -content_server='server {\n' -content_server=$content_server" listen ${USE_LISTEN_PORT};\n" -content_server=$content_server' location / {\n' -content_server=$content_server' try_files $uri @app;\n' -content_server=$content_server' }\n' -content_server=$content_server' location @app {\n' -content_server=$content_server' include uwsgi_params;\n' -content_server=$content_server' uwsgi_pass unix:///tmp/uwsgi.sock;\n' -content_server=$content_server' }\n' -content_server=$content_server" location $USE_STATIC_URL {\n" -content_server=$content_server" alias $USE_STATIC_PATH;\n" -content_server=$content_server' }\n' -# If STATIC_INDEX is 1, serve / with /static/index.html directly (or the static URL configured) -if [ "$STATIC_INDEX" = 1 ] ; then - content_server=$content_server' location = / {\n' - content_server=$content_server" index $USE_STATIC_URL/index.html;\n" +if [ -f /app/nginx.conf ]; then + cp /app/nginx.conf /etc/nginx/nginx.conf +else + content_server='server {\n' + content_server=$content_server" listen ${USE_LISTEN_PORT};\n" + content_server=$content_server' location / {\n' + content_server=$content_server' try_files $uri @app;\n' content_server=$content_server' }\n' + content_server=$content_server' location @app {\n' + content_server=$content_server' include uwsgi_params;\n' + content_server=$content_server' uwsgi_pass unix:///tmp/uwsgi.sock;\n' + content_server=$content_server' }\n' + content_server=$content_server" location $USE_STATIC_URL {\n" + content_server=$content_server" alias $USE_STATIC_PATH;\n" + content_server=$content_server' }\n' + # If STATIC_INDEX is 1, serve / with /static/index.html directly (or the static URL configured) + if [ "$STATIC_INDEX" = 1 ] ; then + content_server=$content_server' location = / {\n' + content_server=$content_server" index $USE_STATIC_URL/index.html;\n" + content_server=$content_server' }\n' + fi + content_server=$content_server'}\n' + # Save generated server /etc/nginx/conf.d/nginx.conf + printf "$content_server" > /etc/nginx/conf.d/nginx.conf fi -content_server=$content_server'}\n' -# Save generated server /etc/nginx/conf.d/nginx.conf -printf "$content_server" > /etc/nginx/conf.d/nginx.conf exec "$@" diff --git a/python3.7-alpine3.8/entrypoint.sh b/python3.7-alpine3.8/entrypoint.sh index 0219dd53..7ff34758 100644 --- a/python3.7-alpine3.8/entrypoint.sh +++ b/python3.7-alpine3.8/entrypoint.sh @@ -14,26 +14,30 @@ USE_STATIC_PATH=${STATIC_PATH:-'/app/static'} # Get the listen port for Nginx, default to 80 USE_LISTEN_PORT=${LISTEN_PORT:-80} -content_server='server {\n' -content_server=$content_server" listen ${USE_LISTEN_PORT};\n" -content_server=$content_server' location / {\n' -content_server=$content_server' try_files $uri @app;\n' -content_server=$content_server' }\n' -content_server=$content_server' location @app {\n' -content_server=$content_server' include uwsgi_params;\n' -content_server=$content_server' uwsgi_pass unix:///tmp/uwsgi.sock;\n' -content_server=$content_server' }\n' -content_server=$content_server" location $USE_STATIC_URL {\n" -content_server=$content_server" alias $USE_STATIC_PATH;\n" -content_server=$content_server' }\n' -# If STATIC_INDEX is 1, serve / with /static/index.html directly (or the static URL configured) -if [ "$STATIC_INDEX" = 1 ] ; then - content_server=$content_server' location = / {\n' - content_server=$content_server" index $USE_STATIC_URL/index.html;\n" +if [ -f /app/nginx.conf ]; then + cp /app/nginx.conf /etc/nginx/nginx.conf +else + content_server='server {\n' + content_server=$content_server" listen ${USE_LISTEN_PORT};\n" + content_server=$content_server' location / {\n' + content_server=$content_server' try_files $uri @app;\n' content_server=$content_server' }\n' + content_server=$content_server' location @app {\n' + content_server=$content_server' include uwsgi_params;\n' + content_server=$content_server' uwsgi_pass unix:///tmp/uwsgi.sock;\n' + content_server=$content_server' }\n' + content_server=$content_server" location $USE_STATIC_URL {\n" + content_server=$content_server" alias $USE_STATIC_PATH;\n" + content_server=$content_server' }\n' + # If STATIC_INDEX is 1, serve / with /static/index.html directly (or the static URL configured) + if [ "$STATIC_INDEX" = 1 ] ; then + content_server=$content_server' location = / {\n' + content_server=$content_server" index $USE_STATIC_URL/index.html;\n" + content_server=$content_server' }\n' + fi + content_server=$content_server'}\n' + # Save generated server /etc/nginx/conf.d/nginx.conf + printf "$content_server" > /etc/nginx/conf.d/nginx.conf fi -content_server=$content_server'}\n' -# Save generated server /etc/nginx/conf.d/nginx.conf -printf "$content_server" > /etc/nginx/conf.d/nginx.conf exec "$@" diff --git a/python3.7/entrypoint.sh b/python3.7/entrypoint.sh index c253ac4c..0f458269 100644 --- a/python3.7/entrypoint.sh +++ b/python3.7/entrypoint.sh @@ -10,26 +10,30 @@ USE_STATIC_PATH=${STATIC_PATH:-'/app/static'} # Get the listen port for Nginx, default to 80 USE_LISTEN_PORT=${LISTEN_PORT:-80} -content_server='server {\n' -content_server=$content_server" listen ${USE_LISTEN_PORT};\n" -content_server=$content_server' location / {\n' -content_server=$content_server' try_files $uri @app;\n' -content_server=$content_server' }\n' -content_server=$content_server' location @app {\n' -content_server=$content_server' include uwsgi_params;\n' -content_server=$content_server' uwsgi_pass unix:///tmp/uwsgi.sock;\n' -content_server=$content_server' }\n' -content_server=$content_server" location $USE_STATIC_URL {\n" -content_server=$content_server" alias $USE_STATIC_PATH;\n" -content_server=$content_server' }\n' -# If STATIC_INDEX is 1, serve / with /static/index.html directly (or the static URL configured) -if [ "$STATIC_INDEX" = 1 ] ; then - content_server=$content_server' location = / {\n' - content_server=$content_server" index $USE_STATIC_URL/index.html;\n" +if [ -f /app/nginx.conf ]; then + cp /app/nginx.conf /etc/nginx/nginx.conf +else + content_server='server {\n' + content_server=$content_server" listen ${USE_LISTEN_PORT};\n" + content_server=$content_server' location / {\n' + content_server=$content_server' try_files $uri @app;\n' content_server=$content_server' }\n' + content_server=$content_server' location @app {\n' + content_server=$content_server' include uwsgi_params;\n' + content_server=$content_server' uwsgi_pass unix:///tmp/uwsgi.sock;\n' + content_server=$content_server' }\n' + content_server=$content_server" location $USE_STATIC_URL {\n" + content_server=$content_server" alias $USE_STATIC_PATH;\n" + content_server=$content_server' }\n' + # If STATIC_INDEX is 1, serve / with /static/index.html directly (or the static URL configured) + if [ "$STATIC_INDEX" = 1 ] ; then + content_server=$content_server' location = / {\n' + content_server=$content_server" index $USE_STATIC_URL/index.html;\n" + content_server=$content_server' }\n' + fi + content_server=$content_server'}\n' + # Save generated server /etc/nginx/conf.d/nginx.conf + printf "$content_server" > /etc/nginx/conf.d/nginx.conf fi -content_server=$content_server'}\n' -# Save generated server /etc/nginx/conf.d/nginx.conf -printf "$content_server" > /etc/nginx/conf.d/nginx.conf exec "$@" diff --git a/tests/test_02_app/custom_nginx_app/app/main.py b/tests/test_02_app/custom_nginx_app/app/main.py new file mode 100644 index 00000000..99bcb1d2 --- /dev/null +++ b/tests/test_02_app/custom_nginx_app/app/main.py @@ -0,0 +1,23 @@ +import sys + +from flask import Flask + +app = Flask(__name__) + + +@app.route("/") +def hello(): + version = "{}.{}".format(sys.version_info.major, sys.version_info.minor) + message = "Hello World from Flask in a uWSGI Nginx Docker container with Python {} - testing".format( + version + ) + return message + + +@app.route("/static/test.txt") +def static_test(): + return "Static, from Flask" + + +if __name__ == "__main__": + app.run(host="0.0.0.0", debug=True, port=80) diff --git a/tests/test_02_app/custom_nginx_app/app/nginx.conf b/tests/test_02_app/custom_nginx_app/app/nginx.conf new file mode 100644 index 00000000..7f874477 --- /dev/null +++ b/tests/test_02_app/custom_nginx_app/app/nginx.conf @@ -0,0 +1,28 @@ +user nginx; +worker_processes 2; +error_log /var/log/nginx/error.log warn; +pid /var/run/nginx.pid; +events { + worker_connections 2048; +} +http { + include /etc/nginx/mime.types; + default_type application/octet-stream; + log_format main '$remote_addr - $remote_user [$time_local] "$request" ' + '$status $body_bytes_sent "$http_referer" ' + '"$http_user_agent" "$http_x_forwarded_for"'; + access_log /var/log/nginx/access.log main; + sendfile on; + keepalive_timeout 300; + server { + listen 8080; + location / { + try_files $uri @app; + } + location @app { + include uwsgi_params; + uwsgi_pass unix:///tmp/uwsgi.sock; + } + } +} +daemon off; diff --git a/tests/test_02_app/custom_nginx_app/latest.dockerfile b/tests/test_02_app/custom_nginx_app/latest.dockerfile new file mode 100644 index 00000000..dd651277 --- /dev/null +++ b/tests/test_02_app/custom_nginx_app/latest.dockerfile @@ -0,0 +1,3 @@ +FROM tiangolo/uwsgi-nginx-flask:latest + +COPY app /app diff --git a/tests/test_02_app/custom_nginx_app/python2.7-alpine3.7.dockerfile b/tests/test_02_app/custom_nginx_app/python2.7-alpine3.7.dockerfile new file mode 100644 index 00000000..1bf89a03 --- /dev/null +++ b/tests/test_02_app/custom_nginx_app/python2.7-alpine3.7.dockerfile @@ -0,0 +1,3 @@ +FROM tiangolo/uwsgi-nginx-flask:python2.7-alpine3.7 + +COPY app /app diff --git a/tests/test_02_app/custom_nginx_app/python2.7-alpine3.8.dockerfile b/tests/test_02_app/custom_nginx_app/python2.7-alpine3.8.dockerfile new file mode 100644 index 00000000..1732878d --- /dev/null +++ b/tests/test_02_app/custom_nginx_app/python2.7-alpine3.8.dockerfile @@ -0,0 +1,3 @@ +FROM tiangolo/uwsgi-nginx-flask:python2.7-alpine3.8 + +COPY app /app diff --git a/tests/test_02_app/custom_nginx_app/python2.7.dockerfile b/tests/test_02_app/custom_nginx_app/python2.7.dockerfile new file mode 100644 index 00000000..b97f19ed --- /dev/null +++ b/tests/test_02_app/custom_nginx_app/python2.7.dockerfile @@ -0,0 +1,3 @@ +FROM tiangolo/uwsgi-nginx-flask:python2.7 + +COPY app /app diff --git a/tests/test_02_app/custom_nginx_app/python3.5.dockerfile b/tests/test_02_app/custom_nginx_app/python3.5.dockerfile new file mode 100644 index 00000000..82319782 --- /dev/null +++ b/tests/test_02_app/custom_nginx_app/python3.5.dockerfile @@ -0,0 +1,3 @@ +FROM tiangolo/uwsgi-nginx-flask:python3.5 + +COPY app /app diff --git a/tests/test_02_app/custom_nginx_app/python3.6-alpine3.7.dockerfile b/tests/test_02_app/custom_nginx_app/python3.6-alpine3.7.dockerfile new file mode 100644 index 00000000..4829cdfe --- /dev/null +++ b/tests/test_02_app/custom_nginx_app/python3.6-alpine3.7.dockerfile @@ -0,0 +1,3 @@ +FROM tiangolo/uwsgi-nginx-flask:python3.6-alpine3.7 + +COPY app /app diff --git a/tests/test_02_app/custom_nginx_app/python3.6-alpine3.8.dockerfile b/tests/test_02_app/custom_nginx_app/python3.6-alpine3.8.dockerfile new file mode 100644 index 00000000..2d1e8717 --- /dev/null +++ b/tests/test_02_app/custom_nginx_app/python3.6-alpine3.8.dockerfile @@ -0,0 +1,3 @@ +FROM tiangolo/uwsgi-nginx-flask:python3.6-alpine3.8 + +COPY app /app diff --git a/tests/test_02_app/custom_nginx_app/python3.6.dockerfile b/tests/test_02_app/custom_nginx_app/python3.6.dockerfile new file mode 100644 index 00000000..02c9bcfc --- /dev/null +++ b/tests/test_02_app/custom_nginx_app/python3.6.dockerfile @@ -0,0 +1,3 @@ +FROM tiangolo/uwsgi-nginx-flask:python3.6 + +COPY app /app diff --git a/tests/test_02_app/custom_nginx_app/python3.7-alpine3.7.dockerfile b/tests/test_02_app/custom_nginx_app/python3.7-alpine3.7.dockerfile new file mode 100644 index 00000000..5826e772 --- /dev/null +++ b/tests/test_02_app/custom_nginx_app/python3.7-alpine3.7.dockerfile @@ -0,0 +1,3 @@ +FROM tiangolo/uwsgi-nginx-flask:python3.7-alpine3.7 + +COPY app /app diff --git a/tests/test_02_app/custom_nginx_app/python3.7-alpine3.8.dockerfile b/tests/test_02_app/custom_nginx_app/python3.7-alpine3.8.dockerfile new file mode 100644 index 00000000..bb212de1 --- /dev/null +++ b/tests/test_02_app/custom_nginx_app/python3.7-alpine3.8.dockerfile @@ -0,0 +1,3 @@ +FROM tiangolo/uwsgi-nginx-flask:python3.7-alpine3.8 + +COPY app /app diff --git a/tests/test_02_app/custom_nginx_app/python3.7.dockerfile b/tests/test_02_app/custom_nginx_app/python3.7.dockerfile new file mode 100644 index 00000000..1099189e --- /dev/null +++ b/tests/test_02_app/custom_nginx_app/python3.7.dockerfile @@ -0,0 +1,3 @@ +FROM tiangolo/uwsgi-nginx-flask:python3.7 + +COPY app /app diff --git a/tests/test_02_app/test_custom_ngnix_app.py b/tests/test_02_app/test_custom_ngnix_app.py new file mode 100644 index 00000000..0af6af92 --- /dev/null +++ b/tests/test_02_app/test_custom_ngnix_app.py @@ -0,0 +1,138 @@ +import time +from pathlib import Path, PurePath + +import docker +import pytest +import requests + +from ..utils import ( + CONTAINER_NAME, + get_logs, + get_nginx_config, + remove_previous_container, +) + +client = docker.from_env() + + +def verify_container(container, response_text): + nginx_config = get_nginx_config(container) + assert "client_max_body_size 0;" not in nginx_config + assert "worker_processes 2;" in nginx_config + assert "listen 8080;" in nginx_config + assert "worker_connections 2048;" in nginx_config + assert "worker_rlimit_nofile;" not in nginx_config + assert "daemon off;" in nginx_config + assert "include uwsgi_params;" in nginx_config + assert "uwsgi_pass unix:///tmp/uwsgi.sock;" in nginx_config + assert "try_files $uri @app;" in nginx_config + assert "location @app {" in nginx_config + assert "include uwsgi_params;" in nginx_config + assert "location /static {" not in nginx_config + assert "alias /app/static;" not in nginx_config + # Nginx index.html specific + assert "location = / {" not in nginx_config + assert "index /static/index.html;" not in nginx_config + logs = get_logs(container) + assert "getting INI configuration from /app/uwsgi.ini" in logs + assert "getting INI configuration from /etc/uwsgi/uwsgi.ini" in logs + assert "ini = /app/uwsgi.ini" in logs + assert "ini = /etc/uwsgi/uwsgi.ini" in logs + assert "socket = /tmp/uwsgi.sock" in logs + assert "chown-socket = nginx:nginx" in logs + assert "chmod-socket = 664" in logs + assert "hook-master-start = unix_signal:15 gracefully_kill_them_all" in logs + assert "need-app = true" in logs + assert "die-on-term = true" in logs + assert "show-config = true" in logs + assert "module = main" in logs + assert "callable = app" in logs + assert "processes = 16" in logs + assert "cheaper = 2" in logs + assert "Checking for script in /app/prestart.sh" in logs + assert "Running script /app/prestart.sh" in logs + assert ( + "Running inside /app/prestart.sh, you could add migrations to this file" in logs + ) + assert "spawned uWSGI master process" in logs + assert "spawned uWSGI worker 1" in logs + assert "spawned uWSGI worker 2" in logs + assert "spawned uWSGI worker 3" not in logs + assert 'running "unix_signal:15 gracefully_kill_them_all" (master-start)' in logs + assert "success: nginx entered RUNNING state, process has stayed up for" in logs + assert "success: uwsgi entered RUNNING state, process has stayed up for" in logs + response = requests.get("http://127.0.0.1:8080") + assert response.status_code == 200 + assert response.text == response_text + response = requests.get("http://127.0.0.1:8080/static/test.txt") + assert response.status_code == 200 + assert response.text == "Static, from Flask" + + +@pytest.mark.parametrize( + "dockerfile,response_text", + [ + ( + "python2.7.dockerfile", + "Hello World from Flask in a uWSGI Nginx Docker container with Python 2.7 - testing", + ), + ( + "python2.7-alpine3.7.dockerfile", + "Hello World from Flask in a uWSGI Nginx Docker container with Python 2.7 - testing", + ), + ( + "python2.7-alpine3.8.dockerfile", + "Hello World from Flask in a uWSGI Nginx Docker container with Python 2.7 - testing", + ), + ( + "python3.5.dockerfile", + "Hello World from Flask in a uWSGI Nginx Docker container with Python 3.5 - testing", + ), + ( + "python3.6.dockerfile", + "Hello World from Flask in a uWSGI Nginx Docker container with Python 3.6 - testing", + ), + ( + "python3.6-alpine3.7.dockerfile", + "Hello World from Flask in a uWSGI Nginx Docker container with Python 3.6 - testing", + ), + ( + "python3.6-alpine3.8.dockerfile", + "Hello World from Flask in a uWSGI Nginx Docker container with Python 3.6 - testing", + ), + ( + "python3.7.dockerfile", + "Hello World from Flask in a uWSGI Nginx Docker container with Python 3.7 - testing", + ), + ( + "latest.dockerfile", + "Hello World from Flask in a uWSGI Nginx Docker container with Python 3.7 - testing", + ), + # ( + # "python3.7-alpine3.7.dockerfile", + # "Hello World from Flask in a uWSGI Nginx Docker container with Python 3.7 - testing", + # ), + # ( + # "python3.7-alpine3.8.dockerfile", + # "Hello World from Flask in a uWSGI Nginx Docker container with Python 3.7 - testing", + # ), + ], +) +def test_env_vars_1(dockerfile, response_text): + remove_previous_container(client) + tag = "uwsgi-nginx-flask-testimage" + test_path: PurePath = Path(__file__) + path = test_path.parent / "custom_nginx_app" + client.images.build(path=str(path), dockerfile=dockerfile, tag=tag) + container = client.containers.run( + tag, name=CONTAINER_NAME, ports={"8080": "8080"}, detach=True + ) + time.sleep(5) + verify_container(container, response_text) + container.stop() + # Test that everything works after restarting too + container.start() + time.sleep(3) + verify_container(container, response_text) + container.stop() + container.remove()