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)").
This commit is contained in:
@@ -88,7 +88,11 @@ jobs:
|
|||||||
--health-cmd="mysqladmin ping -h localhost -uroot -proot"
|
--health-cmd="mysqladmin ping -h localhost -uroot -proot"
|
||||||
--health-interval=5s --health-timeout=5s --health-retries=20
|
--health-interval=5s --health-timeout=5s --health-retries=20
|
||||||
env:
|
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
|
SECRET_KEY: ci-secret
|
||||||
JWT_SECRET_KEY: ci-jwt-secret
|
JWT_SECRET_KEY: ci-jwt-secret
|
||||||
steps:
|
steps:
|
||||||
@@ -113,7 +117,7 @@ jobs:
|
|||||||
run: |
|
run: |
|
||||||
.venv/bin/python - <<'PY'
|
.venv/bin/python - <<'PY'
|
||||||
import pymysql
|
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:
|
with c.cursor() as cur:
|
||||||
cur.execute("ALTER DATABASE shopdb_ci CHARACTER SET utf8mb4 "
|
cur.execute("ALTER DATABASE shopdb_ci CHARACTER SET utf8mb4 "
|
||||||
"COLLATE utf8mb4_unicode_ci")
|
"COLLATE utf8mb4_unicode_ci")
|
||||||
|
|||||||
Reference in New Issue
Block a user