Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CODEOWNERS
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# Docs for this feature: https://help.github.com/articles/about-codeowners/
/ @plangrid/DevOps
15 changes: 0 additions & 15 deletions Dockerfile

This file was deleted.

44 changes: 44 additions & 0 deletions Dockerfile.j2
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
FROM ubuntu:16.04

ARG ARTIFACTORY_USER
ARG ARTIFACTORY_PASSWORD

ENV PGBOUNCER_VERSION=1.7.2-2.pgdg16.04+1 \
ARTIFACTORY_USER='read-only' \
ARTIFACTORY_PASSWORD='UN5cDIG5EyJdDrc5EBwB'

# Prep apt
# test
# Using /usr/bin/apt-get here because these are dependencies we need for our
# custom apt-get to work
RUN ln -sf /bin/bash /bin/sh \
&& /usr/bin/apt-get update \
&& /usr/bin/apt-get install -y \
apt-transport-https \
ca-certificates \
curl \
locales \
wget \
gnupg \
# make sure en_US.UTF-8 is installed
&& locale-gen en_US.UTF-8 \
# cleanup
&& /usr/bin/apt-get clean \
&& /usr/bin/apt-get autoremove

# Artifactory apt repo
RUN echo "deb https://${ARTIFACTORY_USER}:${ARTIFACTORY_PASSWORD}@plangrid.jfrog.io/plangrid/debs-local xenial main" > /etc/apt/sources.list.d/artifactory.list \
&& curl -u ${ARTIFACTORY_USER}:${ARTIFACTORY_PASSWORD} https://plangrid.jfrog.io/plangrid/api/gpg/key/public \
| apt-key add -

RUN set -x \
&& apt-get -qq update \
&& apt-get install -yq --no-install-recommends pgbouncer=$PGBOUNCER_VERSION \
&& apt-get purge -y --auto-remove \
&& rm -rf /var/lib/apt/lists/*

ADD entrypoint.sh ./

EXPOSE 5432

CMD ["./entrypoint.sh"]
4 changes: 4 additions & 0 deletions Jenkinsfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#!groovy
node {
StandardBuild()
}
70 changes: 67 additions & 3 deletions entrypoint.sh
Original file line number Diff line number Diff line change
@@ -1,13 +1,77 @@
#!/bin/bash
set -e
set -xe

PG_LOG=/var/log/postgresql/
PG_CONFIG=/etc/pgbouncer/pgbouncer.ini
PG_CONFIG_DIR=/etc/pgbouncer
PG_USER=postgres

if [ -f ${PG_CONFIG_DIR}/pgbouncer.ini ]; then
rm ${PG_CONFIG_DIR}/pgbouncer.ini
else
mkdir -p ${PG_CONFIG_DIR}
fi

cp /mnt/private.pem ${PG_CONFIG_DIR}/private.pem
chmod 400 ${PG_CONFIG_DIR}/private.pem
cp /mnt/public.pem ${PG_CONFIG_DIR}/public.pem
chmod 400 ${PG_CONFIG_DIR}/public.pem

echo "create pgbouncer config in ${PG_CONFIG_DIR}"

printf "\
[databases]
${DB_NAME} = host=${DB_HOST:?"Setup pgbouncer config error! You must set DB_HOST env"} port=${DB_PORT:-5432} \
${DB_PASSWORD:+password=${DB_PASSWORD}}

[pgbouncer]
logfile = /var/log/postgresql/pgbouncer.log
pidfile = /var/run/postgresql/pgbouncer.pid

listen_addr = 0.0.0.0
listen_port = 5432

unix_socket_dir = /var/run/postgresql

auth_type = md5
auth_file = /etc/pgbouncer/userlist.txt

pool_mode = transaction

server_reset_query = DISCARD ALL

max_client_conn = 5000
default_pool_size = 180

admin_users = ${PGBOUNCER_ADMIN_USERS}

client_tls_sslmode = require
client_tls_key_file = /etc/pgbouncer/private.pem
client_tls_cert_file = /etc/pgbouncer/public.pem
client_tls_ca_file = /etc/pgbouncer/public.pem
client_tls_protocols = secure

# fivetran connects with extra_float_digits.
# See ref for extra_float_digits:
# https://www.postgresql.org/docs/9.6/static/runtime-config-client.html
#
# DEVOPS-1640
ignore_startup_parameters = extra_float_digits
" > ${PG_CONFIG_DIR}/pgbouncer.ini

IFS=',' read -r -a pg_usernames <<< "$PG_USERS"
IFS=',' read -r -a pg_passwords <<< "$PG_PASSWORDS"

for index in "${!pg_usernames[@]}"
do
printf "\"${pg_usernames[index]}\" \"${pg_passwords[index]}\"\n" >> ${PG_CONFIG_DIR}/userlist.txt
done

mkdir -p ${PG_LOG}
chmod -R 755 ${PG_LOG}
chown -R ${PG_USER}:${PG_USER} ${PG_LOG}

echo "Starting pgbouncer..."
exec pgbouncer -q -u ${PG_USER} $PG_CONFIG
ls -al /etc/pgbouncer
cat ${PG_CONFIG_DIR}/pgbouncer.ini
cat ${PG_CONFIG_DIR}/userlist.txt
pgbouncer -u $PG_USER ${PG_CONFIG_DIR}/pgbouncer.ini
222 changes: 0 additions & 222 deletions etc/pgbouncer/pgbouncer.ini

This file was deleted.