From e72fe1ec7a52b0a763d34c12217ddbfd9208c7d6 Mon Sep 17 00:00:00 2001 From: cproudlock Date: Thu, 27 Aug 2026 01:40:22 +0000 Subject: [PATCH] ci: reach the mysql service by name, not through localhost A service container is reachable on 127.0.0.1 only when the job runs directly on the runner host, which is how GitHub-hosted runners work and how the old host-executor runner worked. Under a container-mode runner the job is itself a container on the services network, published ports land on the runner host rather than the job's own localhost, and the service answers to its name. Fixes: pymysql.err.OperationalError (2003, "Can't connect to MySQL server on '127.0.0.1' ([Errno 111] Connection refused)"). --- .gitea/workflows/ci.yml | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/.gitea/workflows/ci.yml b/.gitea/workflows/ci.yml index 4b426c99..c0e5d2ac 100644 --- a/.gitea/workflows/ci.yml +++ b/.gitea/workflows/ci.yml @@ -88,7 +88,11 @@ jobs: --health-cmd="mysqladmin ping -h localhost -uroot -proot" --health-interval=5s --health-timeout=5s --health-retries=20 env: - DATABASE_URL: mysql+pymysql://root:root@127.0.0.1:3306/shopdb_ci?charset=utf8mb4 + # 'mysql' is the service name, not 127.0.0.1. Under a container-mode + # runner the job is itself a container on the services network, so the + # service is reached by name. Published ports land on the runner host, + # not on the job's localhost the way they do on GitHub-hosted runners. + DATABASE_URL: mysql+pymysql://root:root@mysql:3306/shopdb_ci?charset=utf8mb4 SECRET_KEY: ci-secret JWT_SECRET_KEY: ci-jwt-secret steps: @@ -113,7 +117,7 @@ jobs: run: | .venv/bin/python - <<'PY' import pymysql - c = pymysql.connect(host="127.0.0.1", port=3306, user="root", password="root") + c = pymysql.connect(host="mysql", port=3306, user="root", password="root") with c.cursor() as cur: cur.execute("ALTER DATABASE shopdb_ci CHARACTER SET utf8mb4 " "COLLATE utf8mb4_unicode_ci")