Advertisement
manobombo

Untitled

Dec 13th, 2018
89
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 3.62 KB | None | 0 0
  1. # Pulling CentOS 7 image
  2. FROM centos:centos7
  3.  
  4. # Setting global environment variables
  5. ENV PG_VERSION 9.6
  6. ENV PG_HBA /var/lib/pgsql/$PG_VERSION/data/pg_hba.conf
  7. ENV PG_CONF /var/lib/pgsql/$PG_VERSION/data/postgresql.conf
  8. ENV PGDATA /var/lib/pgsql/$PG_VERSION/data
  9.  
  10. # Setting local PATH for pgxn
  11. ENV PATH /usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/pgsql-$PG_VERSION/bin
  12.  
  13. # Installing primary packages, Postgres 9.6 to CentOS 7 and setting timezone to Europe/Copenhagen
  14. RUN yum -y update && yum clean all && yum -y install epel-release gnupg && \
  15. yum -y install https://download.postgresql.org/pub/repos/yum/9.6/redhat/rhel-7-x86_64/pgdg-centos96-9.6-3.noarch.rpm && \
  16. yum clean all && echo "Europe/Copenhagen" > /etc/timezone && yum update && \
  17. yum -y install acl gcc gcc-c++ sudo \
  18.     postgresql96 postgresql96-contrib postgresql96-devel \
  19.     postgresql96-server postgresql96-plpython vim perl-CPAN \
  20.     cpanminus perl-DBD-Pg libdbi-dbd-pgsql git unzip pgxnclient python-setuptools && \
  21.         cpanm --mirror http://mirrors.dotsrc.org/cpan/ --quiet --force --notest App::Sqitch && \
  22.     export PATH="${PATH}:/usr/pgsql-$PG_VERSION/bin" && pgxn install first_last_agg && \
  23.     pgxn install plpgsql_check && pgxn install pgtap && cpan TAP::Parser::SourceHandler::pgTAP && \
  24.     pgxn install geoip && rm -rf /var/cache/yum
  25.  
  26. # Initializing the database as postgres user
  27. USER postgres
  28. RUN /usr/pgsql-$PG_VERSION/bin/initdb -D $PGDATA
  29.  
  30. # Changing to root user
  31. USER root
  32.  
  33. # Enabling postgresql TCP, loading shared libraries on startup
  34. # Allowing connections from all hosts (it's ok for development, never do this in production!) and getting rid of the unecessary protocols
  35. RUN sed -i "s/^#listen_addresses = 'localhost'/listen_addresses = '*'/" $PG_CONF && \
  36. sed -i "s/^#shared_preload_libraries = ''/shared_preload_libraries = 'plpgsql,pg_stat_statements'/" $PG_CONF && \
  37. sed -i "s/^#listen_addresses = 'localhost'/listen_addresses = '*'/" $PG_CONF && \
  38. sed -i '86s/.*/#&/' $PG_HBA && sed -i '88s/.*/#&/' $PG_HBA && \
  39. echo "host    all             all             all                 md5" >> $PG_HBA
  40.  
  41. # Copying the db contents to the migrations folder, loading the schema using sqitch and setting the right permissions.
  42. RUN mkdir /var/lib/pgsql/migrations && chgrp -R postgres /var/lib/pgsql/migrations && \
  43. chown -R postgres:postgres /var/lib/pgsql/migrations && chmod -R 777 /var/lib/pgsql/migrations
  44.  
  45. COPY .git /var/lib/pgsql/migrations/.git
  46. COPY deploy /var/lib/pgsql/migrations/deploy
  47. COPY revert /var/lib/pgsql/migrations/revert
  48. COPY sqitch.conf /var/lib/pgsql/migrations
  49. COPY sqitch.plan /var/lib/pgsql/migrations
  50. COPY create-new.sql /var/lib/pgsql
  51. COPY create-bmetricdb.sql /var/lib/pgsql
  52. COPY run_pg_service.sh /
  53.  
  54. # Starting the server while creating the roles and empty database
  55. USER postgres
  56. RUN /usr/pgsql-$PG_VERSION/bin/pg_ctl start && sleep 5 && psql --file=/var/lib/pgsql/create-new.sql && \
  57. cd /var/lib/pgsql/migrations && psql --file=/var/lib/pgsql/create-bmetricdb.sql && /usr/pgsql-$PG_VERSION/bin/pg_ctl stop
  58.  
  59. # Exposing the PostgreSQL port to the host
  60. EXPOSE 5432
  61.  
  62. # Adding VOLUMEs to allow backup of config, logs and databases
  63. VOLUME  ["/etc/pgsql", "/var/log/pgsql", "/var/lib/pgsql"]
  64.  
  65. # Switching to root user
  66. USER root
  67.  
  68. # Removing packages that aren't needed anymore
  69. RUN yum -y remove acl gcc gcc-c++ vim unzip bison flex libtool gettext autoconf automake cpp kernel-headers \
  70. gdb dyninst gcc-gfortran doxygen swig dyninst kernel-debug-devel && \
  71. yum clean all && rm -rf /var/cache/yum
  72.  
  73. # Running the service as container starts as postgres user (root session remains active)
  74. CMD ["./run_pg_service.sh"]
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement