diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index ea31efc..6cff70c 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -1,21 +1,15 @@ ## Compiling new versions of pgbouncer and stunnel using Docker -Install [docker](https://www.docker.io/). For OSX, I recommend using -[dvm](http://fnichol.github.io/dvm/) to get virtualbox, vagrant and boot2docker -set up correctly. +Install [docker](https://www.docker.com/). Use the Get Started button at the +top of the page, which autodetects your OS and presents the appropriate +instructions. Build: ``` $ cd support -$ docker build -t your-username/pgbouncer-builder . -$ docker run -i -v /home/docker/cache:/var/cache \ - -e PGBOUNCER_VERSION= \ - -e STUNNEL_VERSION= \ - -e AWS_ACCESS_KEY_ID= \ - -e AWS_SECRET_ACCESS_KEY= \ - -e S3_BUCKET="gregburek-buildpack-pgbouncer" \ - your-username/pgbouncer-builder +$ docker-compose build +$ docker-compose up ``` ## Publishing buildpack updates @@ -25,5 +19,5 @@ heroku plugins:install https://github.com/heroku/heroku-buildpacks cd heroku-buildpack-pgbouncer git checkout master -heroku buildpacks:publish gregburek/pgbouncer +heroku buildpacks:publish heroku/pgbouncer ``` diff --git a/Changelog.md b/Changelog.md index 7e739f4..4e22948 100644 --- a/Changelog.md +++ b/Changelog.md @@ -1,3 +1,14 @@ +## v0.3.4 (January 2, 2015) + +* Updates binary versions to pgbouncer 1.7 and stunnel 5.28 +* Uses `docker-compose up` for building binaries +* Vendors binaries directly into this repo instead of pulling from s3 +* Removes cedar-10 version switch as that stack is EOL +* Adds README warning of excessive logging if non-persistent database + connections are used +* Options at the end of connection url are now kept on purpose, but are still + discouraged + ## v0.3.3 (December 18, 2014) * Improves SIGTERM signal handling in wrapper script (thanks michaeldiscala) diff --git a/README.md b/README.md index 171ada6..3c970e8 100644 --- a/README.md +++ b/README.md @@ -59,21 +59,21 @@ Example usage: $ ls -a Gemfile Gemfile.lock Procfile config/ config.ru - + $ heroku buildpacks:add https://github.com/heroku/heroku-buildpack-pgbouncer Buildpack added. Next release on pgbouncer-test-app will use https://github.com/heroku/heroku-buildpack-pgbouncer. Run `git push heroku master` to create a new release using this buildpack. - + $ heroku buildpacks:add https://github.com/heroku/heroku-buildpack-ruby Buildpack added. Next release on pgbouncer-test-app will use: 1. https://github.com/heroku/heroku-buildpack-pgbouncer 2. https://github.com/heroku/heroku-buildpack-ruby Run `git push heroku master` to create a new release using these buildpacks. - + $ cat Procfile web: bin/start-pgbouncer-stunnel bundle exec unicorn -p $PORT -c ./config/unicorn.rb -E $RACK_ENV worker: bundle exec rake worker - + $ git push heroku master ... -----> Multipack app detected @@ -137,8 +137,8 @@ and [stunnel](http://linux.die.net/man/8/stunnel) configurations to see what set - `PGBOUNCER_SERVER_IDLE_TIMEOUT` Default is 600.0 seconds - `PGBOUNCER_URLS` should contain all config variables that will be overridden to connect to pgbouncer. For example, set this to `AMAZON_RDS_URL` to send RDS connections through pgbouncer. The default is `DATABASE_URL`. - `PGBOUNCER_CONNECTION_RETRY` Default is no -- `PGBOUNCER_LOG_CONNECTIONS` Default is 1 -- `PGBOUNCER_LOG_DISCONNECTIONS` Default is 1 +- `PGBOUNCER_LOG_CONNECTIONS` Default is 1. If your app does not use persistent database connections, this may be noisy and should be set to 0. +- `PGBOUNCER_LOG_DISCONNECTIONS` Default is 1. If your app does not use persistent database connections, this may be noisy and should be set to 0. - `PGBOUNCER_LOG_POOLER_ERRORS` Default is 1 - `PGBOUNCER_STATS_PERIOD` Default is 60 - `PGBOUNCER_SERVER_RESET_QUERY` Default is empty when pool mode is transaction, and "DISCARD ALL;" when session. diff --git a/bin/compile b/bin/compile index 464ea31..b3ba461 100755 --- a/bin/compile +++ b/bin/compile @@ -11,13 +11,8 @@ set -e unset GIT_DIR # config -PGBOUNCER_VERSION="1.5.4-heroku" -if [ "$STACK" == "cedar-14" ]; then - STUNNEL_VERSION="5.08" -else - STUNNEL_VERSION="5.02" -fi -S3_BUCKET="gregburek-buildpack-pgbouncer" +PGBOUNCER_VERSION="1.7-heroku" +STUNNEL_VERSION="5.28" # parse and derive params BUILD_DIR=$1 @@ -38,20 +33,8 @@ function indent() { esac } -function package_download() { - engine="$1" - version="$2" - location="$3" - stack="$4" - - mkdir -p $location - package="https://${S3_BUCKET}.s3.amazonaws.com/$stack/$engine-$version.tgz" - curl $package -s -o - | tar xzf - -C $location -} - echo "Using pgbouncer version: ${PGBOUNCER_VERSION}" | indent echo "Using stunnel version: ${STUNNEL_VERSION}" | indent -echo "Using stack version: ${STACK}" | indent # vendor directories VENDORED_PGBOUNCER="vendor/pgbouncer" @@ -61,13 +44,13 @@ VENDORED_STUNNEL="vendor/stunnel" PATH="$BUILD_DIR/$VENDORED_PGBOUNCER/bin:$PATH" echo "-----> Fetching and vendoring pgbouncer into slug" mkdir -p "$BUILD_DIR/$VENDORED_PGBOUNCER" -package_download "pgbouncer" "${PGBOUNCER_VERSION}" "${BUILD_DIR}/${VENDORED_PGBOUNCER}" "${STACK}" +tar xzf pgbouncer-${PGBOUNCER_VERSION}.tgz -C ${BUILD_DIR}/${VENDORED_PGBOUNCER} # vendor stunnel into the slug PATH="$BUILD_DIR/$VENDORED_STUNNEL/bin:$PATH" echo "-----> Fetching and vendoring stunnel into slug" mkdir -p "$BUILD_DIR/$VENDORED_STUNNEL" -package_download "stunnel" "${STUNNEL_VERSION}" "${BUILD_DIR}/${VENDORED_STUNNEL}" "${STACK}" +tar xzf stunnel-${STUNNEL_VERSION}.tgz -C ${BUILD_DIR}/${VENDORED_STUNNEL} echo "-----> Moving the configuration generation script into app/bin" mkdir -p $BUILD_DIR/bin diff --git a/bin/gen-pgbouncer-conf.sh b/bin/gen-pgbouncer-conf.sh index a0cccf6..be60726 100644 --- a/bin/gen-pgbouncer-conf.sh +++ b/bin/gen-pgbouncer-conf.sh @@ -62,13 +62,8 @@ EOFEOF for POSTGRES_URL in $POSTGRES_URLS do eval POSTGRES_URL_VALUE=\$$POSTGRES_URL - DB=$(echo $POSTGRES_URL_VALUE | perl -lne 'print "$1 $2 $3 $4 $5 $6 $7" if /^postgres(?:ql)?:\/\/([^:]+):([^@]+)@(.*?):(.*?)\/(.*?)(\\?.*)?$/') - DB_URI=( $DB ) - DB_USER=${DB_URI[0]} - DB_PASS=${DB_URI[1]} - DB_HOST=${DB_URI[2]} - DB_PORT=${DB_URI[3]} - DB_NAME=${DB_URI[4]} + IFS=':' read DB_USER DB_PASS DB_HOST DB_PORT DB_NAME <<< $(echo $POSTGRES_URL_VALUE | perl -lne 'print "$1:$2:$3:$4:$5" if /^postgres(?:ql)?:\/\/([^:]*):([^@]*)@(.*?):(.*?)\/(.*?)$/') + DB_MD5_PASS="md5"`echo -n ${DB_PASS}${DB_USER} | md5sum | awk '{print $1}'` CLIENT_DB_NAME="db${n}" diff --git a/pgbouncer-1.7-heroku.tgz b/pgbouncer-1.7-heroku.tgz new file mode 100644 index 0000000..04712f8 Binary files /dev/null and b/pgbouncer-1.7-heroku.tgz differ diff --git a/stunnel-5.28.tgz b/stunnel-5.28.tgz new file mode 100644 index 0000000..0defb5f Binary files /dev/null and b/stunnel-5.28.tgz differ diff --git a/support/pgbouncer-1.5.4-sigterm.diff b/support/0001-Disable-SIGTERM.patch similarity index 77% rename from support/pgbouncer-1.5.4-sigterm.diff rename to support/0001-Disable-SIGTERM.patch index f5cb325..d862480 100644 --- a/support/pgbouncer-1.5.4-sigterm.diff +++ b/support/0001-Disable-SIGTERM.patch @@ -1,4 +1,4 @@ -From 1f349a5a70ffc3954274db38e1703f869ceb5188 Mon Sep 17 00:00:00 2001 +From 7e2d3a9f0fe6ae990278333cc19bba5a76c57b79 Mon Sep 17 00:00:00 2001 From: Greg Burek Date: Sun, 16 Mar 2014 20:00:27 -0700 Subject: [PATCH] Disable SIGTERM @@ -8,10 +8,10 @@ Subject: [PATCH] Disable SIGTERM 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src/main.c b/src/main.c -index cd80377..459354f 100644 +index 78039bd..75f6c59 100644 --- a/src/main.c +++ b/src/main.c -@@ -331,9 +331,7 @@ static struct event ev_sigint; +@@ -401,9 +401,7 @@ static struct event ev_sigint; static void handle_sigterm(int sock, short flags, void *arg) { @@ -23,5 +23,5 @@ index cd80377..459354f 100644 static void handle_sigint(int sock, short flags, void *arg) -- -1.9.0 +2.6.3 diff --git a/support/Dockerfile b/support/Dockerfile index 82e0ffc..777e613 100644 --- a/support/Dockerfile +++ b/support/Dockerfile @@ -4,13 +4,8 @@ MAINTAINER gregburek RUN apt-get -q update RUN apt-get -q -y install curl gcc g++ make wget unzip -RUN wget -q https://github.com/rlmcpherson/s3gof3r/releases/download/v0.3.2/gof3r_0.3.2_linux_amd64.tar.gz -RUN tar zxf gof3r_0.3.2_linux_amd64.tar.gz -RUN mv gof3r_0.3.2_linux_amd64/gof3r . -RUN rm -rf gof3r_0.3.2_linux_amd64* - ADD pgbouncer-build pgbouncer-build -ADD pgbouncer-1.5.4-sigterm.diff pgbouncer-patch +ADD 0001-Disable-SIGTERM.patch pgbouncer-patch CMD ./pgbouncer-build diff --git a/support/docker-compose.yml b/support/docker-compose.yml new file mode 100644 index 0000000..5151c0c --- /dev/null +++ b/support/docker-compose.yml @@ -0,0 +1,8 @@ +pgbouncer-builder: + build: . + environment: + PGBOUNCER_VERSION: "1.7" + STUNNEL_VERSION: "5.28" + command: bash -c './pgbouncer-build' + volumes: + - ..:/external diff --git a/support/pgbouncer-build b/support/pgbouncer-build index 8475740..13095ab 100755 --- a/support/pgbouncer-build +++ b/support/pgbouncer-build @@ -1,33 +1,34 @@ set -e -if [ ! -f "/var/cache/pgbouncer-$PGBOUNCER_VERSION.tar.gz" ]; then - wget -q -O /var/cache/pgbouncer-$PGBOUNCER_VERSION.tar.gz http://pgfoundry.org/frs/download.php/3393/pgbouncer-$PGBOUNCER_VERSION.tar.gz -fi - -tar zxf /var/cache/pgbouncer-$PGBOUNCER_VERSION.tar.gz - -cd pgbouncer-$PGBOUNCER_VERSION -git apply /pgbouncer-patch -./configure --prefix=/app/vendor/pgbouncer -make -make install - -cd /app/vendor/pgbouncer -tar -zcf - . | /gof3r put -b $S3_BUCKET -k cedar-14/pgbouncer-$PGBOUNCER_VERSION-heroku.tgz - -cd / - -if [ ! -f "/var/cache/stunnel-$STUNNEL_VERSION.tar.gz" ]; then - wget -q --no-check-certificate -O /var/cache/stunnel-$STUNNEL_VERSION.tar.gz https://www.stunnel.org/downloads/stunnel-$STUNNEL_VERSION.tar.gz - # cert is for mirt.net, which does not match stunnel.org -fi - -tar zxf /var/cache/stunnel-$STUNNEL_VERSION.tar.gz - -cd stunnel-$STUNNEL_VERSION -./configure --prefix=/app/vendor/stunnel -make -make install - -cd /app/vendor/stunnel -tar -zcf - . | /gof3r put -b $S3_BUCKET -k cedar-14/stunnel-$STUNNEL_VERSION.tgz +PGBOUNCER_VERSION=${PGBOUNCER_VERSION-1.7} +STUNNEL_VERSION=${STUNNEL_VERSION-5.28} + +pgbouncer_tarball_url=https://pgbouncer.github.io/downloads/files/${PGBOUNCER_VERSION}/pgbouncer-${PGBOUNCER_VERSION}.tar.gz +stunnel_tarball_url=https://www.stunnel.org/downloads/stunnel-${STUNNEL_VERSION}.tar.gz + +echo "Downloading $pgbouncer_tarball_url" +curl -L $pgbouncer_tarball_url | tar xzv + +( + cd pgbouncer-${PGBOUNCER_VERSION} + git apply /pgbouncer-patch + ./configure \ + --prefix=/app/vendor/pgbouncer + make + make install +) + +tar -zcvf /external/pgbouncer-${PGBOUNCER_VERSION}-heroku.tgz -C /app/vendor/pgbouncer . + +echo "Downloading $stunnel_tarball_url" +curl -L $stunnel_tarball_url | tar xzv + +( + cd stunnel-${STUNNEL_VERSION} + ./configure \ + --prefix=/app/vendor/stunnel + make + make install +) + +tar -zcvf /external/stunnel-${STUNNEL_VERSION}.tgz -C /app/vendor/stunnel .