FROM ubuntu:14.04

MAINTAINER Alexis Manin <alexis.manin@geomatys.com>

# fix locale
RUN locale-gen en_US.UTF-8
ENV LANG en_US.UTF-8
ENV LANGUAGE en_US:en
ENV LC_ALL en_US.UTF-8
ENV PG_VERSION 9.4
ENV PGIS_VERSION 2.1

# Add the PostgreSQL PGP key to verify their Debian packages
# It should be the same key as https://www.postgresql.org/media/keys/ACCC4CF8.asc
RUN apt-key adv \
        --keyserver hkp://keyserver.ubuntu.com:80 \
        --recv-keys B97B0AFCAA1A47F044F244A07FCC7D46ACCC4CF8 && \
    echo "deb http://apt.postgresql.org/pub/repos/apt/ trusty-pgdg main $PG_VERSION" \
        > /etc/apt/sources.list.d/pgdg.list && \
    apt-get update

RUN apt-get upgrade -y

RUN apt-get install -y \
	    curl \
	    libpq5 \
      	psmisc \
	    postgresql-$PG_VERSION \
	    postgresql-client-$PG_VERSION \
	    postgresql-$PG_VERSION-postgis-$PGIS_VERSION


#>> Cleanup
RUN rm -rf /var/lib/apt/lists/* /tmp/* && \
	apt-get autoremove -y && \
	apt-get autoclean

# install gosu
RUN curl -o /usr/local/bin/gosu -sSL "https://github.com/tianon/gosu/releases/download/1.4/gosu-$(dpkg --print-architecture)" \
	&& chmod +x /usr/local/bin/gosu

ENV PGDATA /var/rhomeo/pgdata

VOLUME /var/rhomeo/pgdata

ADD entrypoint-postgres.sh /usr/local/bin/entrypoint.sh

RUN chmod +x /usr/local/bin/entrypoint.sh


EXPOSE 5432

ENTRYPOINT ["/usr/local/bin/entrypoint.sh"]

CMD ["postgres"]


