Guest User

Untitled

a guest
Jun 12th, 2018
129
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.98 KB | None | 0 0
  1. // Dockerfile
  2. FROM postgres:9.6-alpine
  3.  
  4. ENV GOSU_VERSION 1.10
  5. RUN set -ex;
  6.  
  7. apk add --no-cache --virtual .gosu-deps
  8. dpkg
  9. gnupg
  10. openssl
  11. ;
  12.  
  13. dpkgArch="$(dpkg --print-architecture | awk -F- '{ print $NF }')";
  14. wget -O /usr/local/bin/gosu "https://github.com/tianon/gosu/releases/download/$GOSU_VERSION/gosu-$dpkgArch";
  15. wget -O /usr/local/bin/gosu.asc "https://github.com/tianon/gosu/releases/download/$GOSU_VERSION/gosu-$dpkgArch.asc";
  16.  
  17. # verify the signature
  18. export GNUPGHOME="$(mktemp -d)";
  19. gpg --keyserver ha.pool.sks-keyservers.net --recv-keys B42F6819007F00F88E364FD4036A9C25BF357DD4;
  20. gpg --batch --verify /usr/local/bin/gosu.asc /usr/local/bin/gosu;
  21. rm -r "$GNUPGHOME" /usr/local/bin/gosu.asc;
  22.  
  23. chmod +x /usr/local/bin/gosu;
  24. # verify that the binary works
  25. gosu nobody true;
  26.  
  27. apk del .gosu-deps
  28.  
  29. RUN apk add --update iputils
  30. RUN apk add --update htop
  31.  
  32. # COPY ./setup-slave.sh /docker-entrypoint-initdb.d
  33. COPY ./docker-entrypoint.sh /docker-entrypoint.sh
  34.  
  35. RUN chmod +x /docker-entrypoint.sh
  36.  
  37. CMD ["gosu", "postgres", "pg_ctl", "-D/var/lib/postgresql/data", "start"]
  38.  
  39. #!/bin/bash
  40. if [ ! -s "$PGDATA/PG_VERSION" ]; then
  41. echo '*:*:*:myuser:123456' > ~/.pgpass
  42.  
  43. chmod 0600 ~/.pgpass
  44.  
  45. until ping -c 1 -W 1 pg_master
  46. do
  47. echo "Waiting for master to ping..."
  48. sleep 1s
  49. done
  50. until pg_basebackup -h pg_master -D ${PGDATA} -U arioo -vP -W
  51. do
  52. echo "Waiting for master to connect..."
  53. sleep 1s
  54. done
  55.  
  56. echo "host replication all 0.0.0.0/0 md5" >> "$PGDATA/pg_hba.conf"
  57.  
  58. set -e
  59. cat >> ${PGDATA}/postgresql.conf <<EOF
  60.  
  61. wal_level = hot_standby
  62. max_wal_senders = 8
  63. wal_keep_segments = 32
  64. hot_standby = off
  65. EOF
  66.  
  67. cat > ${PGDATA}/recovery.conf <<EOF
  68. standby_mode = on
  69. primary_conninfo = 'host=pg_master port=5432 user=rep password=123456'
  70. trigger_file = '/tmp/touch_me_to_promote_to_me_master'
  71. EOF
  72. chown postgres. ${PGDATA} -R
  73. chmod 700 ${PGDATA} -R
  74. fi
  75. exec "$@"
  76.  
  77. while true; do
  78. sleep 1s
  79. done
Add Comment
Please, Sign In to add comment