#     Copyright 2025, Kay Hayen, mailto:kay.hayen@gmail.com find license text at end of file

FROM centos:7
ENV container docker

ARG HOST_OS

RUN sed -i s/mirror.centos.org/vault.centos.org/g /etc/yum.repos.d/*.repo; \
sed -i s/^#.*baseurl=http/baseurl=http/g /etc/yum.repos.d/*.repo; \
sed -i s/^mirrorlist=http/#mirrorlist=http/g /etc/yum.repos.d/*.repo; \
sed -i s/^enabled=1/enabled=0/g /etc/yum/pluginconf.d/fastestmirror.conf; \
echo "sslverify=false" >> /etc/yum.conf; \
(cd /lib/systemd/system/sysinit.target.wants/; for i in *; do [ $i == \
systemd-tmpfiles-setup.service ] || rm -f $i; done); \
rm -f /lib/systemd/system/multi-user.target.wants/*;\
rm -f /etc/systemd/system/*.wants/*;\
rm -f /lib/systemd/system/local-fs.target.wants/*; \
rm -f /lib/systemd/system/sockets.target.wants/*udev*; \
rm -f /lib/systemd/system/sockets.target.wants/*initctl*; \
rm -f /lib/systemd/system/basic.target.wants/*;\
rm -f /lib/systemd/system/anaconda.target.wants/*;\
yum -y install epel-release centos-release-scl;\
sed -i s/mirror.centos.org/vault.centos.org/g /etc/yum.repos.d/*.repo; \
sed -i s/^#.*baseurl=http/baseurl=http/g /etc/yum.repos.d/*.repo; \
sed -i s/^mirrorlist=http/#mirrorlist=http/g /etc/yum.repos.d/*.repo; \
yum repolist;\
yum -y install devtoolset-9;\
yum -y install strace patchelf ccache gdb fuse-libs;\
yum -y install openssl-devel openssl11-devel libffi-devel bzip2-devel freetype-devel;\
yum -y install sqlite-devel tk-devel tcl-devel xz-devel ncurses-devel;\
yum -y install mesa-libGL-devel expat-devel gnutls gettext gettext-libs;\
yum -y install fontconfig-devel gdk-pixbuf2 json-glib;\
yum -y install zlib-static;\
yum clean all -y;\
mkdir /usr/local/openssl11;\
cd /usr/local/openssl11;\
ln -s /usr/lib64/openssl11 lib;\
ln -s /usr/include/openssl11 include

ARG PYTHON_VERSION
ARG PYTHON_MINOR_VERSION
ARG TKINTER_VERSION

RUN if [ "${TKINTER_VERSION}" = "8.6" ]; then \
        mkdir -p /opt/ \
    && curl -SL http://prdownloads.sourceforge.net/tcl/tcl8.6.13-src.tar.gz \
    | tar -xzC /opt/ \
    && curl -SL http://prdownloads.sourceforge.net/tcl/tk8.6.13-src.tar.gz \
    | tar -xzC /opt/ \
    && ls -l /opt/ \
    && cd /opt/tcl8.6.13/unix \
    && scl enable devtoolset-9 "./configure --prefix=/usr && make && make install" \
    && cd /opt/tk8.6.13/unix \
    && scl enable devtoolset-9 "./configure --prefix=/usr --with-tcl=/opt/tcl8.6.13/unix && make && make install" \
    && rm -rf /opt/tcl8.6.13 \
    && rm -rf /opt/tk8.6.13 \
    && rm -rf /root/.cache \
        && ldconfig; \
    fi

ENV PIP_ROOT_USER_ACTION=ignore

RUN mkdir -p /opt/ \
    && curl -SL https://www.python.org/ftp/python/${PYTHON_VERSION}.${PYTHON_MINOR_VERSION}/Python-${PYTHON_VERSION}.${PYTHON_MINOR_VERSION}.tgz \
    | tar -xzC /opt/ \
    && cd /opt/Python-${PYTHON_VERSION}.${PYTHON_MINOR_VERSION}/ \
    && echo '*static*' > Modules/Setup.local \
    && if [ -f Modules/Setup ]; then \
       sed Modules/Setup \
          -E -e 's/#(zlib|binascii|math|unicodedata|_sha512|_struct|fcntl|_typing|_pickle|_random|_datetime|_multibytecodec|_codecs_\w+)/\1/' \
          -e 's/-lz/-l:libz.a/' \
          >>Modules/Setup.local; \
       fi \
    && scl enable devtoolset-9 "TCLTK_LIBS='-ltk${TKINTER_VERSION} -ltcl${TKINTER_VERSION}' ./configure --with-openssl=/usr/local/openssl11 --disable-shared --enable-ipv6 --with-ensurepip=install --enable-optimizations && make && make altinstall" \
    && cd /opt \
    && rm -rf /opt/Python-${PYTHON_VERSION}.${PYTHON_MINOR_VERSION} \
    && if [ "$PYTHON_VERSION" = "2.7" ]; then \
        python${PYTHON_VERSION} -m pip install --user -U 'pip<21' 'setuptools<45' \
        && python${PYTHON_VERSION} -m pip install --user -U pycryptodomex tblib; \
       else \
        python${PYTHON_VERSION} -m pip install --user -U 'pip' 'setuptools' wheel pycryptodomex tblib zstandard; \
       fi \
    && rm -rf /root/.cache \
    && find /usr/ -name site-packages \
    && echo "/Nuitka" >/usr/local/lib/python${PYTHON_VERSION}/site-packages/Nuitka.pth

VOLUME [ "/sys/fs/cgroup" ]

#     Part of Nuitka commercial.
#
#     Commercial grade license of Nuitka. No distribution to outside of the
#     buyer is allowed, the file must be kept secret. Usage is limited to
#     Nuitka. Changed versions, or versions of changes sent to the
#     copyright holder are automatically licensed to him under the Apache
#     License, Version 2.0 as used in proper Nuitka, to allow opening code
#     up later.
#
#     Unless required by applicable law or agreed to in writing, software
#     distributed under the License is distributed on an "AS IS" BASIS,
#     WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
