Skip to content
Open
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
FROM mariadb:10.3

COPY mariadb/init.sh /docker-entrypoint-initdb.d/
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @db260179,

the mariadb image already runs the scripts inserted in /docker-entrypoint-initdb.d/ once, see: https://github.com/docker-library/mariadb/blob/44cfe68144976ce0ec135593ffe15c4bcca0dc6f/10.3/docker-entrypoint.sh#L80.

So you do not need to manually check in the entrypoint.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You are correct, so no need for that change.
I've added a commit to allow the master to confirm to the slave its ready to start. Although you have a 30 second count down it isn't that reliable and relying on the depends_on is not a good method especially on docker swarm

COPY mariadb/init.sh /usr/local/bin/
COPY mariadb/entrypoint.sh /usr/local/bin/master-slave-entrypoint.sh

ENTRYPOINT ["master-slave-entrypoint.sh"]
Expand Down
52 changes: 7 additions & 45 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,10 @@

> MariaDB 10.3 dockerized with replication. Master/Slave setup in 30 seconds.

> Added features for Docker swarm setups

## How to use

### Docker run

@TODO

### Docker compose

Example docker-compose.yml for mariadb replication:
Expand All @@ -18,7 +15,7 @@ version: '3'

services:
db-master:
image: caffeina/mariadb-replication
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @db260179,

why force users to build the image when they can use the one already built?

image: *your docker registry*
restart: always
volumes:
- db-master-data:/var/lib/mysql:rw
Expand All @@ -27,7 +24,7 @@ services:
MYSQL_ROOT_PASSWORD: "mastersecret"

db-slave:
image: caffeina/mariadb-replication
image: *your docker registry*
restart: always
depends_on:
- db-master
Expand All @@ -44,16 +41,14 @@ volumes:
db-slave-data:
```

@TODO

```bash
$ docker-compose up
```

@TODO
# Build and run

```bash
$ docker-compose -f docker-compose.yml -f docker-compose.dev.yml up --build
$ docker-compose -f docker-compose.yml up --build
```


Expand All @@ -63,7 +58,7 @@ The `mariadb-replication` image is an extension of `mariadb:10.3`, you can use a

### Enviroment variables

@TODO Sets the connection parameters to the master. The `MYSQL_MASTER_HOST` variable is required.
Sets the connection parameters to the master (for slave container). The `MYSQL_MASTER_HOST` variable is required.

```yaml
MYSQL_MASTER_HOST: "db-master"
Expand All @@ -72,27 +67,21 @@ MYSQL_MASTER_USER: "root" # (Optional) Default: 'root'
MYSQL_MASTER_PASSWORD: "secret" # (Optional) Default: ''
```

@TODO The generated user and password will be printed to stdout.
The generated user and password will be printed to stdout.

```yaml
MYSQL_GRANT_SLAVE_USER: "user" # (Optional) Default: *RANDOM STRING*
MYSQL_GRANT_SLAVE_PASSWORD: "secret" # (Optional) Default: *RANDOM STRING*
```

@TODO

```yaml
SERVER_ID: 2 # (Optional) Default: *RANDOM INT*
```

@TODO

```yaml
EXPIRE_LOGS_DAYS: 5 # (Optional) Default: '10'
```

@TODO

```yaml
MAX_BINLOG_SIZE: "50M" # (Optional) Default: '100M'
```
Expand All @@ -109,30 +98,3 @@ MYSQL_SLAVE_SKIP_ERRORS: "all" # (Optional) Default: 'OFF'
- Add `innodb-read-only` parameter (Service restart on first run is needed);
- Move `/etc/mysql/conf.d/master-slave.cnf` in other path (So the user can bind a volume to `/etc/mysql/conf.d/` for custom configuration);
- Permit replication on existing database.


## Contributing
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @db260179,

please leave this section in README file.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are yes, sorry didn't realise I took it out


How to get involved:

1. [Star](https://github.com/gadiener/docker-mariadb-replication/stargazers) the project!
2. Answer questions that come through [GitHub issues](https://github.com/gadiener/docker-mariadb-replication/issues?state=open)
3. [Report a bug](https://github.com/gadiener/docker-mariadb-replication/issues/new) that you find

This project follows the [GitFlow branching model](http://nvie.com/posts/a-successful-git-branching-model). The ```master``` branch always reflects a production-ready state while the latest development is taking place in the ```develop``` branch.

Each time you want to work on a fix or a new feature, create a new branch based on the ```develop``` branch: ```git checkout -b BRANCH_NAME develop```. Only pull requests to the ```develop``` branch will be merged.

Pull requests are **highly appreciated**.

Solve a problem. Features are great, but even better is cleaning-up and fixing issues in the code that you discover.


## Versioning

This project is maintained by using the [Semantic Versioning Specification (SemVer)](http://semver.org).


## Copyright and license

Copyright 2017 [Caffeina](http://caffeina.com) srl under the [MIT license](LICENSE.md).
10 changes: 0 additions & 10 deletions docker-compose.dev.yml

This file was deleted.

9 changes: 8 additions & 1 deletion mariadb/entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -129,4 +129,11 @@ if [ "$1" = 'mysqld' -a -z "$wantHelp" ]; then
fi
fi

docker-entrypoint.sh $@
# Check if init.sh has been added and add status folder
if [ ! -e "/docker-entrypoint-initdb.d/init.sh" ]; then
cp -f /usr/local/bin/init.sh /docker-entrypoint-initdb.d
chown mysql:mysql /status
chown mysql:mysql /docker-entrypoint-initdb.d/*
fi

docker-entrypoint.sh $@
21 changes: 15 additions & 6 deletions mariadb/init.sh
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ if [ ! -z "$MYSQL_MASTER_HOST" ]; then
sleep 1
done

if [ ! -z "$MYSQL_GRANT_SLAVE_USER" -a ! -z "$MYSQL_GRANT_SLAVE_PASSWORD" ]; then
if [ -z "$MYSQL_GRANT_SLAVE_USER" ] || [ -z "$MYSQL_GRANT_SLAVE_PASSWORD" ]; then
export MYSQL_GRANT_SLAVE_USER="$(pwgen -1 16)"
echo "GENERATED SLAVE USER: $MYSQL_GRANT_SLAVE_USER"

Expand All @@ -73,20 +73,29 @@ if [ ! -z "$MYSQL_MASTER_HOST" ]; then
"${master_mysql[@]}" <<-EOSQL
GRANT REPLICATION SLAVE ON *.* TO '$MYSQL_GRANT_SLAVE_USER'@'%' IDENTIFIED BY '$MYSQL_GRANT_SLAVE_PASSWORD';
FLUSH PRIVILEGES;
EOSQL
EOSQL

fi

# If the user sets these then just run the SQL grant for replicaton user
if [ ! -z "$MYSQL_GRANT_SLAVE_USER" ] || [ ! -z "$MYSQL_GRANT_SLAVE_PASSWORD" ]; then

"${master_mysql[@]}" <<-EOSQL
GRANT REPLICATION SLAVE ON *.* TO '$MYSQL_GRANT_SLAVE_USER'@'%' IDENTIFIED BY '$MYSQL_GRANT_SLAVE_PASSWORD';
FLUSH PRIVILEGES;
EOSQL
fi

"${master_mysql[@]}" <<-EOSQL > $MYSQL_STATUS 2>&1
FLUSH TABLES WITH READ LOCK;
SHOW MASTER STATUS;
EOSQL
EOSQL

"${master_mysqldump[@]}" > $MYSQL_EXPORT 2>&1

"${master_mysql[@]}" <<-EOSQL
UNLOCK TABLES;
EOSQL
EOSQL

## SLAVE

Expand Down Expand Up @@ -120,7 +129,7 @@ if [ ! -z "$MYSQL_MASTER_HOST" ]; then
MASTER_CONNECT_RETRY=$MYSQL_MASTER_CONNECT_RETRY;
START SLAVE;
SHOW SLAVE STATUS\G
EOSQL
EOSQL

if [ -e "$MYSQL_STATUS" ]; then
rm -f $MYSQL_STATUS
Expand Down Expand Up @@ -151,7 +160,7 @@ else

"${master_mysql[@]}" <<-EOSQL
SHOW MASTER STATUS\G
EOSQL
EOSQL

echo
echo 'MySQL master process done. Ready for replication.'
Expand Down