Skip to content

Commit

Permalink
configure custom socket path for mysql container, working around impl…
Browse files Browse the repository at this point in the history
…icitly created volume folders being owned by root

we should probably just not use service containers for this to avoid having to do this patching
  • Loading branch information
Nothing4You committed Jan 28, 2022
1 parent 163a791 commit 1dbd5e9
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 6 deletions.
17 changes: 15 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ jobs:
ports:
- 3306:3306
volumes:
- "/tmp/run-${{ join(matrix.db, '-') }}/:/run/mysqld/"
- "/tmp/run-${{ join(matrix.db, '-') }}/:/socket-mount/"
options: '--name=mysqld'
env:
MYSQL_ROOT_PASSWORD: rootpw
Expand Down Expand Up @@ -106,6 +106,19 @@ jobs:
docker container stop mysqld
docker container cp "${{ github.workspace }}/tests/ssl_resources/ssl" mysqld:/etc/mysql/ssl
docker container cp "${{ github.workspace }}/tests/ssl_resources/tls.cnf" mysqld:/etc/mysql/conf.d/aiomysql-tls.cnf
# use custom socket path
# we need to ensure that the socket path is writable for the user running the DB process in the container
sudo chmod 0777 /tmp/run-${{ join(matrix.db, '-') }}
# mysql 5.7 container overrides the socket path in /etc/mysql/mysql.conf.d/mysqld.cnf
if [ "${{ join(matrix.db, '-') }}" = "mysql-5.7" ]
then
docker container cp "${{ github.workspace }}/tests/ssl_resources/socket.cnf" mysqld:/etc/mysql/mysql.conf.d/zz-aiomysql-socket.cnf
else
docker container cp "${{ github.workspace }}/tests/ssl_resources/socket.cnf" mysqld:/etc/mysql/conf.d/aiomysql-socket.cnf
fi
docker container start mysqld
# ensure server is started up
Expand All @@ -121,7 +134,7 @@ jobs:
run: |
# timeout ensures a more or less clean stop by sending a KeyboardInterrupt which will still provide useful logs
timeout --preserve-status --signal=INT --verbose 5m \
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"
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"
env:
PYTHONUNBUFFERED: 1
DB: '${{ matrix.db[0] }}'
Expand Down
11 changes: 7 additions & 4 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,29 +40,32 @@ def pytest_generate_tests(metafunc):
ids.append(label)
else:
mysql_addresses.append(opt_mysql_unix_socket[i])
ids.append("socket{}".format(i))
ids.append("unix{}".format(i))

opt_mysql_address = list(metafunc.config.getoption("mysql_address"))
for i in range(len(opt_mysql_address)):
if "=" in opt_mysql_address[i]:
label, addr = opt_mysql_unix_socket[i].rsplit("=", 1)
label, addr = opt_mysql_address[i].rsplit("=", 1)
ids.append(label)
else:
addr = opt_mysql_address[i]
ids.append("socket{}".format(i))
ids.append("tcp{}".format(i))

if ":" in addr:
addr = addr.rsplit(":", 1)
mysql_addresses.append((addr[0], int(addr[1])))
else:
mysql_addresses.append((addr, 3306))
ids.append("address{}".format(i))

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

assert len(mysql_addresses) == len(set(mysql_addresses))
assert len(ids) == len(set(ids))
assert len(mysql_addresses) == len(ids)

metafunc.parametrize("mysql_address",
mysql_addresses,
ids=ids,
Expand Down
2 changes: 2 additions & 0 deletions tests/ssl_resources/socket.cnf
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
[mysqld]
socket = /socket-mount/mysql.sock

0 comments on commit 1dbd5e9

Please sign in to comment.