Skip to content

Commit

Permalink
Merge pull request #67 from heroku/updates
Browse files Browse the repository at this point in the history
Various improvements
  • Loading branch information
gregburek committed Jan 20, 2016
2 parents c8cb7f9 + 664b235 commit b385b81
Show file tree
Hide file tree
Showing 11 changed files with 74 additions and 87 deletions.
18 changes: 6 additions & 12 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -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=<pgbouncer-version> \
-e STUNNEL_VERSION=<stunnel-version> \
-e AWS_ACCESS_KEY_ID=<ur-key> \
-e AWS_SECRET_ACCESS_KEY=<ur-secret-key> \
-e S3_BUCKET="gregburek-buildpack-pgbouncer" \
your-username/pgbouncer-builder
$ docker-compose build
$ docker-compose up
```

## Publishing buildpack updates
Expand All @@ -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
```
11 changes: 11 additions & 0 deletions Changelog.md
Original file line number Diff line number Diff line change
@@ -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)
Expand Down
12 changes: 6 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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.
Expand Down
25 changes: 4 additions & 21 deletions bin/compile
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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"
Expand All @@ -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
Expand Down
9 changes: 2 additions & 7 deletions bin/gen-pgbouncer-conf.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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}"
Expand Down
Binary file added pgbouncer-1.7-heroku.tgz
Binary file not shown.
Binary file added stunnel-5.28.tgz
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -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 <greg.burek@gmail.com>
Date: Sun, 16 Mar 2014 20:00:27 -0700
Subject: [PATCH] Disable SIGTERM
Expand All @@ -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)
{
Expand All @@ -23,5 +23,5 @@ index cd80377..459354f 100644

static void handle_sigint(int sock, short flags, void *arg)
--
1.9.0
2.6.3

7 changes: 1 addition & 6 deletions support/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -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

8 changes: 8 additions & 0 deletions support/docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
pgbouncer-builder:
build: .
environment:
PGBOUNCER_VERSION: "1.7"
STUNNEL_VERSION: "5.28"
command: bash -c './pgbouncer-build'
volumes:
- ..:/external
63 changes: 32 additions & 31 deletions support/pgbouncer-build
Original file line number Diff line number Diff line change
@@ -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 .

0 comments on commit b385b81

Please sign in to comment.