FROM registry.fedoraproject.org/fedora:33

# Install generic dependencies to build jss
RUN true \
        && dnf update -y --refresh \
        && dnf install -y dnf-plugins-core git gcc make rpm-build \
                          java-devel python2 python3 diffutils \
        && dnf copr -y enable ${JSS_4_6_REPO:-@pki/10.12} \
        && dnf build-dep -y jss \
        && 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

# Install dependencies from the spec file in case they've changed
# since the last release on this platform.
RUN true \
        && dnf build-dep -y --spec /home/sandbox/jss/jss.spec \
        && true

# Perform the actual RPM build
# Generate a new PKCS11Constants.java and compare the differences
WORKDIR /home/sandbox/jss
CMD true \
        && bash ./build.sh --with-timestamp --with-commit-id rpm \
        && dnf install -y /root/build/jss/RPMS/*.rpm \
        && echo "############################################################" \
        && echo "## Generating PKCS #11 constants with Python 2" \
        && python2 ./tools/build_pkcs11_constants.py \
                   --pkcs11t /usr/include/nss3/pkcs11t.h \
                   --pkcs11n /usr/include/nss3/pkcs11n.h \
                   -o PKCS11Constants-py2.java \
                   --verbose \
        && echo "############################################################" \
        && echo "## Generating PKCS #11 constants with Python 3" \
        && python3 ./tools/build_pkcs11_constants.py -s \
                   --pkcs11t /usr/include/nss3/pkcs11t.h \
                   --pkcs11n /usr/include/nss3/pkcs11n.h \
                   -o PKCS11Constants-py3.java \
                   --verbose \
        && diff PKCS11Constants-py2.java PKCS11Constants-py3.java \
        && diff PKCS11Constants-py3.java src/main/java/org/mozilla/jss/pkcs11/PKCS11Constants.java \
        && true
