diff --git a/python2.7-alpine3.7/Dockerfile b/python2.7-alpine3.7/Dockerfile index e75e181..c7a4eb6 100644 --- a/python2.7-alpine3.7/Dockerfile +++ b/python2.7-alpine3.7/Dockerfile @@ -139,8 +139,6 @@ RUN GPG_KEYS=B0F4253373F8F6F510D42178520A9993A1C052F8 \ && ln -sf /dev/stdout /var/log/nginx/access.log \ && ln -sf /dev/stderr /var/log/nginx/error.log -COPY nginx.conf /etc/nginx/nginx.conf - # Standard set up Nginx finished EXPOSE 80 @@ -152,10 +150,6 @@ EXPOSE 443 # Install uWSGI RUN apk add --no-cache uwsgi-python -# Make NGINX run on the foreground -RUN echo "daemon off;" >> /etc/nginx/nginx.conf -# Copy the modified Nginx conf -COPY nginx-custom.conf /etc/nginx/conf.d/nginx.conf # Copy the base uWSGI ini file to enable default dynamic uwsgi process number COPY uwsgi.ini /etc/uwsgi/ diff --git a/python2.7-alpine3.7/entrypoint.sh b/python2.7-alpine3.7/entrypoint.sh index d415a13..8071431 100644 --- a/python2.7-alpine3.7/entrypoint.sh +++ b/python2.7-alpine3.7/entrypoint.sh @@ -1,35 +1,61 @@ #!/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 - # 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 +# Get the maximum upload file size for Nginx, default to 0: unlimited +USE_NGINX_MAX_UPLOAD=${NGINX_MAX_UPLOAD:-0} + # 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 +# 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 +NGINX_WORKER_CONNECTIONS=${NGINX_WORKER_CONNECTIONS:-1024} # Get the listen port for Nginx, default to 80 USE_LISTEN_PORT=${LISTEN_PORT:-80} -# Modify Nginx config for listen port -if ! grep -q "listen ${USE_LISTEN_PORT};" /etc/nginx/conf.d/nginx.conf ; then - sed -i -e "/server {/a\ listen ${USE_LISTEN_PORT};" /etc/nginx/conf.d/nginx.conf + +content='user nginx;\n' +# Set the number of worker processes in Nginx +content=$content"worker_processes ${USE_NGINX_WORKER_PROCESSES};\n" +content=$content'error_log /var/log/nginx/error.log warn;\n' +content=$content'pid /var/run/nginx.pid;\n' +content=$content'events {\n' +content=$content" worker_connections ${NGINX_WORKER_CONNECTIONS};\n" +content=$content'}\n' +content=$content'http {\n' +content=$content' include /etc/nginx/mime.types;\n' +content=$content' default_type application/octet-stream;\n' +content=$content' log_format main '"'\$remote_addr - \$remote_user [\$time_local] \"\$request\" '\n" +content=$content' '"'\$status \$body_bytes_sent \"\$http_referer\" '\n" +content=$content' '"'\"\$http_user_agent\" \"\$http_x_forwarded_for\"';\n" +content=$content' access_log /var/log/nginx/access.log main;\n' +content=$content' sendfile on;\n' +content=$content' keepalive_timeout 65;\n' +content=$content' include /etc/nginx/conf.d/*.conf;\n' +content=$content'}\n' +content=$content'daemon off;\n' +# Set the max number of open file descriptors for Nginx workers, if requested +if [ -n "${NGINX_WORKER_OPEN_FILES}" ] ; then + content=$content"worker_rlimit_nofile ${NGINX_WORKER_OPEN_FILES};\n" fi +# Save generated /etc/nginx/nginx.conf +printf "$content" > /etc/nginx/nginx.conf + +content_server='server {\n' +content_server=$content_server" listen ${USE_LISTEN_PORT};\n" +content_server=$content_server' location / {\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'}\n' +# Save generated server /etc/nginx/conf.d/nginx.conf +printf "$content_server" > /etc/nginx/conf.d/nginx.conf + +# Generate Nginx config for maximum upload file size +printf "client_max_body_size $USE_NGINX_MAX_UPLOAD;\n" > /etc/nginx/conf.d/upload.conf + exec "$@" diff --git a/python2.7-alpine3.7/nginx-custom.conf b/python2.7-alpine3.7/nginx-custom.conf deleted file mode 100644 index eca3646..0000000 --- a/python2.7-alpine3.7/nginx-custom.conf +++ /dev/null @@ -1,6 +0,0 @@ -server { - location / { - include uwsgi_params; - uwsgi_pass unix:///tmp/uwsgi.sock; - } -} \ No newline at end of file diff --git a/python2.7-alpine3.7/nginx.conf b/python2.7-alpine3.7/nginx.conf deleted file mode 100644 index 7271761..0000000 --- a/python2.7-alpine3.7/nginx.conf +++ /dev/null @@ -1,31 +0,0 @@ -user nginx; -worker_processes 1; - -error_log /var/log/nginx/error.log warn; -pid /var/run/nginx.pid; - - -events { - worker_connections 1024; -} - - -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; - #tcp_nopush on; - - keepalive_timeout 65; - - #gzip on; - - include /etc/nginx/conf.d/*.conf; -} \ No newline at end of file diff --git a/python2.7-alpine3.8/Dockerfile b/python2.7-alpine3.8/Dockerfile index 037ec40..3ae72cd 100644 --- a/python2.7-alpine3.8/Dockerfile +++ b/python2.7-alpine3.8/Dockerfile @@ -139,8 +139,6 @@ RUN GPG_KEYS=B0F4253373F8F6F510D42178520A9993A1C052F8 \ && ln -sf /dev/stdout /var/log/nginx/access.log \ && ln -sf /dev/stderr /var/log/nginx/error.log -COPY nginx.conf /etc/nginx/nginx.conf - # Standard set up Nginx finished EXPOSE 80 @@ -152,10 +150,6 @@ EXPOSE 443 # Install uWSGI RUN apk add --no-cache uwsgi-python -# Make NGINX run on the foreground -RUN echo "daemon off;" >> /etc/nginx/nginx.conf -# Copy the modified Nginx conf -COPY nginx-custom.conf /etc/nginx/conf.d/nginx.conf # Copy the base uWSGI ini file to enable default dynamic uwsgi process number COPY uwsgi.ini /etc/uwsgi/ diff --git a/python2.7-alpine3.8/entrypoint.sh b/python2.7-alpine3.8/entrypoint.sh index d415a13..8071431 100644 --- a/python2.7-alpine3.8/entrypoint.sh +++ b/python2.7-alpine3.8/entrypoint.sh @@ -1,35 +1,61 @@ #!/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 - # 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 +# Get the maximum upload file size for Nginx, default to 0: unlimited +USE_NGINX_MAX_UPLOAD=${NGINX_MAX_UPLOAD:-0} + # 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 +# 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 +NGINX_WORKER_CONNECTIONS=${NGINX_WORKER_CONNECTIONS:-1024} # Get the listen port for Nginx, default to 80 USE_LISTEN_PORT=${LISTEN_PORT:-80} -# Modify Nginx config for listen port -if ! grep -q "listen ${USE_LISTEN_PORT};" /etc/nginx/conf.d/nginx.conf ; then - sed -i -e "/server {/a\ listen ${USE_LISTEN_PORT};" /etc/nginx/conf.d/nginx.conf + +content='user nginx;\n' +# Set the number of worker processes in Nginx +content=$content"worker_processes ${USE_NGINX_WORKER_PROCESSES};\n" +content=$content'error_log /var/log/nginx/error.log warn;\n' +content=$content'pid /var/run/nginx.pid;\n' +content=$content'events {\n' +content=$content" worker_connections ${NGINX_WORKER_CONNECTIONS};\n" +content=$content'}\n' +content=$content'http {\n' +content=$content' include /etc/nginx/mime.types;\n' +content=$content' default_type application/octet-stream;\n' +content=$content' log_format main '"'\$remote_addr - \$remote_user [\$time_local] \"\$request\" '\n" +content=$content' '"'\$status \$body_bytes_sent \"\$http_referer\" '\n" +content=$content' '"'\"\$http_user_agent\" \"\$http_x_forwarded_for\"';\n" +content=$content' access_log /var/log/nginx/access.log main;\n' +content=$content' sendfile on;\n' +content=$content' keepalive_timeout 65;\n' +content=$content' include /etc/nginx/conf.d/*.conf;\n' +content=$content'}\n' +content=$content'daemon off;\n' +# Set the max number of open file descriptors for Nginx workers, if requested +if [ -n "${NGINX_WORKER_OPEN_FILES}" ] ; then + content=$content"worker_rlimit_nofile ${NGINX_WORKER_OPEN_FILES};\n" fi +# Save generated /etc/nginx/nginx.conf +printf "$content" > /etc/nginx/nginx.conf + +content_server='server {\n' +content_server=$content_server" listen ${USE_LISTEN_PORT};\n" +content_server=$content_server' location / {\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'}\n' +# Save generated server /etc/nginx/conf.d/nginx.conf +printf "$content_server" > /etc/nginx/conf.d/nginx.conf + +# Generate Nginx config for maximum upload file size +printf "client_max_body_size $USE_NGINX_MAX_UPLOAD;\n" > /etc/nginx/conf.d/upload.conf + exec "$@" diff --git a/python2.7-alpine3.8/nginx-custom.conf b/python2.7-alpine3.8/nginx-custom.conf deleted file mode 100644 index eca3646..0000000 --- a/python2.7-alpine3.8/nginx-custom.conf +++ /dev/null @@ -1,6 +0,0 @@ -server { - location / { - include uwsgi_params; - uwsgi_pass unix:///tmp/uwsgi.sock; - } -} \ No newline at end of file diff --git a/python2.7-alpine3.8/nginx.conf b/python2.7-alpine3.8/nginx.conf deleted file mode 100644 index 7271761..0000000 --- a/python2.7-alpine3.8/nginx.conf +++ /dev/null @@ -1,31 +0,0 @@ -user nginx; -worker_processes 1; - -error_log /var/log/nginx/error.log warn; -pid /var/run/nginx.pid; - - -events { - worker_connections 1024; -} - - -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; - #tcp_nopush on; - - keepalive_timeout 65; - - #gzip on; - - include /etc/nginx/conf.d/*.conf; -} \ No newline at end of file diff --git a/python2.7/Dockerfile b/python2.7/Dockerfile index d07b26f..efd2056 100644 --- a/python2.7/Dockerfile +++ b/python2.7/Dockerfile @@ -104,12 +104,8 @@ EXPOSE 80 # Expose 443, in case of LTS / HTTPS EXPOSE 443 -# Make NGINX run on the foreground -RUN echo "daemon off;" >> /etc/nginx/nginx.conf # Remove default configuration from Nginx RUN rm /etc/nginx/conf.d/default.conf -# Copy the modified Nginx conf -COPY nginx.conf /etc/nginx/conf.d/ # Copy the base uWSGI ini file to enable default dynamic uwsgi process number COPY uwsgi.ini /etc/uwsgi/ diff --git a/python2.7/entrypoint.sh b/python2.7/entrypoint.sh index a8cf7d3..5306a8a 100644 --- a/python2.7/entrypoint.sh +++ b/python2.7/entrypoint.sh @@ -1,31 +1,57 @@ -#!/bin/bash +#!/usr/bin/env bash 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 +# Set the max number of connections per worker for Nginx, if requested # Cannot exceed worker_rlimit_nofile, see NGINX_WORKER_OPEN_FILES below -if [[ -v 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 [[ -v NGINX_WORKER_OPEN_FILES ]] ; then - echo "worker_rlimit_nofile ${NGINX_WORKER_OPEN_FILES};" >> /etc/nginx/nginx.conf -fi +NGINX_WORKER_CONNECTIONS=${NGINX_WORKER_CONNECTIONS:-1024} # Get the listen port for Nginx, default to 80 USE_LISTEN_PORT=${LISTEN_PORT:-80} -# Modify Nignx config for listen port -if ! grep -q "listen ${USE_LISTEN_PORT};" /etc/nginx/conf.d/nginx.conf ; then - sed -i -e "/server {/a\ listen ${USE_LISTEN_PORT};" /etc/nginx/conf.d/nginx.conf + +content='user nginx;\n' +# Set the number of worker processes in Nginx +content=$content"worker_processes ${USE_NGINX_WORKER_PROCESSES};\n" +content=$content'error_log /var/log/nginx/error.log warn;\n' +content=$content'pid /var/run/nginx.pid;\n' +content=$content'events {\n' +content=$content" worker_connections ${NGINX_WORKER_CONNECTIONS};\n" +content=$content'}\n' +content=$content'http {\n' +content=$content' include /etc/nginx/mime.types;\n' +content=$content' default_type application/octet-stream;\n' +content=$content' log_format main '"'\$remote_addr - \$remote_user [\$time_local] \"\$request\" '\n" +content=$content' '"'\$status \$body_bytes_sent \"\$http_referer\" '\n" +content=$content' '"'\"\$http_user_agent\" \"\$http_x_forwarded_for\"';\n" +content=$content' access_log /var/log/nginx/access.log main;\n' +content=$content' sendfile on;\n' +content=$content' keepalive_timeout 65;\n' +content=$content' include /etc/nginx/conf.d/*.conf;\n' +content=$content'}\n' +content=$content'daemon off;\n' +# Set the max number of open file descriptors for Nginx workers, if requested +if [ -n "${NGINX_WORKER_OPEN_FILES}" ] ; then + content=$content"worker_rlimit_nofile ${NGINX_WORKER_OPEN_FILES};\n" fi +# Save generated /etc/nginx/nginx.conf +printf "$content" > /etc/nginx/nginx.conf + +content_server='server {\n' +content_server=$content_server" listen ${USE_LISTEN_PORT};\n" +content_server=$content_server' location / {\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'}\n' +# Save generated server /etc/nginx/conf.d/nginx.conf +printf "$content_server" > /etc/nginx/conf.d/nginx.conf + +# Generate Nginx config for maximum upload file size +printf "client_max_body_size $USE_NGINX_MAX_UPLOAD;\n" > /etc/nginx/conf.d/upload.conf + exec "$@" diff --git a/python2.7/nginx.conf b/python2.7/nginx.conf deleted file mode 100644 index eca3646..0000000 --- a/python2.7/nginx.conf +++ /dev/null @@ -1,6 +0,0 @@ -server { - location / { - include uwsgi_params; - uwsgi_pass unix:///tmp/uwsgi.sock; - } -} \ No newline at end of file diff --git a/python3.5/Dockerfile b/python3.5/Dockerfile index e7eb6a8..888ec2e 100644 --- a/python3.5/Dockerfile +++ b/python3.5/Dockerfile @@ -102,12 +102,8 @@ EXPOSE 80 # apt-key adv --no-tty # Standard set up Nginx finished -# Make NGINX run on the foreground -RUN echo "daemon off;" >> /etc/nginx/nginx.conf # Remove default configuration from Nginx RUN rm /etc/nginx/conf.d/default.conf -# Copy the modified Nginx conf -COPY nginx.conf /etc/nginx/conf.d/ # Copy the base uWSGI ini file to enable default dynamic uwsgi process number COPY uwsgi.ini /etc/uwsgi/ diff --git a/python3.5/entrypoint.sh b/python3.5/entrypoint.sh index a8cf7d3..5306a8a 100644 --- a/python3.5/entrypoint.sh +++ b/python3.5/entrypoint.sh @@ -1,31 +1,57 @@ -#!/bin/bash +#!/usr/bin/env bash 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 +# Set the max number of connections per worker for Nginx, if requested # Cannot exceed worker_rlimit_nofile, see NGINX_WORKER_OPEN_FILES below -if [[ -v 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 [[ -v NGINX_WORKER_OPEN_FILES ]] ; then - echo "worker_rlimit_nofile ${NGINX_WORKER_OPEN_FILES};" >> /etc/nginx/nginx.conf -fi +NGINX_WORKER_CONNECTIONS=${NGINX_WORKER_CONNECTIONS:-1024} # Get the listen port for Nginx, default to 80 USE_LISTEN_PORT=${LISTEN_PORT:-80} -# Modify Nignx config for listen port -if ! grep -q "listen ${USE_LISTEN_PORT};" /etc/nginx/conf.d/nginx.conf ; then - sed -i -e "/server {/a\ listen ${USE_LISTEN_PORT};" /etc/nginx/conf.d/nginx.conf + +content='user nginx;\n' +# Set the number of worker processes in Nginx +content=$content"worker_processes ${USE_NGINX_WORKER_PROCESSES};\n" +content=$content'error_log /var/log/nginx/error.log warn;\n' +content=$content'pid /var/run/nginx.pid;\n' +content=$content'events {\n' +content=$content" worker_connections ${NGINX_WORKER_CONNECTIONS};\n" +content=$content'}\n' +content=$content'http {\n' +content=$content' include /etc/nginx/mime.types;\n' +content=$content' default_type application/octet-stream;\n' +content=$content' log_format main '"'\$remote_addr - \$remote_user [\$time_local] \"\$request\" '\n" +content=$content' '"'\$status \$body_bytes_sent \"\$http_referer\" '\n" +content=$content' '"'\"\$http_user_agent\" \"\$http_x_forwarded_for\"';\n" +content=$content' access_log /var/log/nginx/access.log main;\n' +content=$content' sendfile on;\n' +content=$content' keepalive_timeout 65;\n' +content=$content' include /etc/nginx/conf.d/*.conf;\n' +content=$content'}\n' +content=$content'daemon off;\n' +# Set the max number of open file descriptors for Nginx workers, if requested +if [ -n "${NGINX_WORKER_OPEN_FILES}" ] ; then + content=$content"worker_rlimit_nofile ${NGINX_WORKER_OPEN_FILES};\n" fi +# Save generated /etc/nginx/nginx.conf +printf "$content" > /etc/nginx/nginx.conf + +content_server='server {\n' +content_server=$content_server" listen ${USE_LISTEN_PORT};\n" +content_server=$content_server' location / {\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'}\n' +# Save generated server /etc/nginx/conf.d/nginx.conf +printf "$content_server" > /etc/nginx/conf.d/nginx.conf + +# Generate Nginx config for maximum upload file size +printf "client_max_body_size $USE_NGINX_MAX_UPLOAD;\n" > /etc/nginx/conf.d/upload.conf + exec "$@" diff --git a/python3.5/nginx.conf b/python3.5/nginx.conf deleted file mode 100644 index eca3646..0000000 --- a/python3.5/nginx.conf +++ /dev/null @@ -1,6 +0,0 @@ -server { - location / { - include uwsgi_params; - uwsgi_pass unix:///tmp/uwsgi.sock; - } -} \ No newline at end of file diff --git a/python3.6-alpine3.7/Dockerfile b/python3.6-alpine3.7/Dockerfile index f053a5c..b0cfc20 100644 --- a/python3.6-alpine3.7/Dockerfile +++ b/python3.6-alpine3.7/Dockerfile @@ -139,8 +139,6 @@ RUN GPG_KEYS=B0F4253373F8F6F510D42178520A9993A1C052F8 \ && ln -sf /dev/stdout /var/log/nginx/access.log \ && ln -sf /dev/stderr /var/log/nginx/error.log -COPY nginx.conf /etc/nginx/nginx.conf - # Standard set up Nginx finished EXPOSE 80 @@ -152,10 +150,6 @@ EXPOSE 443 # Install uWSGI RUN apk add --no-cache uwsgi-python3 -# Make NGINX run on the foreground -RUN echo "daemon off;" >> /etc/nginx/nginx.conf -# Copy the modified Nginx conf -COPY nginx-custom.conf /etc/nginx/conf.d/nginx.conf # Copy the base uWSGI ini file to enable default dynamic uwsgi process number COPY uwsgi.ini /etc/uwsgi/ diff --git a/python3.6-alpine3.7/entrypoint.sh b/python3.6-alpine3.7/entrypoint.sh index 523d2f5..8071431 100644 --- a/python3.6-alpine3.7/entrypoint.sh +++ b/python3.6-alpine3.7/entrypoint.sh @@ -1,35 +1,61 @@ #!/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 - # 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 +export PYTHONPATH=$PYTHONPATH:/usr/local/lib/python2.7/site-packages:/usr/lib/python2.7/site-packages + +# Get the maximum upload file size for Nginx, default to 0: unlimited +USE_NGINX_MAX_UPLOAD=${NGINX_MAX_UPLOAD:-0} # 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 +# 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 +NGINX_WORKER_CONNECTIONS=${NGINX_WORKER_CONNECTIONS:-1024} # Get the listen port for Nginx, default to 80 USE_LISTEN_PORT=${LISTEN_PORT:-80} -# Modify Nignx config for listen port -if ! grep -q "listen ${USE_LISTEN_PORT};" /etc/nginx/conf.d/nginx.conf ; then - sed -i -e "/server {/a\ listen ${USE_LISTEN_PORT};" /etc/nginx/conf.d/nginx.conf + +content='user nginx;\n' +# Set the number of worker processes in Nginx +content=$content"worker_processes ${USE_NGINX_WORKER_PROCESSES};\n" +content=$content'error_log /var/log/nginx/error.log warn;\n' +content=$content'pid /var/run/nginx.pid;\n' +content=$content'events {\n' +content=$content" worker_connections ${NGINX_WORKER_CONNECTIONS};\n" +content=$content'}\n' +content=$content'http {\n' +content=$content' include /etc/nginx/mime.types;\n' +content=$content' default_type application/octet-stream;\n' +content=$content' log_format main '"'\$remote_addr - \$remote_user [\$time_local] \"\$request\" '\n" +content=$content' '"'\$status \$body_bytes_sent \"\$http_referer\" '\n" +content=$content' '"'\"\$http_user_agent\" \"\$http_x_forwarded_for\"';\n" +content=$content' access_log /var/log/nginx/access.log main;\n' +content=$content' sendfile on;\n' +content=$content' keepalive_timeout 65;\n' +content=$content' include /etc/nginx/conf.d/*.conf;\n' +content=$content'}\n' +content=$content'daemon off;\n' +# Set the max number of open file descriptors for Nginx workers, if requested +if [ -n "${NGINX_WORKER_OPEN_FILES}" ] ; then + content=$content"worker_rlimit_nofile ${NGINX_WORKER_OPEN_FILES};\n" fi +# Save generated /etc/nginx/nginx.conf +printf "$content" > /etc/nginx/nginx.conf + +content_server='server {\n' +content_server=$content_server" listen ${USE_LISTEN_PORT};\n" +content_server=$content_server' location / {\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'}\n' +# Save generated server /etc/nginx/conf.d/nginx.conf +printf "$content_server" > /etc/nginx/conf.d/nginx.conf + +# Generate Nginx config for maximum upload file size +printf "client_max_body_size $USE_NGINX_MAX_UPLOAD;\n" > /etc/nginx/conf.d/upload.conf + exec "$@" diff --git a/python3.6-alpine3.7/nginx-custom.conf b/python3.6-alpine3.7/nginx-custom.conf deleted file mode 100644 index eca3646..0000000 --- a/python3.6-alpine3.7/nginx-custom.conf +++ /dev/null @@ -1,6 +0,0 @@ -server { - location / { - include uwsgi_params; - uwsgi_pass unix:///tmp/uwsgi.sock; - } -} \ No newline at end of file diff --git a/python3.6-alpine3.7/nginx.conf b/python3.6-alpine3.7/nginx.conf deleted file mode 100644 index 7271761..0000000 --- a/python3.6-alpine3.7/nginx.conf +++ /dev/null @@ -1,31 +0,0 @@ -user nginx; -worker_processes 1; - -error_log /var/log/nginx/error.log warn; -pid /var/run/nginx.pid; - - -events { - worker_connections 1024; -} - - -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; - #tcp_nopush on; - - keepalive_timeout 65; - - #gzip on; - - include /etc/nginx/conf.d/*.conf; -} \ No newline at end of file diff --git a/python3.6-alpine3.8/Dockerfile b/python3.6-alpine3.8/Dockerfile index b60150f..efc9f5b 100644 --- a/python3.6-alpine3.8/Dockerfile +++ b/python3.6-alpine3.8/Dockerfile @@ -139,8 +139,6 @@ RUN GPG_KEYS=B0F4253373F8F6F510D42178520A9993A1C052F8 \ && ln -sf /dev/stdout /var/log/nginx/access.log \ && ln -sf /dev/stderr /var/log/nginx/error.log -COPY nginx.conf /etc/nginx/nginx.conf - # Standard set up Nginx finished EXPOSE 80 @@ -152,10 +150,6 @@ EXPOSE 443 # Install uWSGI RUN apk add --no-cache uwsgi-python3 -# Make NGINX run on the foreground -RUN echo "daemon off;" >> /etc/nginx/nginx.conf -# Copy the modified Nginx conf -COPY nginx-custom.conf /etc/nginx/conf.d/nginx.conf # Copy the base uWSGI ini file to enable default dynamic uwsgi process number COPY uwsgi.ini /etc/uwsgi/ diff --git a/python3.6-alpine3.8/entrypoint.sh b/python3.6-alpine3.8/entrypoint.sh index 523d2f5..8071431 100644 --- a/python3.6-alpine3.8/entrypoint.sh +++ b/python3.6-alpine3.8/entrypoint.sh @@ -1,35 +1,61 @@ #!/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 - # 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 +export PYTHONPATH=$PYTHONPATH:/usr/local/lib/python2.7/site-packages:/usr/lib/python2.7/site-packages + +# Get the maximum upload file size for Nginx, default to 0: unlimited +USE_NGINX_MAX_UPLOAD=${NGINX_MAX_UPLOAD:-0} # 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 +# 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 +NGINX_WORKER_CONNECTIONS=${NGINX_WORKER_CONNECTIONS:-1024} # Get the listen port for Nginx, default to 80 USE_LISTEN_PORT=${LISTEN_PORT:-80} -# Modify Nignx config for listen port -if ! grep -q "listen ${USE_LISTEN_PORT};" /etc/nginx/conf.d/nginx.conf ; then - sed -i -e "/server {/a\ listen ${USE_LISTEN_PORT};" /etc/nginx/conf.d/nginx.conf + +content='user nginx;\n' +# Set the number of worker processes in Nginx +content=$content"worker_processes ${USE_NGINX_WORKER_PROCESSES};\n" +content=$content'error_log /var/log/nginx/error.log warn;\n' +content=$content'pid /var/run/nginx.pid;\n' +content=$content'events {\n' +content=$content" worker_connections ${NGINX_WORKER_CONNECTIONS};\n" +content=$content'}\n' +content=$content'http {\n' +content=$content' include /etc/nginx/mime.types;\n' +content=$content' default_type application/octet-stream;\n' +content=$content' log_format main '"'\$remote_addr - \$remote_user [\$time_local] \"\$request\" '\n" +content=$content' '"'\$status \$body_bytes_sent \"\$http_referer\" '\n" +content=$content' '"'\"\$http_user_agent\" \"\$http_x_forwarded_for\"';\n" +content=$content' access_log /var/log/nginx/access.log main;\n' +content=$content' sendfile on;\n' +content=$content' keepalive_timeout 65;\n' +content=$content' include /etc/nginx/conf.d/*.conf;\n' +content=$content'}\n' +content=$content'daemon off;\n' +# Set the max number of open file descriptors for Nginx workers, if requested +if [ -n "${NGINX_WORKER_OPEN_FILES}" ] ; then + content=$content"worker_rlimit_nofile ${NGINX_WORKER_OPEN_FILES};\n" fi +# Save generated /etc/nginx/nginx.conf +printf "$content" > /etc/nginx/nginx.conf + +content_server='server {\n' +content_server=$content_server" listen ${USE_LISTEN_PORT};\n" +content_server=$content_server' location / {\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'}\n' +# Save generated server /etc/nginx/conf.d/nginx.conf +printf "$content_server" > /etc/nginx/conf.d/nginx.conf + +# Generate Nginx config for maximum upload file size +printf "client_max_body_size $USE_NGINX_MAX_UPLOAD;\n" > /etc/nginx/conf.d/upload.conf + exec "$@" diff --git a/python3.6-alpine3.8/nginx-custom.conf b/python3.6-alpine3.8/nginx-custom.conf deleted file mode 100644 index eca3646..0000000 --- a/python3.6-alpine3.8/nginx-custom.conf +++ /dev/null @@ -1,6 +0,0 @@ -server { - location / { - include uwsgi_params; - uwsgi_pass unix:///tmp/uwsgi.sock; - } -} \ No newline at end of file diff --git a/python3.6-alpine3.8/nginx.conf b/python3.6-alpine3.8/nginx.conf deleted file mode 100644 index 7271761..0000000 --- a/python3.6-alpine3.8/nginx.conf +++ /dev/null @@ -1,31 +0,0 @@ -user nginx; -worker_processes 1; - -error_log /var/log/nginx/error.log warn; -pid /var/run/nginx.pid; - - -events { - worker_connections 1024; -} - - -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; - #tcp_nopush on; - - keepalive_timeout 65; - - #gzip on; - - include /etc/nginx/conf.d/*.conf; -} \ No newline at end of file diff --git a/python3.6/Dockerfile b/python3.6/Dockerfile index 52f1135..71e0840 100644 --- a/python3.6/Dockerfile +++ b/python3.6/Dockerfile @@ -105,12 +105,8 @@ EXPOSE 443 # Install uWSGI RUN pip install uwsgi -# Make NGINX run on the foreground -RUN echo "daemon off;" >> /etc/nginx/nginx.conf # Remove default configuration from Nginx RUN rm /etc/nginx/conf.d/default.conf -# Copy the modified Nginx conf -COPY nginx.conf /etc/nginx/conf.d/ # Copy the base uWSGI ini file to enable default dynamic uwsgi process number COPY uwsgi.ini /etc/uwsgi/ diff --git a/python3.6/entrypoint.sh b/python3.6/entrypoint.sh index fc1ddaf..5306a8a 100644 --- a/python3.6/entrypoint.sh +++ b/python3.6/entrypoint.sh @@ -1,31 +1,57 @@ -#!/bin/bash +#!/usr/bin/env bash 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 [[ -v 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 [[ -v NGINX_WORKER_OPEN_FILES ]] ; then - echo "worker_rlimit_nofile ${NGINX_WORKER_OPEN_FILES};" >> /etc/nginx/nginx.conf -fi +NGINX_WORKER_CONNECTIONS=${NGINX_WORKER_CONNECTIONS:-1024} # Get the listen port for Nginx, default to 80 USE_LISTEN_PORT=${LISTEN_PORT:-80} -# Modify Nignx config for listen port -if ! grep -q "listen ${USE_LISTEN_PORT};" /etc/nginx/conf.d/nginx.conf ; then - sed -i -e "/server {/a\ listen ${USE_LISTEN_PORT};" /etc/nginx/conf.d/nginx.conf + +content='user nginx;\n' +# Set the number of worker processes in Nginx +content=$content"worker_processes ${USE_NGINX_WORKER_PROCESSES};\n" +content=$content'error_log /var/log/nginx/error.log warn;\n' +content=$content'pid /var/run/nginx.pid;\n' +content=$content'events {\n' +content=$content" worker_connections ${NGINX_WORKER_CONNECTIONS};\n" +content=$content'}\n' +content=$content'http {\n' +content=$content' include /etc/nginx/mime.types;\n' +content=$content' default_type application/octet-stream;\n' +content=$content' log_format main '"'\$remote_addr - \$remote_user [\$time_local] \"\$request\" '\n" +content=$content' '"'\$status \$body_bytes_sent \"\$http_referer\" '\n" +content=$content' '"'\"\$http_user_agent\" \"\$http_x_forwarded_for\"';\n" +content=$content' access_log /var/log/nginx/access.log main;\n' +content=$content' sendfile on;\n' +content=$content' keepalive_timeout 65;\n' +content=$content' include /etc/nginx/conf.d/*.conf;\n' +content=$content'}\n' +content=$content'daemon off;\n' +# Set the max number of open file descriptors for Nginx workers, if requested +if [ -n "${NGINX_WORKER_OPEN_FILES}" ] ; then + content=$content"worker_rlimit_nofile ${NGINX_WORKER_OPEN_FILES};\n" fi +# Save generated /etc/nginx/nginx.conf +printf "$content" > /etc/nginx/nginx.conf + +content_server='server {\n' +content_server=$content_server" listen ${USE_LISTEN_PORT};\n" +content_server=$content_server' location / {\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'}\n' +# Save generated server /etc/nginx/conf.d/nginx.conf +printf "$content_server" > /etc/nginx/conf.d/nginx.conf + +# Generate Nginx config for maximum upload file size +printf "client_max_body_size $USE_NGINX_MAX_UPLOAD;\n" > /etc/nginx/conf.d/upload.conf + exec "$@" diff --git a/python3.6/nginx.conf b/python3.6/nginx.conf deleted file mode 100644 index eca3646..0000000 --- a/python3.6/nginx.conf +++ /dev/null @@ -1,6 +0,0 @@ -server { - location / { - include uwsgi_params; - uwsgi_pass unix:///tmp/uwsgi.sock; - } -} \ No newline at end of file diff --git a/python3.7-alpine3.7/Dockerfile b/python3.7-alpine3.7/Dockerfile index bdad754..0b102f2 100644 --- a/python3.7-alpine3.7/Dockerfile +++ b/python3.7-alpine3.7/Dockerfile @@ -139,8 +139,6 @@ RUN GPG_KEYS=B0F4253373F8F6F510D42178520A9993A1C052F8 \ && ln -sf /dev/stdout /var/log/nginx/access.log \ && ln -sf /dev/stderr /var/log/nginx/error.log -COPY nginx.conf /etc/nginx/nginx.conf - # Standard set up Nginx finished EXPOSE 80 @@ -152,10 +150,6 @@ EXPOSE 443 # Install uWSGI RUN apk add --no-cache uwsgi-python3 -# Make NGINX run on the foreground -RUN echo "daemon off;" >> /etc/nginx/nginx.conf -# Copy the modified Nginx conf -COPY nginx-custom.conf /etc/nginx/conf.d/nginx.conf # Copy the base uWSGI ini file to enable default dynamic uwsgi process number COPY uwsgi.ini /etc/uwsgi/ diff --git a/python3.7-alpine3.7/entrypoint.sh b/python3.7-alpine3.7/entrypoint.sh index 523d2f5..8071431 100644 --- a/python3.7-alpine3.7/entrypoint.sh +++ b/python3.7-alpine3.7/entrypoint.sh @@ -1,35 +1,61 @@ #!/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 - # 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 +export PYTHONPATH=$PYTHONPATH:/usr/local/lib/python2.7/site-packages:/usr/lib/python2.7/site-packages + +# Get the maximum upload file size for Nginx, default to 0: unlimited +USE_NGINX_MAX_UPLOAD=${NGINX_MAX_UPLOAD:-0} # 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 +# 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 +NGINX_WORKER_CONNECTIONS=${NGINX_WORKER_CONNECTIONS:-1024} # Get the listen port for Nginx, default to 80 USE_LISTEN_PORT=${LISTEN_PORT:-80} -# Modify Nignx config for listen port -if ! grep -q "listen ${USE_LISTEN_PORT};" /etc/nginx/conf.d/nginx.conf ; then - sed -i -e "/server {/a\ listen ${USE_LISTEN_PORT};" /etc/nginx/conf.d/nginx.conf + +content='user nginx;\n' +# Set the number of worker processes in Nginx +content=$content"worker_processes ${USE_NGINX_WORKER_PROCESSES};\n" +content=$content'error_log /var/log/nginx/error.log warn;\n' +content=$content'pid /var/run/nginx.pid;\n' +content=$content'events {\n' +content=$content" worker_connections ${NGINX_WORKER_CONNECTIONS};\n" +content=$content'}\n' +content=$content'http {\n' +content=$content' include /etc/nginx/mime.types;\n' +content=$content' default_type application/octet-stream;\n' +content=$content' log_format main '"'\$remote_addr - \$remote_user [\$time_local] \"\$request\" '\n" +content=$content' '"'\$status \$body_bytes_sent \"\$http_referer\" '\n" +content=$content' '"'\"\$http_user_agent\" \"\$http_x_forwarded_for\"';\n" +content=$content' access_log /var/log/nginx/access.log main;\n' +content=$content' sendfile on;\n' +content=$content' keepalive_timeout 65;\n' +content=$content' include /etc/nginx/conf.d/*.conf;\n' +content=$content'}\n' +content=$content'daemon off;\n' +# Set the max number of open file descriptors for Nginx workers, if requested +if [ -n "${NGINX_WORKER_OPEN_FILES}" ] ; then + content=$content"worker_rlimit_nofile ${NGINX_WORKER_OPEN_FILES};\n" fi +# Save generated /etc/nginx/nginx.conf +printf "$content" > /etc/nginx/nginx.conf + +content_server='server {\n' +content_server=$content_server" listen ${USE_LISTEN_PORT};\n" +content_server=$content_server' location / {\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'}\n' +# Save generated server /etc/nginx/conf.d/nginx.conf +printf "$content_server" > /etc/nginx/conf.d/nginx.conf + +# Generate Nginx config for maximum upload file size +printf "client_max_body_size $USE_NGINX_MAX_UPLOAD;\n" > /etc/nginx/conf.d/upload.conf + exec "$@" diff --git a/python3.7-alpine3.7/nginx-custom.conf b/python3.7-alpine3.7/nginx-custom.conf deleted file mode 100644 index eca3646..0000000 --- a/python3.7-alpine3.7/nginx-custom.conf +++ /dev/null @@ -1,6 +0,0 @@ -server { - location / { - include uwsgi_params; - uwsgi_pass unix:///tmp/uwsgi.sock; - } -} \ No newline at end of file diff --git a/python3.7-alpine3.7/nginx.conf b/python3.7-alpine3.7/nginx.conf deleted file mode 100644 index 7271761..0000000 --- a/python3.7-alpine3.7/nginx.conf +++ /dev/null @@ -1,31 +0,0 @@ -user nginx; -worker_processes 1; - -error_log /var/log/nginx/error.log warn; -pid /var/run/nginx.pid; - - -events { - worker_connections 1024; -} - - -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; - #tcp_nopush on; - - keepalive_timeout 65; - - #gzip on; - - include /etc/nginx/conf.d/*.conf; -} \ No newline at end of file diff --git a/python3.7-alpine3.8/Dockerfile b/python3.7-alpine3.8/Dockerfile index 65e9bbf..3a3f3ca 100644 --- a/python3.7-alpine3.8/Dockerfile +++ b/python3.7-alpine3.8/Dockerfile @@ -139,8 +139,6 @@ RUN GPG_KEYS=B0F4253373F8F6F510D42178520A9993A1C052F8 \ && ln -sf /dev/stdout /var/log/nginx/access.log \ && ln -sf /dev/stderr /var/log/nginx/error.log -COPY nginx.conf /etc/nginx/nginx.conf - # Standard set up Nginx finished EXPOSE 80 @@ -152,10 +150,6 @@ EXPOSE 443 # Install uWSGI RUN apk add --no-cache uwsgi-python3 -# Make NGINX run on the foreground -RUN echo "daemon off;" >> /etc/nginx/nginx.conf -# Copy the modified Nginx conf -COPY nginx-custom.conf /etc/nginx/conf.d/nginx.conf # Copy the base uWSGI ini file to enable default dynamic uwsgi process number COPY uwsgi.ini /etc/uwsgi/ diff --git a/python3.7-alpine3.8/entrypoint.sh b/python3.7-alpine3.8/entrypoint.sh index 523d2f5..8071431 100644 --- a/python3.7-alpine3.8/entrypoint.sh +++ b/python3.7-alpine3.8/entrypoint.sh @@ -1,35 +1,61 @@ #!/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 - # 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 +export PYTHONPATH=$PYTHONPATH:/usr/local/lib/python2.7/site-packages:/usr/lib/python2.7/site-packages + +# Get the maximum upload file size for Nginx, default to 0: unlimited +USE_NGINX_MAX_UPLOAD=${NGINX_MAX_UPLOAD:-0} # 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 +# 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 +NGINX_WORKER_CONNECTIONS=${NGINX_WORKER_CONNECTIONS:-1024} # Get the listen port for Nginx, default to 80 USE_LISTEN_PORT=${LISTEN_PORT:-80} -# Modify Nignx config for listen port -if ! grep -q "listen ${USE_LISTEN_PORT};" /etc/nginx/conf.d/nginx.conf ; then - sed -i -e "/server {/a\ listen ${USE_LISTEN_PORT};" /etc/nginx/conf.d/nginx.conf + +content='user nginx;\n' +# Set the number of worker processes in Nginx +content=$content"worker_processes ${USE_NGINX_WORKER_PROCESSES};\n" +content=$content'error_log /var/log/nginx/error.log warn;\n' +content=$content'pid /var/run/nginx.pid;\n' +content=$content'events {\n' +content=$content" worker_connections ${NGINX_WORKER_CONNECTIONS};\n" +content=$content'}\n' +content=$content'http {\n' +content=$content' include /etc/nginx/mime.types;\n' +content=$content' default_type application/octet-stream;\n' +content=$content' log_format main '"'\$remote_addr - \$remote_user [\$time_local] \"\$request\" '\n" +content=$content' '"'\$status \$body_bytes_sent \"\$http_referer\" '\n" +content=$content' '"'\"\$http_user_agent\" \"\$http_x_forwarded_for\"';\n" +content=$content' access_log /var/log/nginx/access.log main;\n' +content=$content' sendfile on;\n' +content=$content' keepalive_timeout 65;\n' +content=$content' include /etc/nginx/conf.d/*.conf;\n' +content=$content'}\n' +content=$content'daemon off;\n' +# Set the max number of open file descriptors for Nginx workers, if requested +if [ -n "${NGINX_WORKER_OPEN_FILES}" ] ; then + content=$content"worker_rlimit_nofile ${NGINX_WORKER_OPEN_FILES};\n" fi +# Save generated /etc/nginx/nginx.conf +printf "$content" > /etc/nginx/nginx.conf + +content_server='server {\n' +content_server=$content_server" listen ${USE_LISTEN_PORT};\n" +content_server=$content_server' location / {\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'}\n' +# Save generated server /etc/nginx/conf.d/nginx.conf +printf "$content_server" > /etc/nginx/conf.d/nginx.conf + +# Generate Nginx config for maximum upload file size +printf "client_max_body_size $USE_NGINX_MAX_UPLOAD;\n" > /etc/nginx/conf.d/upload.conf + exec "$@" diff --git a/python3.7-alpine3.8/nginx-custom.conf b/python3.7-alpine3.8/nginx-custom.conf deleted file mode 100644 index eca3646..0000000 --- a/python3.7-alpine3.8/nginx-custom.conf +++ /dev/null @@ -1,6 +0,0 @@ -server { - location / { - include uwsgi_params; - uwsgi_pass unix:///tmp/uwsgi.sock; - } -} \ No newline at end of file diff --git a/python3.7-alpine3.8/nginx.conf b/python3.7-alpine3.8/nginx.conf deleted file mode 100644 index 7271761..0000000 --- a/python3.7-alpine3.8/nginx.conf +++ /dev/null @@ -1,31 +0,0 @@ -user nginx; -worker_processes 1; - -error_log /var/log/nginx/error.log warn; -pid /var/run/nginx.pid; - - -events { - worker_connections 1024; -} - - -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; - #tcp_nopush on; - - keepalive_timeout 65; - - #gzip on; - - include /etc/nginx/conf.d/*.conf; -} \ No newline at end of file diff --git a/python3.7/Dockerfile b/python3.7/Dockerfile index 94a3be4..b286959 100644 --- a/python3.7/Dockerfile +++ b/python3.7/Dockerfile @@ -105,12 +105,8 @@ EXPOSE 443 # Install uWSGI RUN pip install uwsgi -# Make NGINX run on the foreground -RUN echo "daemon off;" >> /etc/nginx/nginx.conf # Remove default configuration from Nginx RUN rm /etc/nginx/conf.d/default.conf -# Copy the modified Nginx conf -COPY nginx.conf /etc/nginx/conf.d/ # Copy the base uWSGI ini file to enable default dynamic uwsgi process number COPY uwsgi.ini /etc/uwsgi/ diff --git a/python3.7/entrypoint.sh b/python3.7/entrypoint.sh index fc1ddaf..5306a8a 100644 --- a/python3.7/entrypoint.sh +++ b/python3.7/entrypoint.sh @@ -1,31 +1,57 @@ -#!/bin/bash +#!/usr/bin/env bash 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 [[ -v 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 [[ -v NGINX_WORKER_OPEN_FILES ]] ; then - echo "worker_rlimit_nofile ${NGINX_WORKER_OPEN_FILES};" >> /etc/nginx/nginx.conf -fi +NGINX_WORKER_CONNECTIONS=${NGINX_WORKER_CONNECTIONS:-1024} # Get the listen port for Nginx, default to 80 USE_LISTEN_PORT=${LISTEN_PORT:-80} -# Modify Nignx config for listen port -if ! grep -q "listen ${USE_LISTEN_PORT};" /etc/nginx/conf.d/nginx.conf ; then - sed -i -e "/server {/a\ listen ${USE_LISTEN_PORT};" /etc/nginx/conf.d/nginx.conf + +content='user nginx;\n' +# Set the number of worker processes in Nginx +content=$content"worker_processes ${USE_NGINX_WORKER_PROCESSES};\n" +content=$content'error_log /var/log/nginx/error.log warn;\n' +content=$content'pid /var/run/nginx.pid;\n' +content=$content'events {\n' +content=$content" worker_connections ${NGINX_WORKER_CONNECTIONS};\n" +content=$content'}\n' +content=$content'http {\n' +content=$content' include /etc/nginx/mime.types;\n' +content=$content' default_type application/octet-stream;\n' +content=$content' log_format main '"'\$remote_addr - \$remote_user [\$time_local] \"\$request\" '\n" +content=$content' '"'\$status \$body_bytes_sent \"\$http_referer\" '\n" +content=$content' '"'\"\$http_user_agent\" \"\$http_x_forwarded_for\"';\n" +content=$content' access_log /var/log/nginx/access.log main;\n' +content=$content' sendfile on;\n' +content=$content' keepalive_timeout 65;\n' +content=$content' include /etc/nginx/conf.d/*.conf;\n' +content=$content'}\n' +content=$content'daemon off;\n' +# Set the max number of open file descriptors for Nginx workers, if requested +if [ -n "${NGINX_WORKER_OPEN_FILES}" ] ; then + content=$content"worker_rlimit_nofile ${NGINX_WORKER_OPEN_FILES};\n" fi +# Save generated /etc/nginx/nginx.conf +printf "$content" > /etc/nginx/nginx.conf + +content_server='server {\n' +content_server=$content_server" listen ${USE_LISTEN_PORT};\n" +content_server=$content_server' location / {\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'}\n' +# Save generated server /etc/nginx/conf.d/nginx.conf +printf "$content_server" > /etc/nginx/conf.d/nginx.conf + +# Generate Nginx config for maximum upload file size +printf "client_max_body_size $USE_NGINX_MAX_UPLOAD;\n" > /etc/nginx/conf.d/upload.conf + exec "$@" diff --git a/python3.7/nginx.conf b/python3.7/nginx.conf deleted file mode 100644 index eca3646..0000000 --- a/python3.7/nginx.conf +++ /dev/null @@ -1,6 +0,0 @@ -server { - location / { - include uwsgi_params; - uwsgi_pass unix:///tmp/uwsgi.sock; - } -} \ No newline at end of file diff --git a/tests/test_01_main/test_defaults.py b/tests/test_01_main/test_defaults.py index d051193..f37eaf1 100644 --- a/tests/test_01_main/test_defaults.py +++ b/tests/test_01_main/test_defaults.py @@ -5,11 +5,53 @@ import requests from requests import Response -from ..utils import CONTAINER_NAME, get_logs, get_nginx_config, stop_previous_container +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;" in nginx_config + assert "worker_processes 1;" in nginx_config + assert "listen 80;" in nginx_config + assert "worker_connections 1024;" 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 + 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 "wsgi-file = /app/main.py" in logs + assert "processes = 16" in logs + assert "cheaper = 2" 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: Response = requests.get("http://127.0.0.1:8000") + assert response.status_code == 200 + assert response.text == response_text + + @pytest.mark.parametrize( "image,response_text", [ @@ -56,44 +98,16 @@ ], ) def test_defaults(image, response_text): - stop_previous_container(client) + remove_previous_container(client) container = client.containers.run( image, name=CONTAINER_NAME, ports={"80": "8000"}, detach=True ) - nginx_config = get_nginx_config(container) - assert "client_max_body_size 0;" in nginx_config - assert "worker_processes 1;" in nginx_config - assert "listen 80;" in nginx_config - assert "worker_connections 1024;" 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 time.sleep(3) - 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 "wsgi-file = /app/main.py" in logs - assert "processes = 16" in logs - assert "cheaper = 2" 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: Response = requests.get("http://127.0.0.1:8000") - assert response.status_code == 200 - assert response.text == response_text + 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() diff --git a/tests/test_01_main/test_env_vars_1.py b/tests/test_01_main/test_env_vars_1.py index 90d827d..ae0e454 100644 --- a/tests/test_01_main/test_env_vars_1.py +++ b/tests/test_01_main/test_env_vars_1.py @@ -4,11 +4,55 @@ import pytest import requests -from ..utils import CONTAINER_NAME, get_logs, get_nginx_config, stop_previous_container +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 1m;" in nginx_config + assert "worker_processes 2;" in nginx_config + assert "listen 80;" in nginx_config + assert "worker_connections 2048;" in nginx_config + assert "worker_rlimit_nofile 2048;" in nginx_config + assert "daemon off;" in nginx_config + assert "listen 80;" in nginx_config + assert "include uwsgi_params;" in nginx_config + assert "uwsgi_pass unix:///tmp/uwsgi.sock;" 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 "wsgi-file = /app/main.py" in logs + assert "processes = 8" in logs + assert "cheaper = 3" 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" in logs + assert "spawned uWSGI worker 4" 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:8000") + assert response.status_code == 200 + assert response.text == response_text + + @pytest.mark.parametrize( "image,response_text", [ @@ -55,7 +99,7 @@ ], ) def test_env_vars_1(image, response_text): - stop_previous_container(client) + remove_previous_container(client) container = client.containers.run( image, name=CONTAINER_NAME, @@ -70,42 +114,12 @@ def test_env_vars_1(image, response_text): ports={"80": "8000"}, detach=True, ) - nginx_config = get_nginx_config(container) - assert "client_max_body_size 1m;" in nginx_config - assert "worker_processes 2;" in nginx_config - assert "listen 80;" in nginx_config - assert "worker_connections 2048;" in nginx_config - assert "worker_rlimit_nofile 2048;" in nginx_config - assert "daemon off;" in nginx_config - assert "listen 80;" in nginx_config - assert "include uwsgi_params;" in nginx_config - assert "uwsgi_pass unix:///tmp/uwsgi.sock;" in nginx_config time.sleep(3) - 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 "wsgi-file = /app/main.py" in logs - assert "processes = 8" in logs - assert "cheaper = 3" 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" in logs - assert "spawned uWSGI worker 4" 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: Response = requests.get("http://127.0.0.1:8000") - assert response.status_code == 200 - assert response.text == response_text + 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() diff --git a/tests/test_02_app/test_app_and_env_vars.py b/tests/test_02_app/test_app_and_env_vars.py index 2e8a797..de5598e 100644 --- a/tests/test_02_app/test_app_and_env_vars.py +++ b/tests/test_02_app/test_app_and_env_vars.py @@ -5,11 +5,53 @@ import pytest import requests -from ..utils import CONTAINER_NAME, get_logs, get_nginx_config, stop_previous_container +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;" in nginx_config + assert "worker_processes 1;" in nginx_config + assert "listen 8080;" in nginx_config + assert "worker_connections 1024;" 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 + logs = get_logs(container) + assert "getting INI configuration from /application/custom_app/uwsgi.ini" in logs + assert "getting INI configuration from /etc/uwsgi/uwsgi.ini" in logs + assert "ini = /application/custom_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 "wsgi-file = /application/custom_app/main.py" in logs + assert "processes = 16" in logs + assert "cheaper = 2" 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:8000") + assert response.status_code == 200 + assert response.text == response_text + + @pytest.mark.parametrize( "dockerfile,response_text", [ @@ -60,7 +102,7 @@ ], ) def test_env_vars_1(dockerfile, response_text): - stop_previous_container(client) + remove_previous_container(client) tag = "uwsgi-nginx-testimage" test_path: PurePath = Path(__file__) path = test_path.parent / "custom_app" @@ -75,40 +117,12 @@ def test_env_vars_1(dockerfile, response_text): ports={"8080": "8000"}, detach=True, ) - nginx_config = get_nginx_config(container) - assert "client_max_body_size 0;" in nginx_config - assert "worker_processes 1;" in nginx_config - assert "listen 8080;" in nginx_config - assert "worker_connections 1024;" 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 time.sleep(3) - logs = get_logs(container) - assert "getting INI configuration from /application/custom_app/uwsgi.ini" in logs - assert "getting INI configuration from /etc/uwsgi/uwsgi.ini" in logs - assert "ini = /application/custom_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 "wsgi-file = /application/custom_app/main.py" in logs - assert "processes = 16" in logs - assert "cheaper = 2" 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: Response = requests.get("http://127.0.0.1:8000") - assert response.status_code == 200 - assert response.text == response_text + 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() diff --git a/tests/test_02_app/test_simple_app.py b/tests/test_02_app/test_simple_app.py index ff2d87d..cd4c69d 100644 --- a/tests/test_02_app/test_simple_app.py +++ b/tests/test_02_app/test_simple_app.py @@ -5,11 +5,53 @@ import pytest import requests -from ..utils import CONTAINER_NAME, get_logs, get_nginx_config, stop_previous_container +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;" in nginx_config + assert "worker_processes 1;" in nginx_config + assert "listen 80;" in nginx_config + assert "worker_connections 1024;" 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 + 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 "wsgi-file = /app/main.py" in logs + assert "processes = 16" in logs + assert "cheaper = 2" 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:8000") + assert response.status_code == 200 + assert response.text == response_text + + @pytest.mark.parametrize( "dockerfile,response_text", [ @@ -60,51 +102,20 @@ ], ) def test_env_vars_1(dockerfile, response_text): - stop_previous_container(client) + remove_previous_container(client) tag = "uwsgi-nginx-testimage" test_path: PurePath = Path(__file__) path = test_path.parent / "simple_app" client.images.build(path=str(path), dockerfile=dockerfile, tag=tag) container = client.containers.run( - tag, - name=CONTAINER_NAME, - ports={"80": "8000"}, - detach=True, + tag, name=CONTAINER_NAME, ports={"80": "8000"}, detach=True ) - nginx_config = get_nginx_config(container) - assert "client_max_body_size 0;" in nginx_config - assert "worker_processes 1;" in nginx_config - assert "listen 80;" in nginx_config - assert "worker_connections 1024;" 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 time.sleep(3) - 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 "wsgi-file = /app/main.py" in logs - assert "processes = 16" in logs - assert "cheaper = 2" 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: Response = requests.get("http://127.0.0.1:8000") - assert response.status_code == 200 - assert response.text == response_text + 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() diff --git a/tests/utils.py b/tests/utils.py index d94dc89..08d9bb2 100644 --- a/tests/utils.py +++ b/tests/utils.py @@ -13,7 +13,7 @@ def get_nginx_config(container): return result.output.decode() -def stop_previous_container(client): +def remove_previous_container(client): try: previous = client.containers.get(CONTAINER_NAME) previous.stop()