FROM registry.hub.docker.com/library/debian:buster-slim as repo-key
# hadolint ignore=DL3008
RUN apt-get update && \
    DEBIAN_FRONTEND=noninteractive apt-get install -y --no-install-recommends \
        ca-certificates \
        curl \
        gnupg \
    && \
    rm -rf /tmp/* /var/tmp/* /var/lib/apt/lists/* /var/cache/apt/archives/*
WORKDIR /gnupghome
ENV GNUPGHOME /gnupghome
RUN gpg --keyserver hkp://keys.gnupg.net --recv-key 0x810273C4 && \
    gpg --output inverse.gpg --export-options=export-minimal --export 0x810273C4

FROM registry.hub.docker.com/library/debian:buster-slim
# hadolint ignore=DL3008
RUN apt-get update && \
    DEBIAN_FRONTEND=noninteractive apt-get install -y --no-install-recommends \
        apt-transport-https \
        ca-certificates \
    && \
    rm -rf /tmp/* /var/tmp/* /var/lib/apt/lists/* /var/cache/apt/archives/*
COPY --from=repo-key /gnupghome/inverse.gpg /usr/share/keyrings/
COPY inverse.sources /etc/apt/sources.list.d/
# hadolint ignore=DL3008
RUN apt-get update && \
    # FIXME: There's an issue with the sogo package configure script, this is a
    # hackish workaround. The error is: chmod: cannot access
    # '/usr/share/doc/sogo/*.sh': No such file or directory
    mkdir -p /usr/share/doc/sogo/ && touch /usr/share/doc/sogo/foo.sh && \
    DEBIAN_FRONTEND=noninteractive apt-get install -y --no-install-recommends \
        sogo-activesync \
        sogo \
    && \
    rm -rf /tmp/* /var/tmp/* /var/lib/apt/lists/* /var/cache/apt/archives/*
EXPOSE 20000
USER "www-data"
WORKDIR /var/www
CMD [ "apache2", "-DFOREGROUND" ]
HEALTHCHECK CMD wget --spider --quiet http://localhost:20000/ --user-agent 'Healthcheck' || exit 1
