ARG VERSION

FROM postgres:${VERSION} AS base

ENV DB_USER=username
ENV DB_PASSWORD=pass
ENV POSTGRES_PASSWORD=root

COPY --from=artifacts schema.sql /docker-entrypoint-initdb.d/001_schema.sql
COPY --from=artifacts postgresql.conf /etc/postgresql.conf
COPY initdb /docker-entrypoint-initdb.d/
RUN chown -R postgres:postgres /docker-entrypoint-initdb.d

COPY healthcheck.sh /usr/local/bin/

HEALTHCHECK --interval=1s --timeout=5s \
    CMD /usr/local/bin/healthcheck.sh

ENTRYPOINT ["docker-entrypoint.sh"]
CMD ["postgres"]
