entrypoint.sh 3.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. #!/usr/bin/env sh
  2. set -e
  3. # Get the maximum upload file size for Nginx, default to 0: unlimited
  4. USE_NGINX_MAX_UPLOAD=${NGINX_MAX_UPLOAD:-0}
  5. # Get the number of workers for Nginx, default to 1
  6. USE_NGINX_WORKER_PROCESSES=${NGINX_WORKER_PROCESSES:-1}
  7. # Set the max number of connections per worker for Nginx, if requested
  8. # Cannot exceed worker_rlimit_nofile, see NGINX_WORKER_OPEN_FILES below
  9. NGINX_WORKER_CONNECTIONS=${NGINX_WORKER_CONNECTIONS:-1024}
  10. # Get the listen port for Nginx, default to 80
  11. USE_LISTEN_PORT=${LISTEN_PORT:-80}
  12. if [ -f /app/nginx.conf ]; then
  13. cp /app/nginx.conf /etc/nginx/nginx.conf
  14. else
  15. content='user nginx;\n'
  16. # Set the number of worker processes in Nginx
  17. content=$content"worker_processes ${USE_NGINX_WORKER_PROCESSES};\n"
  18. content=$content'error_log /var/log/nginx/error.log warn;\n'
  19. content=$content'pid /var/run/nginx.pid;\n'
  20. content=$content'events {\n'
  21. content=$content" worker_connections ${NGINX_WORKER_CONNECTIONS};\n"
  22. content=$content'}\n'
  23. content=$content'http {\n'
  24. content=$content' include /etc/nginx/mime.types;\n'
  25. content=$content' default_type application/octet-stream;\n'
  26. content=$content' log_format main '"'\$remote_addr - \$remote_user [\$time_local] \"\$request\" '\n"
  27. content=$content' '"'\$status \$body_bytes_sent \"\$http_referer\" '\n"
  28. content=$content' '"'\"\$http_user_agent\" \"\$http_x_forwarded_for\"';\n"
  29. content=$content' access_log /var/log/nginx/access.log main;\n'
  30. content=$content' sendfile on;\n'
  31. content=$content' keepalive_timeout 65;\n'
  32. content=$content' include /etc/nginx/conf.d/*.conf;\n'
  33. content=$content'}\n'
  34. content=$content'daemon off;\n'
  35. # Set the max number of open file descriptors for Nginx workers, if requested
  36. if [ -n "${NGINX_WORKER_OPEN_FILES}" ] ; then
  37. content=$content"worker_rlimit_nofile ${NGINX_WORKER_OPEN_FILES};\n"
  38. fi
  39. # Save generated /etc/nginx/nginx.conf
  40. printf "$content" > /etc/nginx/nginx.conf
  41. content_server='server {\n'
  42. content_server=$content_server" listen ${USE_LISTEN_PORT};\n"
  43. content_server=$content_server' location / {\n'
  44. content_server=$content_server' include uwsgi_params;\n'
  45. content_server=$content_server' uwsgi_pass unix:///tmp/uwsgi.sock;\n'
  46. content_server=$content_server' }\n'
  47. content_server=$content_server'}\n'
  48. # Save generated server /etc/nginx/conf.d/nginx.conf
  49. printf "$content_server" > /etc/nginx/conf.d/nginx.conf
  50. # Generate Nginx config for maximum upload file size
  51. printf "client_max_body_size $USE_NGINX_MAX_UPLOAD;\n" > /etc/nginx/conf.d/upload.conf
  52. # Remove default Nginx config from Alpine
  53. printf "" > /etc/nginx/conf.d/default.conf
  54. fi
  55. # For Alpine:
  56. # Explicitly add installed Python packages and uWSGI Python packages to PYTHONPATH
  57. # Otherwise uWSGI can't import Flask
  58. if [ -n "$ALPINEPYTHON" ] ; then
  59. export PYTHONPATH=$PYTHONPATH:/usr/local/lib/$ALPINEPYTHON/site-packages:/usr/lib/$ALPINEPYTHON/site-packages
  60. fi
  61. exec "$@"