| 36 | |
| 37 | |
| 38 | class MySql(Service): |
| 39 | DEFAULT_ROOT_PASSWORD = "p@ssw0rd" |
| 40 | DEFAULT_VERSION = "9.7.0" |
| 41 | |
| 42 | DEFAULT_ADDITIONAL_ARGS = create_mysql_server_args(server_id="1", is_master=True) |
| 43 | |
| 44 | def __init__( |
| 45 | self, |
| 46 | root_password: str = DEFAULT_ROOT_PASSWORD, |
| 47 | name: str = "mysql", |
| 48 | version: str = DEFAULT_VERSION, |
| 49 | port: int = 3306, |
| 50 | volumes: list[str] = ["mydata:/var/lib/mysql-files"], |
| 51 | additional_args: list[str] = DEFAULT_ADDITIONAL_ARGS, |
| 52 | use_seeded_image: bool = True, |
| 53 | ) -> None: |
| 54 | image = f"mysql:{version}" |
| 55 | config: ServiceConfig = { |
| 56 | "init": True, |
| 57 | "ports": [port], |
| 58 | "environment": [ |
| 59 | f"MYSQL_ROOT_PASSWORD={root_password}", |
| 60 | ], |
| 61 | "command": [ |
| 62 | "--secure-file-priv=/var/lib/mysql-files", |
| 63 | *additional_args, |
| 64 | ], |
| 65 | "healthcheck": { |
| 66 | "test": [ |
| 67 | "CMD", |
| 68 | "mysqladmin", |
| 69 | "ping", |
| 70 | f"--password={root_password}", |
| 71 | "--protocol=TCP", |
| 72 | ], |
| 73 | "interval": "1s", |
| 74 | # MySQL can be slow to start up |
| 75 | "start_period": "180s", |
| 76 | }, |
| 77 | "volumes": volumes, |
| 78 | } |
| 79 | |
| 80 | if ( |
| 81 | use_seeded_image |
| 82 | and version == self.DEFAULT_VERSION |
| 83 | and root_password == self.DEFAULT_ROOT_PASSWORD |
| 84 | ): |
| 85 | config["mzbuild"] = "mysql" |
| 86 | else: |
| 87 | config["image"] = image |
| 88 | |
| 89 | super().__init__( |
| 90 | name=name, |
| 91 | config=config, |
| 92 | ) |
no test coverage detected