#!/bin/bash # Installs and starts a throwaway MariaDB inside a CI job container (Debian or # Ubuntu, as root) and creates the database and user from DB_NAME, DB_USER and # DB_PASSWORD. Used instead of a service container: the Gitea runner puts jobs on # Docker's default bridge network, where services can't be reached by name. set -euo pipefail : "${DB_NAME:?}" "${DB_USER:?}" "${DB_PASSWORD:?}" # 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 transient failures. 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 for attempt in 1 2 3; do if apt-get -o Acquire::Retries=3 update -qq \ && DEBIAN_FRONTEND=noninteractive apt-get -o Acquire::Retries=3 install -y -qq --no-install-recommends mariadb-server >/dev/null; then break fi [ "$attempt" = 3 ] && { echo "::error::could not install mariadb-server"; exit 1; } echo "apt failed (attempt $attempt); retrying in 10s" sleep 10 done 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 DATABASE IF NOT EXISTS \`${DB_NAME}\`; CREATE USER IF NOT EXISTS '${DB_USER}'@'127.0.0.1' IDENTIFIED BY '${DB_PASSWORD}'; GRANT ALL ON \`${DB_NAME}\`.* TO '${DB_USER}'@'127.0.0.1';" echo "node $(node --version), $(mariadb --version)"