##############################################################################
# Dockerfile to build postgres for LINDAT Dspace container
# Based on Postgres
##############################################################################
ARG POSTGRES_VERSION=9.6

FROM gitlab.inf.unibz.it:4567/commul/docker/clarin-dspace/dspace-app/2020.02.1:1.0 as dspace-app

FROM postgres:$POSTGRES_VERSION
ARG POSTGRES_VERSION

ARG LABEL_VCS_URL="https://gitlab.inf.unibz.it/commul/docker/clarin-dspace"
LABEL maintainer="Alexander König <Alexander.Koenig@eurac.edu>" \
      maintainer="Egon W. Stemle <egon.stemle@eurac.edu>"

ENV TERM linux
# APT(-GET) tweaks
# Set some sane defaults for apt inside docker
ENV DEBIAN_FRONTEND=noninteractive
COPY apt.local.conf /etc/apt/apt.conf.d/99local.conf
#
#
RUN apt-get update && \
    apt-get upgrade

# Install git
RUN apt-get update && apt-get install git

# copy int db script
RUN mkdir -p /docker-entrypoint-initdb.d
COPY init-dspace-dbs.sh /docker-entrypoint-initdb.d/
RUN chmod +x /docker-entrypoint-initdb.d/*

# FIXME: still needed?
# copy over modified config file
#COPY commul-customization/postgresql.conf /tmp/
#COPY commul-customization/updateConfig.sh /docker-entrypoint-initdb.d/_updateConfig.sh

# Adapt license definitions file
RUN mkdir /tmp/sql/
COPY --from=dspace-app /app/utilities/utilities.sql /tmp/sql/
COPY --from=dspace-app /app/utilities/license_definition.txt /tmp/sql
RUN chmod -R a+w /tmp/sql/ && \
    perl -pi -e "s#afile :utildir '/license_definition.txt'#afile '/tmp/sql/license_definition.txt'#;" /tmp/sql/utilities.sql

ARG LABEL_VERSION
ARG LABEL_BUILD_DATE
LABEL org.label-schema.version="$LABEL_VERSION"
LABEL org.label-schema.build-date="$LABEL_BUILD_DATE"
LABEL org.label-schema.vcs-url="$LABEL_VCS_URL"