Bootstrap: docker
From: ubuntu:26.04

%post
    export DEBIAN_FRONTEND=noninteractive
    set -e

    apt-get update && apt-get install -y \
        tzdata \
        wget \
        unzip \
        build-essential \
        libssl-dev \
        zlib1g-dev \
        libbz2-dev \
        libreadline-dev \
        libsqlite3-dev \
        curl \
        libncursesw5-dev \
        xz-utils \
        tk-dev \
        libxml2-dev \
        libxmlsec1-dev \
        libffi-dev \
        liblzma-dev \
		libegl1  \
		libgl1 \
		libglib2.0-0 \
        libx11-6 \
        libxext6 \
        libxrender1 \
        libxkbcommon-x11-0 \
        libxcb1 \
		libdbus-1-3 \
        libxcb-cursor0 \
        libxcb-xinerama0 \
        libsm6 \
        libice6 \
        libglu1-mesa

    ln -fs /usr/share/zoneinfo/Europe/Helsinki /etc/localtime
    dpkg-reconfigure --frontend noninteractive tzdata

    # Clean apt caches
    apt-get clean
    rm -rf /var/lib/apt/lists/*

    # -------------------------------
    # Install Python 3.13 from source
    # -------------------------------
    cd /tmp
    wget https://www.python.org/ftp/python/3.13.0/Python-3.13.0.tgz
    tar -xf Python-3.13.0.tgz
    cd Python-3.13.0

    ./configure --enable-optimizations
    make -j$(nproc)
    make altinstall   # installs as python3.13

    # -------------------------------
    # Create virtual environment
    # -------------------------------
    /usr/local/bin/python3.13 -m venv /opt/venv

    # Activate and install packages
    . /opt/venv/bin/activate
    pip install --upgrade pip
    pip install spinetoolbox

    deactivate

    # Remove Python build artifacts
    cd /
    rm -rf /tmp/Python-3.13.0*

    # -------------------------------
    # Install GAMS
    # -------------------------------
    cd /
    wget https://d37drm4t2jghv5.cloudfront.net/distributions/53.5.1/linux/linux_x64_64_sfx.exe
    chmod +x linux_x64_64_sfx.exe
    ./linux_x64_64_sfx.exe

    mkdir -p /opt
    mv /gams53.5_linux_x64_64_sfx /opt/gams53.5

    rm linux_x64_64_sfx.exe

%environment
    # Make "python" point to venv python
    export PATH=/opt/venv/bin:/opt/gams53.5:$PATH
	export QT_QPA_PLATFORM=offscreen
