ci: reach the mysql service by name, not through localhost
Some checks failed
CI / backend (push) Waiting to run
CI / naming (push) Successful in 3s
CI / frontend (push) Successful in 12s
CI / migrations-mysql (push) Failing after 15s

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)").
This commit is contained in:
2026-08-27 01:40:22 +00:00
parent 702861f1f9
commit e72fe1ec7a

View File

@@ -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")