Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # Pulling CentOS 7 image
- FROM centos:centos7
- # Setting global environment variables
- ENV PG_VERSION 9.6
- ENV PG_HBA /var/lib/pgsql/$PG_VERSION/data/pg_hba.conf
- ENV PG_CONF /var/lib/pgsql/$PG_VERSION/data/postgresql.conf
- ENV PGDATA /var/lib/pgsql/$PG_VERSION/data
- # Setting local PATH for pgxn
- ENV PATH /usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/pgsql-$PG_VERSION/bin
- # Installing primary packages, Postgres 9.6 to CentOS 7 and setting timezone to Europe/Copenhagen
- RUN yum -y update && yum clean all && yum -y install epel-release gnupg && \
- yum -y install https://download.postgresql.org/pub/repos/yum/9.6/redhat/rhel-7-x86_64/pgdg-centos96-9.6-3.noarch.rpm && \
- yum clean all && echo "Europe/Copenhagen" > /etc/timezone && yum update && \
- yum -y install acl gcc gcc-c++ sudo \
- postgresql96 postgresql96-contrib postgresql96-devel \
- postgresql96-server postgresql96-plpython vim perl-CPAN \
- cpanminus perl-DBD-Pg libdbi-dbd-pgsql git unzip pgxnclient python-setuptools && \
- cpanm --mirror http://mirrors.dotsrc.org/cpan/ --quiet --force --notest App::Sqitch && \
- export PATH="${PATH}:/usr/pgsql-$PG_VERSION/bin" && pgxn install first_last_agg && \
- pgxn install plpgsql_check && pgxn install pgtap && cpan TAP::Parser::SourceHandler::pgTAP && \
- pgxn install geoip && rm -rf /var/cache/yum
- # Initializing the database as postgres user
- USER postgres
- RUN /usr/pgsql-$PG_VERSION/bin/initdb -D $PGDATA
- # Changing to root user
- USER root
- # Enabling postgresql TCP, loading shared libraries on startup
- # Allowing connections from all hosts (it's ok for development, never do this in production!) and getting rid of the unecessary protocols
- RUN sed -i "s/^#listen_addresses = 'localhost'/listen_addresses = '*'/" $PG_CONF && \
- sed -i "s/^#shared_preload_libraries = ''/shared_preload_libraries = 'plpgsql,pg_stat_statements'/" $PG_CONF && \
- sed -i "s/^#listen_addresses = 'localhost'/listen_addresses = '*'/" $PG_CONF && \
- sed -i '86s/.*/#&/' $PG_HBA && sed -i '88s/.*/#&/' $PG_HBA && \
- echo "host all all all md5" >> $PG_HBA
- # Copying the db contents to the migrations folder, loading the schema using sqitch and setting the right permissions.
- RUN mkdir /var/lib/pgsql/migrations && chgrp -R postgres /var/lib/pgsql/migrations && \
- chown -R postgres:postgres /var/lib/pgsql/migrations && chmod -R 777 /var/lib/pgsql/migrations
- COPY .git /var/lib/pgsql/migrations/.git
- COPY deploy /var/lib/pgsql/migrations/deploy
- COPY revert /var/lib/pgsql/migrations/revert
- COPY sqitch.conf /var/lib/pgsql/migrations
- COPY sqitch.plan /var/lib/pgsql/migrations
- COPY create-new.sql /var/lib/pgsql
- COPY create-bmetricdb.sql /var/lib/pgsql
- COPY run_pg_service.sh /
- # Starting the server while creating the roles and empty database
- USER postgres
- RUN /usr/pgsql-$PG_VERSION/bin/pg_ctl start && sleep 5 && psql --file=/var/lib/pgsql/create-new.sql && \
- cd /var/lib/pgsql/migrations && psql --file=/var/lib/pgsql/create-bmetricdb.sql && /usr/pgsql-$PG_VERSION/bin/pg_ctl stop
- # Exposing the PostgreSQL port to the host
- EXPOSE 5432
- # Adding VOLUMEs to allow backup of config, logs and databases
- VOLUME ["/etc/pgsql", "/var/log/pgsql", "/var/lib/pgsql"]
- # Switching to root user
- USER root
- # Removing packages that aren't needed anymore
- RUN yum -y remove acl gcc gcc-c++ vim unzip bison flex libtool gettext autoconf automake cpp kernel-headers \
- gdb dyninst gcc-gfortran doxygen swig dyninst kernel-debug-devel && \
- yum clean all && rm -rf /var/cache/yum
- # Running the service as container starts as postgres user (root session remains active)
- CMD ["./run_pg_service.sh"]
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement