Add pgbouncer

This commit is contained in:
Christine Dodrill 2015-03-25 23:56:53 -07:00
parent cf25c872b6
commit 40da27ad79
3 changed files with 74 additions and 0 deletions

12
net/pgbouncer/Dockerfile Normal file
View File

@ -0,0 +1,12 @@
FROM ubuntu:14.04
RUN apt-get update && apt-get -y install wget
RUN wget --quiet --no-check-certificate -O - https://www.postgresql.org/media/keys/ACCC4CF8.asc | apt-key add -
RUN echo "deb http://apt.postgresql.org/pub/repos/apt/ precise-pgdg main" > /etc/apt/sources.list.d/pgdg.list
RUN apt-get update
RUN DEBIAN_FRONTEND=noninteractive apt-get -y install pgbouncer
ADD run.sh /run.sh
EXPOSE 5432
CMD /run.sh

19
net/pgbouncer/README.md Normal file
View File

@ -0,0 +1,19 @@
# `docker-pgbouncer`
docker image for pgbouncer
Example usage:
`docker run -i -t -d -p 6432:6432 --link postgres:pg xena/docker-pgbouncer`
This requires a link (named pg) to a postgres container or manually configured
environment variables as follows:
`PG_PORT_5432_TCP_ADDR` (default: <empty>)
`PG_PORT_5432_TCP_PORT` (default: <empty>)
`PG_ENV_POSTGRESQL_USER` (default: <empty>)
`PG_ENV_POSTGRESQL_PASS` (default: <empty>)
Based on https://github.com/mbentley/dockerfiles/tree/master/ubuntu/pgbouncer

43
net/pgbouncer/run.sh Executable file
View File

@ -0,0 +1,43 @@
#!/bin/bash
set -e
PG_PORT_5432_TCP_ADDR=${PG_PORT_5432_TCP_ADDR:-}
PG_PORT_5432_TCP_PORT=${PG_PORT_5432_TCP_PORT:-}
PG_ENV_POSTGRESQL_USER=${PG_ENV_POSTGRESQL_USER:-}
PG_ENV_POSTGRESQL_PASS=${PG_ENV_POSTGRESQL_PASS:-}
if [ ! -f /etc/pgbouncer/pgbconf.ini ]
then
cat << EOF > /etc/pgbouncer/pgbconf.ini
[databases]
* = host=${PG_PORT_5432_TCP_ADDR} port=${PG_PORT_5432_TCP_PORT}
[pgbouncer]
logfile = /var/log/postgresql/pgbouncer.log
pidfile = /var/run/postgresql/pgbouncer.pid
;listen_addr = *
listen_addr = 0.0.0.0
listen_port = 5432
unix_socket_dir = /var/run/postgresql
;auth_type = any
auth_type = trust
auth_file = /etc/pgbouncer/userlist.txt
pool_mode = session
server_reset_query = DISCARD ALL
max_client_conn = 100
default_pool_size = 20
ignore_startup_parameters = extra_float_digits
EOF
fi
if [ ! -s /etc/pgbouncer/userlist.txt ]
then
echo '"'"${PG_ENV_POSTGRESQL_USER}"'" "'"${PG_ENV_POSTGRESQL_PASS}"'"' > /etc/pgbouncer/userlist.txt
fi
chown -R postgres:postgres /etc/pgbouncer
chown root:postgres /var/log/postgresql
chmod 1775 /var/log/postgresql
chmod 640 /etc/pgbouncer/userlist.txt
/usr/sbin/pgbouncer -u postgres /etc/pgbouncer/pgbconf.ini