Skip to content

Commit 1dbd5e9

Browse files
committed
configure custom socket path for mysql container, working around implicitly created volume folders being owned by root
we should probably just not use service containers for this to avoid having to do this patching
1 parent 163a791 commit 1dbd5e9

File tree

3 files changed

+24
-6
lines changed

3 files changed

+24
-6
lines changed

.github/workflows/ci.yml

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ jobs:
5050
ports:
5151
- 3306:3306
5252
volumes:
53-
- "/tmp/run-${{ join(matrix.db, '-') }}/:/run/mysqld/"
53+
- "/tmp/run-${{ join(matrix.db, '-') }}/:/socket-mount/"
5454
options: '--name=mysqld'
5555
env:
5656
MYSQL_ROOT_PASSWORD: rootpw
@@ -106,6 +106,19 @@ jobs:
106106
docker container stop mysqld
107107
docker container cp "${{ github.workspace }}/tests/ssl_resources/ssl" mysqld:/etc/mysql/ssl
108108
docker container cp "${{ github.workspace }}/tests/ssl_resources/tls.cnf" mysqld:/etc/mysql/conf.d/aiomysql-tls.cnf
109+
110+
# use custom socket path
111+
# we need to ensure that the socket path is writable for the user running the DB process in the container
112+
sudo chmod 0777 /tmp/run-${{ join(matrix.db, '-') }}
113+
114+
# mysql 5.7 container overrides the socket path in /etc/mysql/mysql.conf.d/mysqld.cnf
115+
if [ "${{ join(matrix.db, '-') }}" = "mysql-5.7" ]
116+
then
117+
docker container cp "${{ github.workspace }}/tests/ssl_resources/socket.cnf" mysqld:/etc/mysql/mysql.conf.d/zz-aiomysql-socket.cnf
118+
else
119+
docker container cp "${{ github.workspace }}/tests/ssl_resources/socket.cnf" mysqld:/etc/mysql/conf.d/aiomysql-socket.cnf
120+
fi
121+
109122
docker container start mysqld
110123
111124
# ensure server is started up
@@ -121,7 +134,7 @@ jobs:
121134
run: |
122135
# timeout ensures a more or less clean stop by sending a KeyboardInterrupt which will still provide useful logs
123136
timeout --preserve-status --signal=INT --verbose 5m \
124-
pytest --color=yes --capture=no --verbosity 2 --cov-report term --cov-report xml --cov aiomysql ./tests --mysql-unix-socket "${{ join(matrix.db, '') }}=/tmp/run-${{ join(matrix.db, '-') }}/mysql.sock" --mysql-address "${{ join(matrix.db, '') }}=127.0.0.1:3306"
137+
pytest --color=yes --capture=no --verbosity 2 --cov-report term --cov-report xml --cov aiomysql ./tests --mysql-unix-socket "unix-${{ join(matrix.db, '') }}=/tmp/run-${{ join(matrix.db, '-') }}/mysql.sock" --mysql-address "tcp-${{ join(matrix.db, '') }}=127.0.0.1:3306"
125138
env:
126139
PYTHONUNBUFFERED: 1
127140
DB: '${{ matrix.db[0] }}'

tests/conftest.py

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -40,29 +40,32 @@ def pytest_generate_tests(metafunc):
4040
ids.append(label)
4141
else:
4242
mysql_addresses.append(opt_mysql_unix_socket[i])
43-
ids.append("socket{}".format(i))
43+
ids.append("unix{}".format(i))
4444

4545
opt_mysql_address = list(metafunc.config.getoption("mysql_address"))
4646
for i in range(len(opt_mysql_address)):
4747
if "=" in opt_mysql_address[i]:
48-
label, addr = opt_mysql_unix_socket[i].rsplit("=", 1)
48+
label, addr = opt_mysql_address[i].rsplit("=", 1)
4949
ids.append(label)
5050
else:
5151
addr = opt_mysql_address[i]
52-
ids.append("socket{}".format(i))
52+
ids.append("tcp{}".format(i))
5353

5454
if ":" in addr:
5555
addr = addr.rsplit(":", 1)
5656
mysql_addresses.append((addr[0], int(addr[1])))
5757
else:
5858
mysql_addresses.append((addr, 3306))
59-
ids.append("address{}".format(i))
6059

6160
# default to connecting to localhost
6261
if len(mysql_addresses) == 0:
6362
mysql_addresses = [("127.0.0.1", 3306)]
6463
ids = ["tcp-local"]
6564

65+
assert len(mysql_addresses) == len(set(mysql_addresses))
66+
assert len(ids) == len(set(ids))
67+
assert len(mysql_addresses) == len(ids)
68+
6669
metafunc.parametrize("mysql_address",
6770
mysql_addresses,
6871
ids=ids,

tests/ssl_resources/socket.cnf

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
[mysqld]
2+
socket = /socket-mount/mysql.sock

0 commit comments

Comments
 (0)