FROM debian:bookworm

ARG VERSION=25.10
ARG IS_CLOUD=0

ARG NODE_VERSION=24
ARG PNPM_VERSION=10.24.0

COPY .github/docker/gorgone/package.json .github/docker/gorgone/pnpm-lock.yaml /usr/local/src/

ENV DEBIAN_FRONTEND=noninteractive

RUN --mount=type=secret,id=ARTIFACTORY_INTERNAL_REPO_USERNAME \
    --mount=type=secret,id=ARTIFACTORY_INTERNAL_REPO_PASSWORD \
    bash -e <<EOF

echo '
Acquire::Retries "10";
Acquire::https::Timeout "300";
Acquire::http::Timeout "300";
APT::Install-Recommends "false";
APT::Install-Suggests "false";
' > /etc/apt/apt.conf.d/99custom

apt-get update

# Install the required lib for language and apt installation. zstd is required for cache management in GHA.
# Install Robotframework and test dependency
apt-get install -y locales lsb-release libcurl4-openssl-dev curl wget gnupg2 \
  apt-transport-https zstd python3 python3-dev python3-pip ca-certificates \
  software-properties-common jq mariadb-client iproute2 procps lsof

localedef -i en_US -c -f UTF-8 -A /usr/share/locale/locale.alias en_US.UTF-8

pip3 install --break-system-packages --no-cache-dir \
  robotframework robotframework-examples robotframework-databaselibrary \
  pymysql robotframework-requests robotframework-jsonlibrary
pip3 cache purge

curl -fsSL https://deb.nodesource.com/setup_${NODE_VERSION}.x | bash -
apt-get install -y nodejs
curl -fsSL https://get.pnpm.io/install.sh | env PNPM_VERSION=${PNPM_VERSION} SHELL="$(which bash)" sh -
source ~/.bashrc
cd /usr/local/src
pnpm install \
  --frozen-lockfile \
  --config.trustPolicy=no-downgrade \
  --config.minimumReleaseAge=2880 \
  --config.blockExoticSubdeps=true

VERSION_CODENAME=\$(
  . /etc/os-release
  echo \$VERSION_CODENAME
)

if [[ "${IS_CLOUD}" == "true" ]]; then
  APT_AUTH_CONF_FILE="/etc/apt/auth.conf.d/centreon-${VERSION}-internal.conf"
  echo "deb https://packages.centreon.com/apt-standard-internal/ \$VERSION_CODENAME-${VERSION}-unstable main" | tee -a /etc/apt/sources.list.d/centreon-unstable.list
  echo "machine packages.centreon.com" > \$APT_AUTH_CONF_FILE
  echo "login $(cat /run/secrets/ARTIFACTORY_INTERNAL_REPO_USERNAME)" >> \$APT_AUTH_CONF_FILE
  echo "password $(cat /run/secrets/ARTIFACTORY_INTERNAL_REPO_PASSWORD)" >> \$APT_AUTH_CONF_FILE
  chmod 600 \$APT_AUTH_CONF_FILE
else
  echo "deb https://packages.centreon.com/apt-standard/ \$VERSION_CODENAME-${VERSION}-stable main" | tee -a /etc/apt/sources.list.d/centreon-stable.list
  echo "deb https://packages.centreon.com/apt-standard/ \$VERSION_CODENAME-${VERSION}-testing-hotfix main" | tee -a /etc/apt/sources.list.d/centreon-testing-hotfix.list
  echo "deb https://packages.centreon.com/apt-standard/ \$VERSION_CODENAME-${VERSION}-testing-release main" | tee -a /etc/apt/sources.list.d/centreon-testing-release.list
  echo "deb https://packages.centreon.com/apt-standard/ \$VERSION_CODENAME-${VERSION}-unstable main" | tee -a /etc/apt/sources.list.d/centreon-unstable.list
fi
echo "deb https://packages.centreon.com/apt-plugins-stable/ \$VERSION_CODENAME main" | tee -a /etc/apt/sources.list.d/centreon-plugins-stable.list
echo "deb https://packages.centreon.com/apt-plugins-testing/ \$VERSION_CODENAME main" | tee -a /etc/apt/sources.list.d/centreon-plugins-testing.list
echo "deb https://packages.centreon.com/apt-plugins-unstable/ \$VERSION_CODENAME main" | tee -a /etc/apt/sources.list.d/centreon-plugins-unstable.list
wget -O- https://packages.centreon.com/api/security/keypair/APT-GPG-KEY/public | gpg --dearmor | tee /etc/apt/trusted.gpg.d/centreon.gpg > /dev/null 2>&1

apt-get update

apt-get install -y \
  perl-base \
  perl-modules \
  libclone-choose-perl \
  libdatetime-perl \
  libdbd-mysql-perl \
  libev-perl \
  libhttp-daemon-ssl-perl \
  libjson-perl \
  libmojolicious-perl \
  libnet-curl-perl \
  librrds-perl \
  libssh-session-perl \
  libxml-simple-perl \
  libzmq-ffi-perl

apt-get clean
rm -rf /var/lib/apt/lists/*

EOF

ENV PATH="/usr/local/src/node_modules/.bin/:$PATH"
