From 84f2fb5396469f5c9532806a17da70d682fd7a47 Mon Sep 17 00:00:00 2001
From: Kenneth Reitz <me@kennethreitz.org>
Date: Fri, 5 May 2017 14:28:00 -0400
Subject: [PATCH] update python.gunicorn.sh to WEB_CONCURRENCY.sh (#373)

* update python.gunicorn.sh to WEB_CONCURRENCY.sh

* don't remove WEB_CONCURRENCY for prefixed 0s

* split gunicorn functionality into its own file

* cleanup comments

* fix var ordering

* add retry to curl

* use proper url for buildpack stdlib
---
 bin/compile               |  3 +++
 bin/utils                 |  2 +-
 vendor/WEB_CONCURRENCY.sh | 29 +++++++++++++++++++++++++++++
 vendor/python.gunicorn.sh | 36 ------------------------------------
 4 files changed, 33 insertions(+), 37 deletions(-)
 create mode 100755 vendor/WEB_CONCURRENCY.sh

diff --git a/bin/compile b/bin/compile
index 89e30019..e499dbd7 100755
--- a/bin/compile
+++ b/bin/compile
@@ -68,6 +68,7 @@ mkdir -p /app/.heroku
 PROFILE_PATH="$BUILD_DIR/.profile.d/python.sh"
 EXPORT_PATH="$BIN_DIR/../export"
 GUNICORN_PROFILE_PATH="$BUILD_DIR/.profile.d/python.gunicorn.sh"
+WEB_CONCURRENCY_PROFILE_PATH="$BUILD_DIR/.profile.d/WEB_CONCURRENCY.sh"
 
 # We'll need to send these statics to other scripts we `source`.
 export BUILD_DIR CACHE_DIR BIN_DIR PROFILE_PATH EXPORT_PATH
@@ -211,8 +212,10 @@ set-default-env PYTHONHASHSEED random
 set-default-env PYTHONPATH /app/
 
 # Install sane-default script for $WEB_CONCURRENCY and $FORWARDED_ALLOW_IPS.
+cp $ROOT_DIR/vendor/WEB_CONCURRENCY.sh $WEB_CONCURRENCY_PROFILE_PATH
 cp $ROOT_DIR/vendor/python.gunicorn.sh $GUNICORN_PROFILE_PATH
 
+
 # Experimental post_compile hook.
 source $BIN_DIR/steps/hooks/post_compile
 
diff --git a/bin/utils b/bin/utils
index 6d16aac6..dc2a69d7 100755
--- a/bin/utils
+++ b/bin/utils
@@ -3,7 +3,7 @@ shopt -s extglob
 
 # The standard library.
 if [[ ! -f  /tmp/stdlib.sh ]]; then
-  curl -s https://raw.githubusercontent.com/heroku/buildpack-stdlib/v2/stdlib.sh > /tmp/stdlib.sh
+  curl --retry 3 -s https://lang-common.s3.amazonaws.com/buildpack-stdlib/v2/stdlib.sh > /tmp/stdlib.sh
 fi
 source /tmp/stdlib.sh
 
diff --git a/vendor/WEB_CONCURRENCY.sh b/vendor/WEB_CONCURRENCY.sh
new file mode 100755
index 00000000..69a562a9
--- /dev/null
+++ b/vendor/WEB_CONCURRENCY.sh
@@ -0,0 +1,29 @@
+case $(ulimit -u) in
+
+# Automatic configuration for Gunicorn's Workers setting.
+
+# Standard-1X (+Free, +Hobby) Dyno
+256)
+  export DYNO_RAM=512
+  export WEB_CONCURRENCY=${WEB_CONCURRENCY:-02}
+  ;;
+
+# Standard-2X Dyno
+512)
+  export DYNO_RAM=1024
+  export WEB_CONCURRENCY=${WEB_CONCURRENCY:-04}
+  ;;
+
+# Performance-M Dyno
+16384)
+  export DYNO_RAM=2560
+  export WEB_CONCURRENCY=${WEB_CONCURRENCY:-08}
+  ;;
+
+# Performance-L Dyno
+32768)
+  export DYNO_RAM=6656
+  export WEB_CONCURRENCY=${WEB_CONCURRENCY:-011}
+  ;;
+
+esac
\ No newline at end of file
diff --git a/vendor/python.gunicorn.sh b/vendor/python.gunicorn.sh
index 9a1c395f..164ca075 100755
--- a/vendor/python.gunicorn.sh
+++ b/vendor/python.gunicorn.sh
@@ -1,38 +1,2 @@
-if [[ "${WEB_CONCURRENCY:-}" == 0* ]]; then
-  # another buildpack set a default value, with leading zero
-  unset WEB_CONCURRENCY
-fi
-
-case $(ulimit -u) in
-
-# Automatic configuration for Gunicorn's Workers setting.
-# Leading zero padding so a subsequent buildpack can figure out that we set a value, and not the user
-
-# Standard-1X (+Free, +Hobby) Dyno
-256)
-  export DYNO_RAM=512
-  export WEB_CONCURRENCY=${WEB_CONCURRENCY:-02}
-  ;;
-
-# Standard-2X Dyno
-512)
-  export DYNO_RAM=1024
-  export WEB_CONCURRENCY=${WEB_CONCURRENCY:-04}
-  ;;
-
-# Performance-M Dyno
-16384)
-  export DYNO_RAM=2560
-  export WEB_CONCURRENCY=${WEB_CONCURRENCY:-08}
-  ;;
-
-# Performance-L Dyno
-32768)
-  export DYNO_RAM=6656
-  export WEB_CONCURRENCY=${WEB_CONCURRENCY:-011}
-  ;;
-
-esac
-
 # Automatic configuration for Gunicorn's ForwardedAllowIPS setting.
 export FORWARDED_ALLOW_IPS='*'
-- 
GitLab