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 && \
    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
