# Base Containerfile for Debcraft
FROM debian:sid

ENV DEBIAN_FRONTEND=noninteractive

# Debian build essentials and Debcraft essentials
# Unfortunately this is almost 500 MB but here is no way around it. Luckily due
# to caching all rebuilds and all later containers will build much faster.
RUN apt-get update -q && \
    apt-get install -q --yes --no-install-recommends \
    blhc \
    ccache \
    curl \
    devscripts \
    eatmydata \
    equivs \
    fakeroot \
    git \
    git-buildpackage \
    lintian \
    pristine-tar

# Validator dependencies
RUN apt-get install -q --yes --no-install-recommends \
  autopkgtest \
  apt-utils \
  diffoscope-minimal \
  hunspell-en-us \
  python3-debian \
  python3-hunspell \
  python3-levenshtein \
  shellcheck \
  xxd

# @TODO: The dh-debputy and python3-lsprotocol are available only in latest
# Debian Sid 2024, and thus building containers of older Debian and Ubuntu
# releases will fail and thus an override to return a successful exit code is
# needed. This can be removed once dh-debputy with dependencies is available via
# backports: https://salsa.debian.org/debian/debputy/-/issues/76#note_512583
RUN apt-get install -q --yes --no-install-recommends \
  dh-debputy \
  python3-lsprotocol || true

COPY control /
RUN apt-get update -q && \
    DEBIAN_FRONTEND=noninteractive mk-build-deps -r -i /control \
    -t 'apt-get -y -o Debug::pkgProblemResolver=yes --no-install-recommends'

# Should be automatic and not needed at all, but run one more time just to be sure
RUN update-ccache-symlinks

# Older ccache does not support '--verbose' but will print stats anyway, just
# followed by help section. Newer ccache 4.0+ (Ubuntu 22.04 "Focal", Debian 12
# "Bullseye") however require '--verbose' to show any cache hit stats at all.
RUN ccache --show-stats  --verbose || true

# Enable source repositories so debcraft-downloader can work
COPY enable-source-repositories.sh /enable-source-repositories
RUN /enable-source-repositories

RUN apt-get install -q --yes command-not-found && \
    apt-get update -q

COPY *.sh /
