diff --git a/net/pgbouncer/Dockerfile b/net/pgbouncer/Dockerfile new file mode 100644 index 0000000..9518370 --- /dev/null +++ b/net/pgbouncer/Dockerfile @@ -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 diff --git a/net/pgbouncer/README.md b/net/pgbouncer/README.md new file mode 100644 index 0000000..74a9da2 --- /dev/null +++ b/net/pgbouncer/README.md @@ -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: ) + +`PG_PORT_5432_TCP_PORT` (default: ) + +`PG_ENV_POSTGRESQL_USER` (default: ) + +`PG_ENV_POSTGRESQL_PASS` (default: ) + +Based on https://github.com/mbentley/dockerfiles/tree/master/ubuntu/pgbouncer diff --git a/net/pgbouncer/run.sh b/net/pgbouncer/run.sh new file mode 100755 index 0000000..a5ac476 --- /dev/null +++ b/net/pgbouncer/run.sh @@ -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