#!/bin/bash # CI only: installs PHP (and, unless WITH_DB=0, a throwaway MariaDB on # 127.0.0.1:3306 with a 'tinker_ui' user) inside a job container, as root. # # tests/ci/setup.sh # PHP + MariaDB (api and ui jobs) # WITH_DB=0 tests/ci/setup.sh # PHP only (lint and audit jobs) # EXTRA_PKGS="unzip" tests/ci/setup.sh # # Works in the node:22-trixie job image (Debian 13: PHP 8.4, the same packages # as production on CT 132) and in the Playwright image (Ubuntu 24.04: PHP 8.3). # MariaDB runs in the job container rather than as a service container because # the Gitea runner puts jobs on Docker's default bridge network, where services # can't be reached by name (same as Pulse and Thor). set -euo pipefail # The Playwright image points apt at Azure's Ubuntu mirror, which our runner # can't always reach; use the main Ubuntu mirror instead, and retry. for f in /etc/apt/sources.list /etc/apt/sources.list.d/*.list /etc/apt/sources.list.d/*.sources; do [ -f "$f" ] && sed -i 's#http://azure\.archive\.ubuntu\.com/#http://archive.ubuntu.com/#g' "$f" done PKGS="php-cli php-mysql php-mbstring php-curl php-ldap php-xml ${EXTRA_PKGS:-}" [ "${WITH_DB:-1}" = 1 ] && PKGS="mariadb-server $PKGS" for attempt in 1 2 3; do # shellcheck disable=SC2086 if apt-get -o Acquire::Retries=3 update -qq \ && DEBIAN_FRONTEND=noninteractive apt-get -o Acquire::Retries=3 install -y -qq --no-install-recommends $PKGS >/dev/null; then break fi [ "$attempt" = 3 ] && { echo "::error::could not install $PKGS"; exit 1; } echo "apt failed (attempt $attempt); retrying in 10s" sleep 10 done if [ "${WITH_DB:-1}" = 1 ]; then mkdir -p /run/mysqld && chown mysql:mysql /run/mysqld if ! mariadb-admin ping --silent 2>/dev/null; then (mariadbd --user=mysql --bind-address=127.0.0.1 --port=3306 >/tmp/mariadb.log 2>&1 &) fi for _ in $(seq 1 30); do mariadb-admin ping --silent 2>/dev/null && break; sleep 1; done mariadb -e "CREATE USER IF NOT EXISTS 'tinker_ui'@'127.0.0.1' IDENTIFIED BY 'ci-only';" mariadb --version fi php --version | head -1