FROM registry.fedoraproject.org/fedora:rawhide

# Install generic dependencies to build jss
RUN true \
        && dnf update -y --refresh \
        && dnf install -y dnf-plugins-core gcc make rpm-build cmake \
                          nss-tools apache-commons-lang3 \
                          gcc-c++ jpackage-utils slf4j zlib-devel perl \
                          slf4j-jdk14 junit ninja-build gyp gtest mercurial \
                          python-unversioned-command \
        && dnf build-dep nss nspr jss -y \
        && mkdir -p /home/sandbox \
        && dnf clean -y all \
        && rm -rf /usr/share/doc /usr/share/doc-base \
                  /usr/share/man /usr/share/locale /usr/share/zoneinfo \
        && true

# Link in the current version of jss from the git repository
WORKDIR /home/sandbox
COPY . /home/sandbox/jss

# Download and build NSPR and NSS
RUN true \
        && cd /home/sandbox \
        && hg clone https://hg.mozilla.org/projects/nspr \
        && hg clone https://hg.mozilla.org/projects/nss \
        && cd nss \
        && ./build.sh --enable-fips --enable-libpkix \
        && true

# Perform the actual RPM build
WORKDIR /home/sandbox/jss
CMD true \
        && export SANDBOX=1 \
        && rm -rf build \
        && mkdir build \
        && cd build \
        && CFLAGS="-Wall -Wextra -Werror -Og -ggdb" cmake -DCMAKE_BUILD_TYPE=Debug .. \
        && make all \
        && ctest --output-on-failure \
        && true
