Skip to content

Refactor/docker compose anchors #449

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

68 changes: 51 additions & 17 deletions docker-compose-test.yml
Original file line number Diff line number Diff line change
@@ -1,26 +1,56 @@
version: '3.2'
version: '3.4'

x-mysql: &mysql
environment:
MYSQL_ALLOW_EMPTY_PASSWORD: true
command: >
mysqld
--log-bin=mysql-bin.log
--server-id 1
--binlog-format=row
--gtid_mode=on
--enforce-gtid-consistency=on

x-mariadb: &mariadb
environment:
MARIADB_ALLOW_EMPTY_ROOT_PASSWORD: 1
command: >
--server-id=1
--default-authentication-plugin=mysql_native_password
--log-bin=master-bin
--binlog-format=row

services:
percona-5.7:
platform: linux/amd64
percona-5.7-ctl:
<<: *mysql
image: percona:5.7
environment:
MYSQL_ALLOW_EMPTY_PASSWORD: true
MYSQL_DATABASE: pymysqlreplication_test
ports:
- 3306:3306
command: mysqld --log-bin=mysql-bin.log --server-id 1 --binlog-format=row --gtid_mode=on --enforce-gtid-consistency=on --log_slave_updates
restart: always
- "3307:3306"
networks:
- default

percona-5.7-ctl:
percona-5.7:
<<: *mysql
image: percona:5.7
environment:
MYSQL_ALLOW_EMPTY_PASSWORD: true
MYSQL_DATABASE: pymysqlreplication_test
ports:
- 3307:3307
command: mysqld --log-bin=mysql-bin.log --server-id 1 --binlog-format=row --gtid_mode=on --enforce-gtid-consistency=on --log_slave_updates -P 3307
- "3306:3306"
networks:
- default

mariadb-10.6:
<<: *mariadb
image: mariadb:10.6
ports:
- "3308:3306"
volumes:
- type: bind
source: ./.mariadb
target: /opt/key_file
- type: bind
source: ./.mariadb/my.cnf
target: /etc/mysql/my.cnf
networks:
- default

pymysqlreplication:
build:
Expand All @@ -30,6 +60,9 @@ services:
BASE_IMAGE: python:3.11-alpine
MYSQL_5_7: percona-5.7
MYSQL_5_7_CTL: percona-5.7-ctl
MYSQL_5_7_CTL_PORT: 3306
MARIADB_10_6: mariadb-10.6
MARIADB_10_6_PORT: 3306

command:
- /bin/sh
Expand All @@ -39,7 +72,7 @@ services:

while :
do
if mysql -h percona-5.7 --user=root --execute "USE pymysqlreplication_test;" 2>&1 >/dev/null && mysql -h percona-5.7-ctl --port=3307 --user=root --execute "USE pymysqlreplication_test;" 2>&1 >/dev/null; then
if mysql -h percona-5.7 --user=root --execute "SELECT version();" 2>&1 >/dev/null && mysql -h percona-5.7-ctl --user=root --execute "SELECT version();" 2>&1 >/dev/null; then
break
fi
sleep 1
Expand All @@ -56,4 +89,5 @@ services:
- percona-5.7-ctl

networks:
default: {}
default:
driver: bridge
46 changes: 28 additions & 18 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -1,37 +1,47 @@
version: '3.2'
version: '3.4'

x-mysql: &mysql
environment:
MYSQL_ALLOW_EMPTY_PASSWORD: true
command: >
mysqld
--log-bin=mysql-bin.log
--server-id 1
--binlog-format=row
--gtid_mode=on
--enforce-gtid-consistency=on

x-mariadb: &mariadb
environment:
MARIADB_ALLOW_EMPTY_ROOT_PASSWORD: 1
command: >
--log-bin=master-bin
--server-id=1
--default-authentication-plugin=mysql_native_password
--binlog-format=row

services:
percona-5.7:
<<: *mysql
image: percona:5.7
environment:
MYSQL_ALLOW_EMPTY_PASSWORD: true
ports:
- 3306:3306
command: mysqld --log-bin=mysql-bin.log --server-id 1 --binlog-format=row --gtid_mode=on --enforce-gtid-consistency=on --log_slave_updates
- "3306:3306"

percona-5.7-ctl:
<<: *mysql
image: percona:5.7
environment:
MYSQL_ALLOW_EMPTY_PASSWORD: true
ports:
- 3307:3307
command: mysqld --log-bin=mysql-bin.log --server-id 1 --binlog-format=row --gtid_mode=on --enforce-gtid-consistency=on --log_slave_updates -P 3307
- "3307:3306"

mariadb-10.6:
<<: *mariadb
image: mariadb:10.6
environment:
MARIADB_ALLOW_EMPTY_ROOT_PASSWORD: 1
ports:
- "3308:3306"
command: |
--server-id=1
--default-authentication-plugin=mysql_native_password
--log-bin=master-bin
--binlog-format=row
--log-slave-updates=on
volumes:
- type: bind
source: ./.mariadb
target: /opt/key_file
- type: bind
source: ./.mariadb/my.cnf
target: /etc/mysql/my.cnf
target: /etc/mysql/my.cnf
4 changes: 2 additions & 2 deletions pymysqlreplication/tests/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -125,10 +125,10 @@ class PyMySQLReplicationMariaDbTestCase(PyMySQLReplicationTestCase):
def setUp(self):
# default
self.database = {
"host": "localhost",
"host": os.environ.get("MARIADB_10_6") or "localhost",
"user": "root",
"passwd": "",
"port": 3308,
"port": int(os.environ.get("MARIADB_10_6_PORT") or 3308),
"use_unicode": True,
"charset": "utf8",
"db": "pymysqlreplication_test"
Expand Down
5 changes: 2 additions & 3 deletions pymysqlreplication/tests/test_basic.py
Original file line number Diff line number Diff line change
Expand Up @@ -771,9 +771,8 @@ def setUp(self):
self.stream.close()
ctl_db = copy.copy(self.database)
ctl_db["db"] = None
ctl_db["port"] = 3307
if os.environ.get("MYSQL_5_7_CTL") is not None:
ctl_db["host"] = os.environ.get("MYSQL_5_7_CTL")
ctl_db["port"] = int(os.environ.get("MYSQL_5_7_CTL_PORT") or 3307)
ctl_db["host"] = os.environ.get("MYSQL_5_7_CTL") or "localhost"
self.ctl_conn_control = pymysql.connect(**ctl_db)
self.ctl_conn_control.cursor().execute("DROP DATABASE IF EXISTS pymysqlreplication_test")
self.ctl_conn_control.cursor().execute("CREATE DATABASE pymysqlreplication_test")
Expand Down
12 changes: 11 additions & 1 deletion test.Dockerfile
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
ARG BASE_IMAGE=${BASE_IMAGE:-python:3.11-alpine}
FROM ${BASE_IMAGE}

COPY .mariadb .mariadb
COPY pymysqlreplication pymysqlreplication
COPY README.md README.md
COPY setup.py setup.py
Expand All @@ -13,4 +14,13 @@ ARG MYSQL_5_7
ENV MYSQL_5_7 ${MYSQL_5_7}

ARG MYSQL_5_7_CTL
ENV MYSQL_5_7_CTL ${MYSQL_5_7_CTL}
ENV MYSQL_5_7_CTL ${MYSQL_5_7_CTL}

ARG MYSQL_5_7_CTL_PORT
ENV MYSQL_5_7_CTL_PORT ${MYSQL_5_7_CTL_PORT}

ARG MARIADB_10_6
ENV MARIADB_10_6 ${MARIADB_10_6}

ARG MARIADB_10_6_PORT
ENV MARIADB_10_6_PORT ${MARIADB_10_6_PORT}