mirror of
https://github.com/bitnami/containers.git
synced 2026-03-20 23:10:53 +08:00
Merge pull request #43 from sameersbn/stacksmith-merger
Stacksmith merger
This commit is contained in:
2
bitnami/mariadb/.dockerignore
Normal file
2
bitnami/mariadb/.dockerignore
Normal file
@@ -0,0 +1,2 @@
|
||||
.git/
|
||||
tests/
|
||||
1
bitnami/mariadb/.gitignore
vendored
Normal file
1
bitnami/mariadb/.gitignore
vendored
Normal file
@@ -0,0 +1 @@
|
||||
pkg-cache/
|
||||
@@ -1,20 +1,17 @@
|
||||
FROM bitnami/base-ubuntu:14.04-onbuild
|
||||
FROM gcr.io/stacksmith-images/ubuntu:14.04-r07
|
||||
MAINTAINER Bitnami <containers@bitnami.com>
|
||||
|
||||
ENV BITNAMI_APP_DIR=$BITNAMI_PREFIX/mysql \
|
||||
ENV BITNAMI_IMAGE_VERSION=10.1.13-r0 \
|
||||
BITNAMI_APP_NAME=mariadb \
|
||||
BITNAMI_APP_USER=mysql \
|
||||
BITNAMI_APP_DAEMON=mysqld.bin \
|
||||
BITNAMI_APP_VERSION=5.5.48-0-r01
|
||||
BITNAMI_APP_USER=mysql
|
||||
|
||||
ENV BITNAMI_APP_VOL_PREFIX=/bitnami/$BITNAMI_APP_NAME \
|
||||
PATH=$BITNAMI_APP_DIR/bin:$PATH
|
||||
|
||||
RUN $BITNAMI_PREFIX/install.sh\
|
||||
--base_password bitnami --mysql_password bitnami --mysql_allow_all_remote_connections 1 --disable-components common --mysql_init_data_dir 0
|
||||
RUN bitnami-pkg unpack mariadb-10.1.13-5 --checksum 6b463bf13e4e07d7fcae55d9ccafcfd5cab3dd183db13687fac753c35417d154
|
||||
ENV PATH=/opt/bitnami/$BITNAMI_APP_NAME/sbin:/opt/bitnami/$BITNAMI_APP_NAME/bin:$PATH
|
||||
|
||||
COPY rootfs/ /
|
||||
ENTRYPOINT ["/app-entrypoint.sh"]
|
||||
CMD ["harpoon", "start", "--foreground", "mariadb"]
|
||||
|
||||
VOLUME ["/bitnami/$BITNAMI_APP_NAME"]
|
||||
|
||||
EXPOSE 3306
|
||||
VOLUME ["$BITNAMI_APP_VOL_PREFIX/data", "$BITNAMI_APP_VOL_PREFIX/conf", "$BITNAMI_APP_VOL_PREFIX/logs"]
|
||||
ENTRYPOINT ["/entrypoint.sh"]
|
||||
|
||||
@@ -2,23 +2,21 @@
|
||||
|
||||
# What is MariaDB?
|
||||
|
||||
> MariaDB is a fast, reliable, scalable, and easy to use open-source relational database system.
|
||||
> MariaDB Server is intended for mission-critical, heavy-load production systems as well as for
|
||||
> embedding into mass-deployed software.
|
||||
> MariaDB is a fast, reliable, scalable, and easy to use open-source relational database system. MariaDB Server is intended for mission-critical, heavy-load production systems as well as for embedding into mass-deployed software.
|
||||
|
||||
[https://mariadb.com/](https://mariadb.com/)
|
||||
|
||||
# TLDR
|
||||
|
||||
```bash
|
||||
docker run --name mariadb bitnami/mariadb
|
||||
docker run --name mariadb bitnami/mariadb:latest
|
||||
```
|
||||
|
||||
## Docker Compose
|
||||
|
||||
```
|
||||
mariadb:
|
||||
image: bitnami/mariadb
|
||||
image: bitnami/mariadb:latest
|
||||
```
|
||||
|
||||
# Get this image
|
||||
@@ -40,45 +38,35 @@ docker pull bitnami/mariadb:[TAG]
|
||||
If you wish, you can also build the image yourself.
|
||||
|
||||
```bash
|
||||
git clone https://github.com/bitnami/bitnami-docker-mariadb.git
|
||||
cd bitnami-docker-mariadb
|
||||
docker build -t bitnami/mariadb .
|
||||
docker build -t bitnami/mariadb:latest https://github.com/bitnami/bitnami-docker-mariadb.git
|
||||
```
|
||||
|
||||
# Persisting your database
|
||||
|
||||
If you remove the container all your data will be lost, and the next time you run the image the
|
||||
database will be reinitialized. To avoid this loss of data, you should mount a volume that will
|
||||
persist even after the container is removed.
|
||||
If you remove the container all your data and configurations will be lost, and the next time you run the image the database will be reinitialized. To avoid this loss of data, you should mount a volume that will persist even after the container is removed.
|
||||
|
||||
**Note!**
|
||||
If you have already started using your database, follow the steps on
|
||||
[backing up](#backing-up-your-container) and [restoring](#restoring-a-backup) to pull the data from
|
||||
your running container down to your host.
|
||||
[backing up](#backing-up-your-container) and [restoring](#restoring-a-backup) to pull the data from your running container down to your host.
|
||||
|
||||
The MariaDB image exposes a volume at `/bitnami/mariadb/data`, you can mount a directory from your host to serve as the data store. If the directory you mount is empty, the database will be initialized.
|
||||
|
||||
> **Note**
|
||||
>
|
||||
> Persistent volumes cannot be shared across container instances.
|
||||
The image exposes a volume at `/bitnami/mariadb` for the MariaDB data and configurations. For persistence you can mount a directory at this location from your host. If the mounted directory is empty, it will be initialized on the first run.
|
||||
|
||||
```bash
|
||||
docker run -v /path/to/data:/bitnami/mariadb/data bitnami/mariadb
|
||||
docker run -v /path/to/mariadb:/bitnami/mariadb bitnami/mariadb:latest
|
||||
```
|
||||
|
||||
or using Docker Compose:
|
||||
|
||||
```
|
||||
mariadb:
|
||||
image: bitnami/mariadb
|
||||
image: bitnami/mariadb:latest
|
||||
volumes:
|
||||
- /path/to/data:/bitnami/mariadb/data
|
||||
- /path/to/mariadb:/bitnami/mariadb
|
||||
```
|
||||
|
||||
# Linking
|
||||
|
||||
If you want to connect to your MariaDB server inside another container, you can use the linking
|
||||
system provided by Docker.
|
||||
If you want to connect to your MariaDB server inside another container, you can use the linking system provided by Docker.
|
||||
|
||||
## Connecting a MySQL client container to the MariaDB server container
|
||||
|
||||
@@ -86,35 +74,26 @@ system provided by Docker.
|
||||
|
||||
The first step is to start our MariaDB server.
|
||||
|
||||
Docker's linking system uses container ids or names to reference containers. We can explicitly
|
||||
specify a name for our MariaDB server to make it easier to connect to other containers.
|
||||
Docker's linking system uses container ids or names to reference containers. We can explicitly specify a name for our MariaDB server to make it easier to connect to other containers.
|
||||
|
||||
```bash
|
||||
docker run --name mariadb bitnami/mariadb
|
||||
docker run --name mariadb bitnami/mariadb:latest
|
||||
```
|
||||
|
||||
### Step 2: Run MariaDB as a MySQL client and link to our server
|
||||
|
||||
Now that we have our MariaDB server running, we can create another container that links to it by
|
||||
giving Docker the `--link` option. This option takes the id or name of the container we want to link
|
||||
it to as well as a hostname to use inside the container, separated by a colon. For example, to have
|
||||
our MariaDB server accessible in another container with `server` as it's hostname we would pass
|
||||
`--link mariadb:server` to the Docker run command.
|
||||
Now that we have our MariaDB server running, we can create another container that links to it by giving Docker the `--link` option. This option takes the id or name of the container we want to link it to as well as a hostname to use inside the container, separated by a colon. For example, to have our MariaDB server accessible in another container with `server` as it's hostname we would pass `--link mariadb:server` to the Docker run command.
|
||||
|
||||
The Bitnami MariaDB Docker Image also ships with a MySQL client, but by default it will start a
|
||||
server. To start the client instead, we can override the default command Docker runs by stating a
|
||||
different command to run after the image name.
|
||||
The Bitnami MariaDB Docker Image also ships with a MySQL client. To start the client, we can override the default command Docker runs by stating a different command to run after the image name.
|
||||
|
||||
```bash
|
||||
docker run --rm -it --link mariadb:server bitnami/mariadb mysql -h server -u root
|
||||
docker run --rm -it --link mariadb:server bitnami/mariadb:latest mysql -h server -u root
|
||||
```
|
||||
|
||||
We started the MySQL client passing in the `-h` option that allows us to specify the hostname of the
|
||||
server, which we set to the hostname we created in the link.
|
||||
We started the MySQL client passing in the `-h` option that allows us to specify the hostname of the server, which we set to the hostname we created in the link.
|
||||
|
||||
**Note!**
|
||||
You can also run the MySQL client in the same container the server is running in using the Docker
|
||||
[exec](https://docs.docker.com/reference/commandline/cli/#exec) command.
|
||||
You can also run the MySQL client in the same container the server is running in using the Docker [exec](https://docs.docker.com/reference/commandline/cli/#exec) command.
|
||||
|
||||
```bash
|
||||
docker exec -it mariadb mysql -u root
|
||||
@@ -128,13 +107,12 @@ Copy the snippet below into your `docker-compose.yml` to add MariaDB to your app
|
||||
|
||||
```
|
||||
mariadb:
|
||||
image: bitnami/mariadb
|
||||
image: bitnami/mariadb:latest
|
||||
```
|
||||
|
||||
### Step 2: Link it to another container in your application
|
||||
|
||||
Update the definitions for containers you want to access your MariaDB server from to include a link
|
||||
to the `mariadb` entry you added in Step 1.
|
||||
Update the definitions for containers you want to access your MariaDB server from to include a link to the `mariadb` entry you added in Step 1.
|
||||
|
||||
```
|
||||
myapp:
|
||||
@@ -149,80 +127,77 @@ Inside `myapp`, use `mariadb` as the hostname for the MariaDB server.
|
||||
|
||||
## Setting the root password on first run
|
||||
|
||||
Passing the `MARIADB_PASSWORD` environment variable when running the image for the first time will
|
||||
set the password of the root user to the value of `MARIADB_PASSWORD`.
|
||||
Passing the `MARIADB_ROOT_PASSWORD` environment variable when running the image for the first time will set the password of the root user to the value of `MARIADB_ROOT_PASSWORD`.
|
||||
|
||||
```bash
|
||||
docker run --name mariadb -e MARIADB_PASSWORD=password123 bitnami/mariadb
|
||||
docker run --name mariadb -e MARIADB_ROOT_PASSWORD=password123 bitnami/mariadb:latest
|
||||
```
|
||||
|
||||
or using Docker Compose:
|
||||
|
||||
```
|
||||
mariadb:
|
||||
image: bitnami/mariadb
|
||||
image: bitnami/mariadb:latest
|
||||
environment:
|
||||
- MARIADB_PASSWORD=password123
|
||||
- MARIADB_ROOT_PASSWORD=password123
|
||||
```
|
||||
|
||||
**Warning** The `root` user is always created with remote access. It's suggested that the `MARIADB_ROOT_PASSWORD` env variable is always specified to set a password for the `root` user.
|
||||
|
||||
## Creating a database on first run
|
||||
|
||||
By passing the `MARIADB_DATABASE` environment variable when running the image for the first time, a
|
||||
database will be created. This is useful if your application requires that a database already
|
||||
exists, saving you from having to manually create the database using the MySQL client.
|
||||
By passing the `MARIADB_DATABASE` environment variable when running the image for the first time, a database will be created. This is useful if your application requires that a database already exists, saving you from having to manually create the database using the MySQL client.
|
||||
|
||||
```bash
|
||||
docker run --name mariadb -e MARIADB_DATABASE=my_database bitnami/mariadb
|
||||
docker run --name mariadb -e MARIADB_DATABASE=my_database bitnami/mariadb:latest
|
||||
```
|
||||
|
||||
or using Docker Compose:
|
||||
|
||||
```
|
||||
mariadb:
|
||||
image: bitnami/mariadb
|
||||
image: bitnami/mariadb:latest
|
||||
environment:
|
||||
- MARIADB_DATABASE=my_database
|
||||
```
|
||||
|
||||
## Creating a database user on first run
|
||||
|
||||
You can create a restricted database user that only has permissions for the database created with
|
||||
the [`MARIADB_DATABASE`](#creating-a-database-on-first-run) environment variable. To do this,
|
||||
provide the `MARIADB_USER` environment variable.
|
||||
|
||||
**Warning!** In this case, a root user will not be created, and your restricted user will not have
|
||||
permissions to create a new database.
|
||||
You can create a restricted database user that only has permissions for the database created with the [`MARIADB_DATABASE`](#creating-a-database-on-first-run) environment variable. To do this, provide the `MARIADB_USER` environment variable and to set a password for the database user provide the `MARIADB_PASSWORD` variable.
|
||||
|
||||
```bash
|
||||
docker run --name mariadb -e MARIADB_USER=my_user -e MARIADB_DATABASE=my_database bitnami/mariadb
|
||||
docker run --name mariadb \
|
||||
-e MARIADB_USER=my_user -e MARIADB_PASSWORD=my_password \
|
||||
-e MARIADB_DATABASE=my_database \
|
||||
bitnami/mariadb:latest
|
||||
```
|
||||
|
||||
or using Docker Compose:
|
||||
|
||||
```
|
||||
mariadb:
|
||||
image: bitnami/mariadb
|
||||
image: bitnami/mariadb:latest
|
||||
environment:
|
||||
- MARIADB_USER=my_user
|
||||
- MARIADB_PASSWORD=my_password
|
||||
- MARIADB_DATABASE=my_database
|
||||
```
|
||||
|
||||
**Note!**
|
||||
When `MARIADB_PASSWORD` is specified along with `MARIADB_USER`, the value specified in `MARIADB_PASSWORD` is set as the password of the newly created user specified in `MARIADB_USER`.
|
||||
**Note!** The `root` user will still be created with remote access. Please ensure that you have specified a password for the `root` user using the `MARIADB_ROOT_PASSWORD` env variable.
|
||||
|
||||
## Setting up a replication cluster
|
||||
|
||||
A **zero downtime** MariaDB master-slave [replication](https://dev.mysql.com/doc/refman/5.0/en/replication-howto.html) cluster can easily be setup with the Bitnami MariaDB Docker Image using the following environment variables:
|
||||
A **zero downtime** MariaDB master-slave [replication](https://dev.mysql.com/doc/refman/5.0/en/replication-howto.html) cluster can easily be setup with the Bitnami MariaDB Docker image using the following environment variables:
|
||||
|
||||
- `MARIADB_SERVER_ID`: Unique server identifier (default: random number)
|
||||
- `MARIADB_REPLICATION_MODE`: Replication mode. Possible values `master`/`slave` (default: none).
|
||||
- `MARIADB_REPLICATION_USER`: Replication user. User is created on master on the first boot (default: none).
|
||||
- `MARIADB_REPLICATION_PASSWORD`: Replication users password. Password is set for `MARIADB_REPLICATION_USER` on master on the first boot (default: none).
|
||||
- `MARIADB_MASTER_HOST`: Hostname/IP of replication master (parameter available only on slave).
|
||||
- `MARIADB_MASTER_USER`: User on replication master with access to `MARIADB_DATABASE` (parameter available only on slave).
|
||||
- `MARIADB_MASTER_PASSWORD`: Password of user on replication master with access to `MARIADB_DATABASE` (parameter available only on slave).
|
||||
- `MARIADB_REPLICATION_MODE`: The replication mode. Possible values `master`/`slave`. No defaults.
|
||||
- `MARIADB_REPLICATION_USER`: The replication user created on the master on first run. No defaults.
|
||||
- `MARIADB_REPLICATION_PASSWORD`: The replication users password. No defaults.
|
||||
- `MARIADB_MASTER_HOST`: Hostname/IP of replication master (slave parameter). No defaults.
|
||||
- `MARIABD_MASTER_PORT`: Server port of the replication master (slave parameter). Defaults to `3306`.
|
||||
- `MARIADB_MASTER_USER`: User on replication master with access to `MARIADB_DATABASE` (slave parameter). Defaults to `root`
|
||||
- `MARIADB_MASTER_PASSWORD`: Password of user on replication master with access to `MARIADB_DATABASE` (slave parameter). No defaults.
|
||||
|
||||
In a replication cluster you can have one master and zero or more slaves. With replication writes can occur only on the master while reads can take place on both the master or slaves. For best performance you should limit the reads to the slaves and use the master only for the writes.
|
||||
In a replication cluster you can have one master and zero or more slaves. When replication is enabled the master node is in read-write mode, while the slaves are in read-only mode. For best performance its advisable to limit the reads to the slaves.
|
||||
|
||||
### Step 1: Create the replication master
|
||||
|
||||
@@ -230,17 +205,17 @@ The first step is to start the MariaDB master.
|
||||
|
||||
```bash
|
||||
docker run --name mariadb-master \
|
||||
-e MARIADB_SERVER_ID=1 \
|
||||
-e MARIADB_USER=my_user \
|
||||
-e MARIADB_PASSWORD=my_password \
|
||||
-e MARIADB_DATABASE=my_database \
|
||||
-e MARIADB_ROOT_PASSWORD=root_password \
|
||||
-e MARIADB_REPLICATION_MODE=master \
|
||||
-e MARIADB_REPLICATION_USER=my_repl_user \
|
||||
-e MARIADB_REPLICATION_PASSWORD=my_repl_password \
|
||||
bitnami/mariadb
|
||||
-e MARIADB_USER=my_user \
|
||||
-e MARIADB_PASSWORD=my_password \
|
||||
-e MARIADB_DATABASE=my_database \
|
||||
bitnami/mariadb:latest
|
||||
```
|
||||
|
||||
In this command we are configuring the container as the master using the `MARIADB_REPLICATION_MODE=master` parameter. Using the `MARIADB_REPLICATION_USER` and `MARIADB_REPLICATION_PASSWORD` parameters we are creating a replication user that will be used by the slaves to connect to the master and perform the replication.
|
||||
In the above command the container is configured as the `master` using the `MARIADB_REPLICATION_MODE` parameter. A replication user is specified using the `MARIADB_REPLICATION_USER` and `MARIADB_REPLICATION_PASSWORD` parameters.
|
||||
|
||||
### Step 2: Create the replication slave
|
||||
|
||||
@@ -248,66 +223,54 @@ Next we start a MariaDB slave container.
|
||||
|
||||
```bash
|
||||
docker run --name mariadb-slave --link mariadb-master:master \
|
||||
-e MARIADB_SERVER_ID=2 \
|
||||
-e MARIADB_USER=my_user \
|
||||
-e MARIADB_PASSWORD=my_password \
|
||||
-e MARIADB_DATABASE=my_database \
|
||||
-e MARIADB_ROOT_PASSWORD=root_password \
|
||||
-e MARIADB_REPLICATION_MODE=slave \
|
||||
-e MARIADB_REPLICATION_USER=my_repl_user \
|
||||
-e MARIADB_REPLICATION_PASSWORD=my_repl_password \
|
||||
-e MARIADB_MASTER_HOST=mariadb-master -e MARIADB_MASTER_USER=my_user -e MARIADB_MASTER_PASSWORD=my_password \
|
||||
bitnami/mariadb
|
||||
-e MARIADB_MASTER_HOST=master \
|
||||
-e MARIADB_MASTER_USER=my_user \
|
||||
-e MARIADB_MASTER_PASSWORD=my_password \
|
||||
-e MARIADB_USER=my_user \
|
||||
-e MARIADB_PASSWORD=my_password \
|
||||
-e MARIADB_DATABASE=my_database \
|
||||
bitnami/mariadb:latest
|
||||
```
|
||||
|
||||
In this command we are configuring the container as a slave using the `MARIADB_REPLICATION_MODE=slave` parameter. Before the replication slave is started, the `MARIADB_MASTER_HOST`, `MARIADB_MASTER_USER` and `MARIADB_MASTER_PASSWORD` parameters are used by the slave container to connect to the master and take a dump of the existing data in the database identified by the `MARIADB_DATABASE` paramater. The `MARIADB_REPLICATION_USER` and `MARIADB_REPLICATION_PASSWORD` credentials are used to read the binary replication logs from the master.
|
||||
In the above command the container is configured as a `slave` using the `MARIADB_REPLICATION_MODE` parameter. The `MARIADB_MASTER_HOST`, `MARIADB_MASTER_USER` and `MARIADB_MASTER_PASSWORD` parameters are used by the slave to connect to the master and take a dump of the existing data in the database identified by `MARIADB_DATABASE`. The replication user credentials are specified using the `MARIADB_REPLICATION_USER` and `MARIADB_REPLICATION_PASSWORD` parameters and should be the same as the one specified on the master.
|
||||
|
||||
Using the `master` docker link alias, the Bitnami MariaDB Docker image automatically fetches the replication paramaters from the master container, namely:
|
||||
> **Note**! The cluster only replicates the database specified in the `MARIADB_DATABASE` parameter.
|
||||
|
||||
- `MARIADB_REPLICATION_USER`
|
||||
- `MARIADB_REPLICATION_PASSWORD`
|
||||
- `MARIADB_MASTER_HOST`
|
||||
- `MARIADB_MASTER_USER`
|
||||
- `MARIADB_MASTER_PASSWORD`
|
||||
You now have a two node MariaDB master/slave replication cluster up and running. You can scale the cluster by adding/removing slaves without incurring any downtime.
|
||||
|
||||
Additionally, the following parameters are also fetched in the slave container:
|
||||
|
||||
- `MARIADB_USER`
|
||||
- `MARIADB_PASSWORD`
|
||||
- `MARIADB_DATABASE`
|
||||
|
||||
As a result you can drop all of these parameters from the slave. Since `MARIADB_SERVER_ID` is assigned a random identifier we can drop it as well:
|
||||
|
||||
```bash
|
||||
docker run --name mariadb-slave --link mariadb-master:master \
|
||||
-e MARIADB_REPLICATION_MODE=slave \
|
||||
bitnami/mariadb
|
||||
```
|
||||
|
||||
With these two commands you now have a two node MariaDB master-slave replication cluster up and running. When required you can add more slaves to the cluster without any downtime allowing you to scale the cluster horizontally.
|
||||
|
||||
> **Note**:
|
||||
>
|
||||
> The cluster only replicates the database specified in the `MARIADB_DATABASE` parameter.
|
||||
|
||||
With Docker Compose the master-slave replication can be setup using:
|
||||
With Docker Compose the master/slave replication can be setup using:
|
||||
|
||||
```yaml
|
||||
master:
|
||||
image: bitnami/mariadb
|
||||
image: bitnami/mariadb:latest
|
||||
environment:
|
||||
- MARIADB_USER=my_user
|
||||
- MARIADB_PASSWORD=my_password
|
||||
- MARIADB_DATABASE=my_database
|
||||
- MARIADB_ROOT_PASSWORD=root_password
|
||||
- MARIADB_REPLICATION_MODE=master
|
||||
- MARIADB_REPLICATION_USER=my_repl_user
|
||||
- MARIADB_REPLICATION_PASSWORD=my_repl_password
|
||||
- MARIADB_USER=my_user
|
||||
- MARIADB_PASSWORD=my_password
|
||||
- MARIADB_DATABASE=my_database
|
||||
|
||||
slave:
|
||||
image: bitnami/mariadb
|
||||
image: bitnami/mariadb:latest
|
||||
links:
|
||||
- master:master
|
||||
environment:
|
||||
- MARIADB_ROOT_PASSWORD=root_password
|
||||
- MARIADB_REPLICATION_MODE=slave
|
||||
- MARIADB_REPLICATION_USER=my_repl_user
|
||||
- MARIADB_REPLICATION_PASSWORD=my_repl_password
|
||||
- MARIADB_MASTER_HOST=master
|
||||
- MARIADB_MASTER_USER=my_user
|
||||
- MARIADB_MASTER_PASSWORD=my_password
|
||||
- MARIADB_USER=my_user
|
||||
- MARIADB_PASSWORD=my_password
|
||||
- MARIADB_DATABASE=my_database
|
||||
```
|
||||
|
||||
Scale the number of slaves using:
|
||||
@@ -316,52 +279,29 @@ Scale the number of slaves using:
|
||||
docker-compose scale master=1 slave=3
|
||||
```
|
||||
|
||||
The above command scales up the number of slaves to `3`. You can scale down in the same way.
|
||||
The above command scales up the number of slaves to `3`. You can scale down in the same manner.
|
||||
|
||||
> **Note**: You should not scale up/down the number of master nodes. Always have only one master node running.
|
||||
|
||||
## Command-line options
|
||||
|
||||
The simplest way to configure your MariaDB server is to pass custom command-line options when
|
||||
running the image.
|
||||
|
||||
```bash
|
||||
docker run bitnami/mariadb --open-files-limit=2
|
||||
```
|
||||
|
||||
or using Docker Compose:
|
||||
|
||||
```
|
||||
mariadb:
|
||||
image: bitnami/mariadb
|
||||
command: --open-files-limit=2
|
||||
```
|
||||
|
||||
**Further Reading:**
|
||||
|
||||
- [MySQL Server Command Options](https://dev.mysql.com/doc/refman/5.1/en/server-options.html)
|
||||
- [Caveats](#caveats)
|
||||
|
||||
## Configuration file
|
||||
|
||||
This image looks for configuration in `/bitnami/mariadb/conf`. You can mount a volume there with
|
||||
your own configuration, or the default configuration will be copied to your volume if it is empty.
|
||||
The image looks for configuration in the `conf/` directory of `/bitnami/mariadb`. As as mentioned in [Persisting your database](#persisting-your-data) you can mount a volume at this location and copy your own configurations in the `conf/` directory. The default configuration will be copied to the `conf/` directory if it's empty.
|
||||
|
||||
### Step 1: Run the MariaDB image
|
||||
|
||||
Run the MariaDB image, mounting a directory from your host.
|
||||
|
||||
```bash
|
||||
docker run --name mariadb -v /path/to/mariadb/conf:/bitnami/mariadb/conf bitnami/mariadb
|
||||
docker run --name mariadb -v /path/to/mariadb:/bitnami/mariadb bitnami/mariadb:latest
|
||||
```
|
||||
|
||||
or using Docker Compose:
|
||||
|
||||
```
|
||||
mariadb:
|
||||
image: bitnami/mariadb
|
||||
image: bitnami/mariadb:latest
|
||||
volumes:
|
||||
- /path/to/mariadb/conf:/bitnami/mariadb/conf
|
||||
- /path/to/mariadb:/bitnami/mariadb
|
||||
```
|
||||
|
||||
### Step 2: Edit the configuration
|
||||
@@ -389,31 +329,10 @@ docker-compose restart mariadb
|
||||
**Further Reading:**
|
||||
|
||||
- [Server Option and Variable Reference](https://dev.mysql.com/doc/refman/5.1/en/mysqld-option-tables.html)
|
||||
- [Caveats](#caveats)
|
||||
|
||||
## Caveats
|
||||
|
||||
The following options cannot be modified, to ensure that the image runs correctly.
|
||||
|
||||
```bash
|
||||
--defaults-file=/opt/bitnami/mysql/my.cnf
|
||||
--log-error=/opt/bitnami/mysql/logs/mysqld.log
|
||||
--basedir=/opt/bitnami/mysql
|
||||
--datadir=/opt/bitnami/mysql/data
|
||||
--plugin-dir=/opt/bitnami/mysql/lib/plugin
|
||||
--user=mysql
|
||||
--socket=/opt/bitnami/mysql/tmp/mysql.sock
|
||||
```
|
||||
|
||||
# Logging
|
||||
|
||||
The Bitnami MariaDB Docker Image supports two different logging modes: logging to stdout, and
|
||||
logging to a file.
|
||||
|
||||
## Logging to stdout
|
||||
|
||||
The default behavior is to log to stdout, as Docker expects. These will be collected by Docker,
|
||||
converted to JSON and stored in the host, to be accessible via the `docker logs` command.
|
||||
The Bitnami MariaDB Docker image sends the container logs to the `stdout`. To view the logs:
|
||||
|
||||
```bash
|
||||
docker logs mariadb
|
||||
@@ -425,30 +344,7 @@ or using Docker Compose:
|
||||
docker-compose logs mariadb
|
||||
```
|
||||
|
||||
This method of logging has the downside of not being easy to manage. Without an easy way to rotate
|
||||
logs, they could grow exponentially and take up large amounts of disk space on your host.
|
||||
|
||||
## Logging to file
|
||||
|
||||
To log to file, run the MariaDB image, mounting a directory from your host at
|
||||
`/bitnami/mariadb/logs`. This will instruct the container to send logs to a `mysqld.log` file in the
|
||||
mounted volume.
|
||||
|
||||
```bash
|
||||
docker run --name mariadb -v /path/to/mariadb/logs:/bitnami/mariadb/logs bitnami/mariadb
|
||||
```
|
||||
|
||||
or using Docker Compose:
|
||||
|
||||
```
|
||||
mariadb:
|
||||
image: bitnami/mariadb
|
||||
volumes:
|
||||
- /path/to/mariadb/logs:/bitnami/mariadb/logs
|
||||
```
|
||||
|
||||
To perform operations (e.g. logrotate) on the logs, mount the same directory in a container designed
|
||||
to operate on log files, such as logstash.
|
||||
You can configure the containers [logging driver](https://docs.docker.com/engine/admin/logging/overview/) using the `--log-driver` option if you wish to consume the container logs differently. In the default configuration docker uses the `json-file` driver.
|
||||
|
||||
# Maintenance
|
||||
|
||||
@@ -470,52 +366,40 @@ docker-compose stop mariadb
|
||||
|
||||
### Step 2: Run the backup command
|
||||
|
||||
We need to mount two volumes in a container we will use to create the backup: a directory on your
|
||||
host to store the backup in, and the volumes from the container we just stopped so we can access the
|
||||
data.
|
||||
We need to mount two volumes in a container we will use to create the backup: a directory on your host to store the backup in, and the volumes from the container we just stopped so we can access the data.
|
||||
|
||||
```bash
|
||||
docker run --rm -v /path/to/backups:/backups --volumes-from mariadb busybox \
|
||||
cp -a /bitnami/mariadb /backups/latest
|
||||
cp -a /bitnami/mariadb:latest /backups/latest
|
||||
```
|
||||
|
||||
or using Docker Compose:
|
||||
|
||||
```bash
|
||||
docker run --rm -v /path/to/backups:/backups --volumes-from `docker-compose ps -q mariadb` busybox \
|
||||
cp -a /bitnami/mariadb /backups/latest
|
||||
cp -a /bitnami/mariadb:latest /backups/latest
|
||||
```
|
||||
|
||||
**Note!**
|
||||
If you only need to backup database data, or configuration, you can change the first argument to
|
||||
`cp` to `/bitnami/mariadb/data` or `/bitnami/mariadb/conf` respectively.
|
||||
|
||||
## Restoring a backup
|
||||
|
||||
Restoring a backup is as simple as mounting the backup as volumes in the container.
|
||||
|
||||
```bash
|
||||
docker run -v /path/to/backups/latest/data:/bitnami/mariadb/data \
|
||||
-v /path/to/backups/latest/conf:/bitnami/mariadb/conf \
|
||||
-v /path/to/backups/latest/logs:/bitnami/mariadb/logs \
|
||||
bitnami/mariadb
|
||||
docker run -v /path/to/backups/latest:/bitnami/mariadb bitnami/mariadb:latest
|
||||
```
|
||||
|
||||
or using Docker Compose:
|
||||
|
||||
```
|
||||
mariadb:
|
||||
image: bitnami/mariadb
|
||||
image: bitnami/mariadb:latest
|
||||
volumes:
|
||||
- /path/to/backups/latest/data:/bitnami/mariadb/data
|
||||
- /path/to/backups/latest/conf:/bitnami/mariadb/conf
|
||||
- /path/to/backups/latest/logs:/bitnami/mariadb/logs
|
||||
- /path/to/backups/latest:/bitnami/mariadb
|
||||
```
|
||||
|
||||
## Upgrade this image
|
||||
|
||||
Bitnami provides up-to-date versions of MariaDB, including security patches, soon after they are
|
||||
made upstream. We recommend that you follow these steps to upgrade your container.
|
||||
Bitnami provides up-to-date versions of MariaDB, including security patches, soon after they are made upstream. We recommend that you follow these steps to upgrade your container.
|
||||
|
||||
### Step 1: Get the updated image
|
||||
|
||||
@@ -546,8 +430,7 @@ docker-compose rm -v mariadb
|
||||
|
||||
### Step 4: Run the new image
|
||||
|
||||
Re-create your container from the new image, [restoring your backup](#restoring-a-backup) if
|
||||
necessary.
|
||||
Re-create your container from the new image, [restoring your backup](#restoring-a-backup) if necessary.
|
||||
|
||||
```bash
|
||||
docker run --name mariadb bitnami/mariadb:latest
|
||||
@@ -561,32 +444,32 @@ docker-compose start mariadb
|
||||
|
||||
# Testing
|
||||
|
||||
This image is tested for expected runtime behavior, using the
|
||||
[Bats](https://github.com/sstephenson/bats) testing framework. You can run the tests on your machine
|
||||
using the `bats` command.
|
||||
This image is tested for expected runtime behavior, using the [Bats](https://github.com/sstephenson/bats) testing framework. You can run the tests on your machine using the `bats` command.
|
||||
|
||||
```
|
||||
bats test.sh
|
||||
```
|
||||
|
||||
# Notable Changes
|
||||
|
||||
## 10.1.13-r1
|
||||
|
||||
- All volumes have been merged at `/bitnami/mariadb`. Now you only need to mount a single volume at `/bitnami/mariadb` for persistence.
|
||||
- The logs are always sent to the `stdout` and are no longer collected in the volume.
|
||||
|
||||
# Contributing
|
||||
|
||||
We'd love for you to contribute to this container. You can request new features by creating an
|
||||
[issue](https://github.com/bitnami/bitnami-docker-mariadb/issues), or submit a
|
||||
[pull request](https://github.com/bitnami/bitnami-docker-mariadb/pulls) with your contribution.
|
||||
We'd love for you to contribute to this container. You can request new features by creating an [issue](https://github.com/bitnami/bitnami-docker-mariadb/issues), or submit a [pull request](https://github.com/bitnami/bitnami-docker-mariadb/pulls) with your contribution.
|
||||
|
||||
# Issues
|
||||
|
||||
If you encountered a problem running this container, you can file an
|
||||
[issue](https://github.com/bitnami/bitnami-docker-mariadb/issues). For us to provide better support,
|
||||
be sure to include the following information in your issue:
|
||||
If you encountered a problem running this container, you can file an [issue](https://github.com/bitnami/bitnami-docker-mariadb/issues). For us to provide better support, be sure to include the following information in your issue:
|
||||
|
||||
- Host OS and version
|
||||
- Docker version (`docker version`)
|
||||
- Output of `docker info`
|
||||
- Version of this container (`echo $BITNAMI_APP_VERSION` inside the container)
|
||||
- The command you used to run the container, and any relevant output you saw (masking any sensitive
|
||||
information)
|
||||
- The command you used to run the container, and any relevant output you saw (masking any sensitive information)
|
||||
|
||||
# License
|
||||
|
||||
|
||||
@@ -1,34 +0,0 @@
|
||||
$BITNAMI_APP_NAME cheatsheet:
|
||||
|
||||
ENVIRONMENT VARIABLES:
|
||||
MARIADB_USER: User to be created on first boot (default: root).
|
||||
MARIADB_PASSWORD: Password to be set for MARIADB_USER on first boot (default: none).
|
||||
MARIADB_DATABASE: Database to be created on first boot, accessible by MARIADB_USER (default: none).
|
||||
MARIADB_SERVER_ID: Unique server identifier (default: random number)
|
||||
MARIADB_REPLICATION_MODE: Replication mode. Possible values master/slave (default: none).
|
||||
MARIADB_REPLICATION_USER: Replication user. User is created on master on the first boot (default: none).
|
||||
MARIADB_REPLICATION_PASSWORD: Replication users password. Password is set for MARIADB_REPLICATION_USER on master on the first boot (default: none).
|
||||
MARIADB_MASTER_HOST: Replication masters hostname/ip (parameter available only on slave).
|
||||
MARIADB_MASTER_USER: User on replication master with access to MARIADB_DATABASE. (default: root, parameter available only on slave).
|
||||
MARIADB_MASTER_PASSWORD: Password of user on replication master with access to MARIADB_DATABASE (parameter available only on slave).
|
||||
|
||||
VOLUMES:
|
||||
$BITNAMI_APP_VOL_PREFIX/data: Location of $BITNAMI_APP_NAME data files.
|
||||
$BITNAMI_APP_VOL_PREFIX/conf: Location of my.cnf ($BITNAMI_APP_NAME config file).
|
||||
$BITNAMI_APP_VOL_PREFIX/logs: Location of mysqld.log.
|
||||
|
||||
PORTS:
|
||||
3306: $BITNAMI_APP_NAME default port.
|
||||
|
||||
MISC:
|
||||
Options: You can add extra options during the docker run using the -- prefix.
|
||||
Note: MARIADB_USER works in conjunction with MARIADB_DATABASE environment variable.
|
||||
Tip: Back up the $BITNAMI_APP_VOL_PREFIX/data and $BITNAMI_APP_VOL_PREFIX/conf directories regularly.
|
||||
|
||||
COMMANDS:
|
||||
print-help: Print this page.
|
||||
check-updates: Check if a new version of the $BITNAMI_APP_NAME image is available.
|
||||
|
||||
Visit $GITHUB_PAGE for more information.
|
||||
|
||||
|
||||
@@ -1,22 +0,0 @@
|
||||
environment_variables:
|
||||
MARIADB_USER: "User to be created on first boot (default: root)."
|
||||
MARIADB_PASSWORD: "Password to be set for MARIADB_USER on first boot (default: none)."
|
||||
MARIADB_DATABASE: "Database to be created on first boot, accessible by MARIADB_USER (default: none)."
|
||||
MARIADB_SERVER_ID: "Unique server identifier (default: random number)"
|
||||
MARIADB_REPLICATION_MODE: "Replication mode. Possible values master/slave (default: none)."
|
||||
MARIADB_REPLICATION_USER: "Replication user. User is created on master on the first boot (default: none)."
|
||||
MARIADB_REPLICATION_PASSWORD: "Replication users password. Password is set for MARIADB_REPLICATION_USER on master on the first boot (default: none)."
|
||||
MARIADB_MASTER_HOST: "Replication masters hostname/ip (parameter available only on slave)."
|
||||
MARIADB_MASTER_USER: "User on replication master with access to MARIADB_DATABASE. (default: root, parameter available only on slave)."
|
||||
MARIADB_MASTER_PASSWORD: "Password of user on replication master with access to MARIADB_DATABASE (parameter available only on slave)."
|
||||
volumes:
|
||||
$BITNAMI_APP_VOL_PREFIX/data: "Location of $BITNAMI_APP_NAME data files."
|
||||
$BITNAMI_APP_VOL_PREFIX/conf: "Location of my.cnf ($BITNAMI_APP_NAME config file)."
|
||||
$BITNAMI_APP_VOL_PREFIX/logs: "Location of mysqld.log."
|
||||
ports:
|
||||
3306: "$BITNAMI_APP_NAME default port."
|
||||
misc:
|
||||
Options: "You can add extra options during the docker run using the -- prefix."
|
||||
Note: "The user and database creation happens only the first time you run the container."
|
||||
Note: "MARIADB_USER works in conjunction with MARIADB_DATABASE environment variable."
|
||||
Tip: "Back up the $BITNAMI_APP_VOL_PREFIX/data and $BITNAMI_APP_VOL_PREFIX/conf directories regularly."
|
||||
@@ -1 +0,0 @@
|
||||
c2767ef3d9ee9e89eacaf377c869d3784025e45874159c62995ddc3bf373d413 /tmp/installer.run
|
||||
@@ -1,18 +0,0 @@
|
||||
#!/bin/bash
|
||||
cd $BITNAMI_APP_DIR
|
||||
|
||||
# set up default config
|
||||
mkdir conf.defaults
|
||||
mv my.cnf conf.defaults/
|
||||
ln -s $BITNAMI_APP_DIR/conf/my.cnf my.cnf
|
||||
|
||||
# symlink mount points at root to install dir
|
||||
ln -s $BITNAMI_APP_DIR/conf $BITNAMI_APP_VOL_PREFIX/conf
|
||||
ln -s $BITNAMI_APP_DIR/data $BITNAMI_APP_VOL_PREFIX/data
|
||||
ln -s $BITNAMI_APP_DIR/logs $BITNAMI_APP_VOL_PREFIX/logs
|
||||
|
||||
# disable DNS lookups
|
||||
cat >> $BITNAMI_APP_DIR/conf.defaults/my.cnf <<EOF
|
||||
[mysqld]
|
||||
skip-name-resolve
|
||||
EOF
|
||||
23
bitnami/mariadb/rootfs/app-entrypoint.sh
Executable file
23
bitnami/mariadb/rootfs/app-entrypoint.sh
Executable file
@@ -0,0 +1,23 @@
|
||||
#!/bin/bash
|
||||
set -e
|
||||
|
||||
if [[ "$1" == "harpoon" && "$2" == "start" ]]; then
|
||||
status=`harpoon inspect $BITNAMI_APP_NAME`
|
||||
if [[ "$status" == *'"lifecycle": "unpacked"'* ]]; then
|
||||
harpoon initialize $BITNAMI_APP_NAME \
|
||||
${MARIADB_ROOT_PASSWORD:+--rootPassword $MARIADB_ROOT_PASSWORD} \
|
||||
${MARIADB_USER:+--username $MARIADB_USER} \
|
||||
${MARIADB_PASSWORD:+--password $MARIADB_PASSWORD} \
|
||||
${MARIADB_DATABASE:+--database $MARIADB_DATABASE} \
|
||||
${MARIADB_REPLICATION_MODE:+--replicationMode $MARIADB_REPLICATION_MODE} \
|
||||
${MARIADB_REPLICATION_USER:+--replicationUser $MARIADB_REPLICATION_USER} \
|
||||
${MARIADB_REPLICATION_PASSWORD:+--replicationPassword $MARIADB_REPLICATION_PASSWORD} \
|
||||
${MARIADB_MASTER_HOST:+--masterHost $MARIADB_MASTER_HOST} \
|
||||
${MARIADB_MASTER_PORT:+--masterPort $MARIADB_MASTER_PORT} \
|
||||
${MARIADB_MASTER_USER:+--masterUser $MARIADB_MASTER_USER} \
|
||||
${MARIADB_MASTER_PASSWORD:+--masterPassword $MARIADB_MASTER_PASSWORD}
|
||||
fi
|
||||
chown $BITNAMI_APP_USER: /bitnami/$BITNAMI_APP_NAME || true
|
||||
fi
|
||||
|
||||
exec /entrypoint.sh "$@"
|
||||
@@ -1,152 +0,0 @@
|
||||
# MariaDB Utility functions
|
||||
PROGRAM_OPTIONS="--defaults-file=$BITNAMI_APP_DIR/my.cnf --log-error=$BITNAMI_APP_DIR/logs/mysqld.log --basedir=$BITNAMI_APP_DIR --datadir=$BITNAMI_APP_DIR/data --plugin-dir=$BITNAMI_APP_DIR/lib/plugin --user=$BITNAMI_APP_USER --socket=$BITNAMI_APP_DIR/tmp/mysql.sock --lower-case-table-names=1"
|
||||
|
||||
case "$MARIADB_REPLICATION_MODE" in
|
||||
master )
|
||||
PROGRAM_OPTIONS+=" --server-id=${MARIADB_SERVER_ID:-$RANDOM} --binlog-format=ROW --log-bin=mysql-bin --innodb_flush_log_at_trx_commit=1 --sync-binlog=1"
|
||||
;;
|
||||
slave)
|
||||
PROGRAM_OPTIONS+=" --server-id=${MARIADB_SERVER_ID:-$RANDOM} --binlog-format=ROW --log-bin=mysql-bin --relay-log=mysql-relay-bin --log-slave-updates=1 --read-only=1 ${MARIADB_DATABASE:+--replicate-do-db=$MARIADB_DATABASE}"
|
||||
;;
|
||||
esac
|
||||
|
||||
initialize_database() {
|
||||
echo "==> Initializing MySQL database..."
|
||||
echo ""
|
||||
$BITNAMI_APP_DIR/scripts/mysql_install_db --port=3306 --socket=$BITNAMI_APP_DIR/tmp/mysql.sock --basedir=$BITNAMI_APP_DIR --datadir=$BITNAMI_APP_DIR/data > /dev/null
|
||||
chown -R $BITNAMI_APP_USER:$BITNAMI_APP_USER $BITNAMI_APP_DIR/data
|
||||
}
|
||||
|
||||
create_custom_database() {
|
||||
if [ "$MARIADB_DATABASE" ]; then
|
||||
echo "==> Creating database $MARIADB_DATABASE..."
|
||||
echo ""
|
||||
echo "CREATE DATABASE IF NOT EXISTS \`$MARIADB_DATABASE\`;" >> /tmp/init_mysql.sql
|
||||
fi
|
||||
}
|
||||
|
||||
create_mysql_user() {
|
||||
if [ "$MARIADB_REPLICATION_MODE" == "slave" ]; then
|
||||
if [ ! "$MARIADB_USER" ] || [ ! "${MARIADB_PASSWORD}" ] || [ ! "$MARIADB_DATABASE" ]; then
|
||||
echo "==> Trying to fetch MariaDB user/password from the master link..."
|
||||
MARIADB_USER=${MARIADB_USER:-$MASTER_ENV_MARIADB_USER}
|
||||
MARIADB_PASSWORD=${MARIADB_PASSWORD:-$MASTER_ENV_MARIADB_PASSWORD}
|
||||
MARIADB_DATABASE=${MARIADB_DATABASE:-$MASTER_ENV_MARIADB_DATABASE}
|
||||
fi
|
||||
fi
|
||||
|
||||
if [ ! "$MARIADB_USER" ]; then
|
||||
MARIADB_USER=root
|
||||
fi
|
||||
|
||||
if [ "$MARIADB_USER" != "root" ] && [ ! $MARIADB_DATABASE ]; then
|
||||
echo "In order to use a custom MARIADB_USER you need to provide the MARIADB_DATABASE as well"
|
||||
echo ""
|
||||
exit -1
|
||||
fi
|
||||
|
||||
echo "==> Creating user $MARIADB_USER..."
|
||||
echo ""
|
||||
|
||||
echo "DELETE FROM mysql.user ;" >> /tmp/init_mysql.sql
|
||||
echo "CREATE USER '${MARIADB_USER}'@'%' IDENTIFIED BY '${MARIADB_PASSWORD}' ;" >> /tmp/init_mysql.sql
|
||||
|
||||
if [ "$MARIADB_USER" = root ]; then
|
||||
echo "==> Creating root user with unrestricted access..."
|
||||
echo "GRANT ALL ON *.* TO 'root'@'%' WITH GRANT OPTION ;" >> /tmp/init_mysql.sql
|
||||
else
|
||||
echo "==> Granting access to $MARIADB_USER to the database $MARIADB_DATABASE..."
|
||||
echo ""
|
||||
echo "GRANT ALL ON \`${MARIADB_DATABASE}\`.* TO \`${MARIADB_USER}\`@'%' ;" >> /tmp/init_mysql.sql
|
||||
echo "GRANT RELOAD, REPLICATION CLIENT ON *.* TO \`${MARIADB_USER}\`@'%' ;" >> /tmp/init_mysql.sql
|
||||
fi
|
||||
|
||||
echo "FLUSH PRIVILEGES ;" >> /tmp/init_mysql.sql
|
||||
echo "DROP DATABASE IF EXISTS test ; " >> /tmp/init_mysql.sql
|
||||
}
|
||||
|
||||
configure_replication() {
|
||||
case "$MARIADB_REPLICATION_MODE" in
|
||||
master)
|
||||
if [ "$MARIADB_REPLICATION_USER" ]; then
|
||||
echo "==> Creating replication user $MARIADB_REPLICATION_USER..."
|
||||
echo ""
|
||||
|
||||
echo "GRANT REPLICATION SLAVE ON *.* TO '$MARIADB_REPLICATION_USER'@'%' IDENTIFIED BY '$MARIADB_REPLICATION_PASSWORD';" >> /tmp/init_mysql.sql
|
||||
echo "FLUSH PRIVILEGES ;" >> /tmp/init_mysql.sql
|
||||
else
|
||||
echo "In order to setup a replication master you need to provide the MARIADB_REPLICATION_USER as well"
|
||||
echo ""
|
||||
exit -1
|
||||
fi
|
||||
;;
|
||||
slave)
|
||||
echo "==> Setting up MariaDB slave..."
|
||||
|
||||
echo "==> Trying to fetch MariaDB replication parameters from the master link..."
|
||||
MARIADB_MASTER_HOST=${MARIADB_MASTER_HOST:-$MASTER_PORT_3306_TCP_ADDR}
|
||||
MARIADB_MASTER_USER=${MARIADB_MASTER_USER:-$MASTER_ENV_MARIADB_USER}
|
||||
MARIADB_MASTER_PASSWORD=${MARIADB_MASTER_PASSWORD:-$MASTER_ENV_MARIADB_PASSWORD}
|
||||
MARIADB_REPLICATION_USER=${MARIADB_REPLICATION_USER:-$MASTER_ENV_MARIADB_REPLICATION_USER}
|
||||
MARIADB_REPLICATION_PASSWORD=${MARIADB_REPLICATION_PASSWORD:-$MASTER_ENV_MARIADB_REPLICATION_PASSWORD}
|
||||
|
||||
if [ ! $MARIADB_MASTER_HOST ]; then
|
||||
echo "In order to setup a replication slave you need to provide the MARIADB_MASTER_HOST as well"
|
||||
echo ""
|
||||
exit -1
|
||||
fi
|
||||
|
||||
if [ ! $MARIADB_MASTER_USER ]; then
|
||||
echo "MARIADB_MASTER_USER not specified. Defaulting to root"
|
||||
MARIADB_MASTER_USER=${MARIADB_MASTER_USER:-root}
|
||||
fi
|
||||
|
||||
if [ ! $MARIADB_DATABASE ]; then
|
||||
echo "In order to setup a replication slave you need to provide the MARIADB_DATABASE as well"
|
||||
echo ""
|
||||
exit -1
|
||||
fi
|
||||
|
||||
if [ ! $MARIADB_REPLICATION_USER ]; then
|
||||
echo "In order to setup a replication slave you need to provide the MARIADB_REPLICATION_USER as well"
|
||||
echo ""
|
||||
exit -1
|
||||
fi
|
||||
echo "==> Setting the master configuration..."
|
||||
echo "CHANGE MASTER TO MASTER_HOST='$MARIADB_MASTER_HOST', MASTER_USER='$MARIADB_REPLICATION_USER', MASTER_PASSWORD='$MARIADB_REPLICATION_PASSWORD';" >> /tmp/init_mysql.sql
|
||||
|
||||
echo "==> Checking if replication master is ready to accept connection (60s timeout)..."
|
||||
timeout=60
|
||||
while ! mysqladmin -u$MARIADB_MASTER_USER ${MARIADB_MASTER_PASSWORD:+-p$MARIADB_MASTER_PASSWORD} -h $MARIADB_MASTER_HOST status >/dev/null 2>&1
|
||||
do
|
||||
timeout=$(expr $timeout - 1)
|
||||
if [[ $timeout -eq 0 ]]; then
|
||||
echo "Could not connect to replication master"
|
||||
echo ""
|
||||
exit -1
|
||||
fi
|
||||
sleep 1
|
||||
done
|
||||
echo
|
||||
|
||||
echo "==> Creating a data snapshot..."
|
||||
mysqldump -u$MARIADB_MASTER_USER ${MARIADB_MASTER_PASSWORD:+-p$MARIADB_MASTER_PASSWORD} -h $MARIADB_MASTER_HOST \
|
||||
--databases $MARIADB_DATABASE --skip-lock-tables --single-transaction --flush-logs --hex-blob --master-data --apply-slave-statements --comments=false | tr -d '\012' | sed -e 's/;/;\n/g' >> /tmp/init_mysql.sql
|
||||
echo ""
|
||||
;;
|
||||
esac
|
||||
}
|
||||
|
||||
print_mysql_password() {
|
||||
if [ -z $MARIADB_PASSWORD ]; then
|
||||
echo "**none**"
|
||||
else
|
||||
echo $MARIADB_PASSWORD
|
||||
fi
|
||||
}
|
||||
|
||||
print_mysql_database() {
|
||||
if [ $MARIADB_DATABASE ]; then
|
||||
echo "Database: $MARIADB_DATABASE"
|
||||
fi
|
||||
}
|
||||
@@ -1,30 +0,0 @@
|
||||
#!/usr/bin/with-contenv bash
|
||||
set -e
|
||||
source $BITNAMI_PREFIX/bitnami-utils.sh
|
||||
|
||||
# remove initialization commands from last run
|
||||
rm -rf /tmp/init_mysql.sql
|
||||
|
||||
if [ ! "$(ls -A $BITNAMI_APP_VOL_PREFIX/conf)" ]; then
|
||||
generate_conf_files
|
||||
fi
|
||||
|
||||
if [ ! -d $BITNAMI_APP_VOL_PREFIX/data/mysql ]; then
|
||||
|
||||
initialize_database
|
||||
|
||||
create_custom_database
|
||||
|
||||
create_mysql_user
|
||||
|
||||
configure_replication
|
||||
|
||||
print_app_credentials $BITNAMI_APP_NAME $MARIADB_USER `print_mysql_password` `print_mysql_database`
|
||||
else
|
||||
print_container_already_initialized $BITNAMI_APP_NAME
|
||||
fi
|
||||
|
||||
chown -R $BITNAMI_APP_USER:$BITNAMI_APP_USER \
|
||||
$BITNAMI_APP_VOL_PREFIX/conf/ \
|
||||
$BITNAMI_APP_VOL_PREFIX/logs/ \
|
||||
$BITNAMI_APP_VOL_PREFIX/data/ || true
|
||||
@@ -1 +0,0 @@
|
||||
/bin/true
|
||||
@@ -1,5 +0,0 @@
|
||||
#!/usr/bin/with-contenv bash
|
||||
set -e
|
||||
source $BITNAMI_PREFIX/bitnami-utils.sh
|
||||
|
||||
exec s6-setuidgid $BITNAMI_APP_USER tail -f -n 1000 $BITNAMI_APP_VOL_PREFIX/logs/*.log 2>/dev/null
|
||||
@@ -1,21 +0,0 @@
|
||||
#!/usr/bin/with-contenv bash
|
||||
|
||||
failcount=0
|
||||
if [ -f $BITNAMI_APP_DIR/tmp/failcount ]; then
|
||||
failcount=$(cat $BITNAMI_APP_DIR/tmp/failcount)
|
||||
fi
|
||||
|
||||
start=$(cat $BITNAMI_APP_DIR/tmp/start)
|
||||
stop=`date '+%d%H%M%S'`
|
||||
interval=`expr $stop - $start`
|
||||
if test $interval -lt 30 ; then
|
||||
failcount=`expr $failcount + 1`
|
||||
else
|
||||
failcount=0
|
||||
fi
|
||||
echo -n $failcount > $BITNAMI_APP_DIR/tmp/failcount
|
||||
|
||||
# bring down container on frequent failures. something is definitely wrong
|
||||
if test $failcount -ge 3 ; then
|
||||
s6-svscanctl -t /var/run/s6/services
|
||||
fi
|
||||
@@ -1,13 +0,0 @@
|
||||
#!/usr/bin/with-contenv bash
|
||||
set -e
|
||||
source $BITNAMI_PREFIX/bitnami-utils.sh
|
||||
|
||||
mkdir -p $BITNAMI_APP_DIR/tmp
|
||||
chown -R $BITNAMI_APP_USER:$BITNAMI_APP_USER $BITNAMI_APP_DIR/tmp || true
|
||||
|
||||
if [ -f /tmp/init_mysql.sql ]; then
|
||||
PROGRAM_OPTIONS="$PROGRAM_OPTIONS --init-file=/tmp/init_mysql.sql"
|
||||
fi
|
||||
|
||||
date '+%d%H%M%S' > $BITNAMI_APP_DIR/tmp/start
|
||||
exec $BITNAMI_APP_DAEMON $PROGRAM_OPTIONS ${EXTRA_OPTIONS:+"$EXTRA_OPTIONS"}
|
||||
@@ -8,20 +8,21 @@ MARIADB_REPLICATION_PASSWORD=repl_password
|
||||
|
||||
# source the helper script
|
||||
APP_NAME=mariadb
|
||||
SLEEP_TIME=5
|
||||
SLEEP_TIME=45
|
||||
VOL_PREFIX=/bitnami/$APP_NAME
|
||||
VOLUMES=$VOL_PREFIX
|
||||
load tests/docker_helper
|
||||
|
||||
# Link to container and execute mysql client
|
||||
# $1 : name of the container to link to
|
||||
# ${@:2} : arguments for the mysql command
|
||||
mysql_client() {
|
||||
container_link_and_run_command $1 mysql --no-defaults -h $APP_NAME -P 3306 "${@:2}"
|
||||
container_link_and_run_command $1 mysql --no-defaults -h$APP_NAME -P3306 "${@:2}"
|
||||
}
|
||||
|
||||
cleanup_environment() {
|
||||
container_remove_full default
|
||||
container_remove_full slave0
|
||||
container_remove_full master
|
||||
container_remove_full standalone
|
||||
}
|
||||
|
||||
teardown() {
|
||||
@@ -32,372 +33,464 @@ teardown() {
|
||||
cleanup_environment
|
||||
|
||||
@test "Port 3306 exposed and accepting external connections" {
|
||||
container_create standalone -d
|
||||
container_create default -d
|
||||
|
||||
# ping mysqld server
|
||||
run container_link_and_run_command standalone mysqladmin --no-defaults -h $APP_NAME -P 3306 ping
|
||||
run container_link_and_run_command default mysqladmin --no-defaults \
|
||||
-h$APP_NAME -P3306 -uroot ping
|
||||
[[ "$output" =~ "mysqld is alive" ]]
|
||||
}
|
||||
|
||||
@test "Root user created without password" {
|
||||
container_create standalone -d
|
||||
@test "Root can login without a password" {
|
||||
container_create default -d
|
||||
|
||||
# auth as root user and list all databases
|
||||
run mysql_client standalone -uroot -e 'SHOW DATABASES\G;'
|
||||
run mysql_client default -uroot -e 'SHOW DATABASES\G;'
|
||||
[[ "$output" =~ "Database: mysql" ]]
|
||||
}
|
||||
|
||||
@test "Root user created with password" {
|
||||
container_create standalone -d \
|
||||
-e MARIADB_PASSWORD=$MARIADB_PASSWORD
|
||||
@test "Root user created with custom password" {
|
||||
container_create default -d \
|
||||
-e MARIADB_ROOT_PASSWORD=$MARIADB_PASSWORD
|
||||
|
||||
# cannot auth as root without password
|
||||
run mysql_client standalone -uroot -e "SHOW DATABASES\G"
|
||||
[[ "$output" =~ "Access denied for user" ]]
|
||||
|
||||
# auth as root with password and list all databases
|
||||
run mysql_client standalone -uroot -p$MARIADB_PASSWORD -e "SHOW DATABASES\G"
|
||||
run mysql_client default -uroot -p$MARIADB_PASSWORD -e 'SHOW DATABASES\G;'
|
||||
[[ "$output" =~ "Database: mysql" ]]
|
||||
}
|
||||
|
||||
@test "Can't set root user password with MARIADB_PASSWORD" {
|
||||
run container_create default \
|
||||
-e MARIADB_PASSWORD=$MARIADB_PASSWORD
|
||||
[[ "$output" =~ "provide the --rootPassword property" ]]
|
||||
}
|
||||
|
||||
@test "Can't specify 'root' in MARIADB_USER" {
|
||||
run container_create default \
|
||||
-e MARIADB_USER=root
|
||||
[[ "$output" =~ "'root' user is created by default" ]]
|
||||
}
|
||||
|
||||
@test "Root user has access to admin database" {
|
||||
container_create standalone -d
|
||||
run mysql_client standalone -uroot -e "SHOW DATABASES\G"
|
||||
[[ "$output" =~ 'Database: mysql' ]]
|
||||
container_create default -d \
|
||||
-e MARIADB_ROOT_PASSWORD=$MARIADB_PASSWORD
|
||||
|
||||
run mysql_client default -uroot -p$MARIADB_PASSWORD mysql -e 'SHOW TABLES\G;'
|
||||
[[ "$output" =~ "Tables_in_mysql: user" ]]
|
||||
}
|
||||
|
||||
@test "Custom database created" {
|
||||
container_create standalone -d \
|
||||
@test "Can create custom database" {
|
||||
container_create default -d \
|
||||
-e MARIADB_DATABASE=$MARIADB_DATABASE
|
||||
|
||||
# auth as root and check if MARIADB_DATABASE exists
|
||||
run mysql_client standalone -uroot -e "SHOW DATABASES\G"
|
||||
run mysql_client default -uroot -e "SHOW DATABASES\G"
|
||||
[[ "$output" =~ "Database: $MARIADB_DATABASE" ]]
|
||||
}
|
||||
|
||||
@test "Can't create a custom user without database" {
|
||||
# create container without specifying MARIADB_DATABASE
|
||||
run container_create standalone \
|
||||
@test "Can create custom database with password for root" {
|
||||
container_create default -d \
|
||||
-e MARIADB_ROOT_PASSWORD=$MARIADB_PASSWORD \
|
||||
-e MARIADB_DATABASE=$MARIADB_DATABASE
|
||||
|
||||
run mysql_client default -uroot -p$MARIADB_PASSWORD -e "SHOW DATABASES\G"
|
||||
[[ "$output" =~ "Database: $MARIADB_DATABASE" ]]
|
||||
}
|
||||
|
||||
@test "Can't create custom user without database" {
|
||||
run container_create default \
|
||||
-e MARIADB_USER=$MARIADB_USER
|
||||
[[ "$output" =~ "you need to provide the MARIADB_DATABASE" ]]
|
||||
[[ "$output" =~ "provide the --database property as well" ]]
|
||||
}
|
||||
|
||||
@test "Create custom user and database without password" {
|
||||
container_create standalone -d \
|
||||
@test "Custom user created without password" {
|
||||
container_create default -d \
|
||||
-e MARIADB_USER=$MARIADB_USER \
|
||||
-e MARIADB_DATABASE=$MARIADB_DATABASE
|
||||
|
||||
# cannot auth as root
|
||||
run mysql_client standalone -uroot -e "SHOW DATABASES\G"
|
||||
run mysql_client default -u$MARIADB_USER -e "SHOW DATABASES\G"
|
||||
[[ "$output" =~ "Database: $MARIADB_DATABASE" ]]
|
||||
}
|
||||
|
||||
@test "Custom user created with password" {
|
||||
container_create default -d \
|
||||
-e MARIADB_USER=$MARIADB_USER \
|
||||
-e MARIADB_PASSWORD=$MARIADB_PASSWORD \
|
||||
-e MARIADB_DATABASE=$MARIADB_DATABASE
|
||||
|
||||
run mysql_client default -u$MARIADB_USER -p$MARIADB_PASSWORD -e "SHOW DATABASES\G"
|
||||
[[ "$output" =~ "Database: $MARIADB_DATABASE" ]]
|
||||
}
|
||||
|
||||
@test "Custom user can't access admin database" {
|
||||
container_create default -d \
|
||||
-e MARIADB_USER=$MARIADB_USER \
|
||||
-e MARIADB_PASSWORD=$MARIADB_PASSWORD \
|
||||
-e MARIADB_DATABASE=$MARIADB_DATABASE
|
||||
|
||||
run mysql_client default -u$MARIADB_USER -p$MARIADB_PASSWORD mysql -e 'SHOW TABLES\G;'
|
||||
[[ "$output" =~ "Access denied for user" ]]
|
||||
}
|
||||
|
||||
# auth as MARIADB_USER and check of MARIADB_DATABASE exists
|
||||
run mysql_client standalone -u$MARIADB_USER -e "SHOW DATABASES\G"
|
||||
@test "Can set root password and create custom user without password" {
|
||||
container_create default -d \
|
||||
-e MARIADB_ROOT_PASSWORD=$MARIADB_PASSWORD \
|
||||
-e MARIADB_USER=$MARIADB_USER \
|
||||
-e MARIADB_DATABASE=$MARIADB_DATABASE
|
||||
|
||||
run mysql_client default -uroot -p$MARIADB_PASSWORD -e "SHOW DATABASES\G"
|
||||
[[ "$output" =~ "Database: mysql" ]]
|
||||
|
||||
run mysql_client default -u$MARIADB_USER -e "SHOW DATABASES\G"
|
||||
[[ "$output" =~ "Database: $MARIADB_DATABASE" ]]
|
||||
}
|
||||
|
||||
@test "Create custom user and database with password" {
|
||||
container_create standalone -d \
|
||||
@test "Can set root password and create custom user with password" {
|
||||
container_create default -d \
|
||||
-e MARIADB_ROOT_PASSWORD=$MARIADB_PASSWORD \
|
||||
-e MARIADB_USER=$MARIADB_USER \
|
||||
-e MARIADB_DATABASE=$MARIADB_DATABASE \
|
||||
-e MARIADB_PASSWORD=$MARIADB_PASSWORD
|
||||
-e MARIADB_PASSWORD=$MARIADB_PASSWORD \
|
||||
-e MARIADB_DATABASE=$MARIADB_DATABASE
|
||||
|
||||
# auth as MARIADB_USER with password and check if MARIADB_DATABASE exists
|
||||
run mysql_client standalone -u$MARIADB_USER -p$MARIADB_PASSWORD -e "SHOW DATABASES\G"
|
||||
run mysql_client default -uroot -p$MARIADB_PASSWORD -e "SHOW DATABASES\G"
|
||||
[[ "$output" =~ "Database: mysql" ]]
|
||||
|
||||
run mysql_client default -u$MARIADB_USER -p$MARIADB_PASSWORD -e "SHOW DATABASES\G"
|
||||
[[ "$output" =~ "Database: $MARIADB_DATABASE" ]]
|
||||
}
|
||||
|
||||
@test "User and password settings are preserved after restart" {
|
||||
container_create standalone -d \
|
||||
@test "Data is preserved on container restart" {
|
||||
container_create default -d \
|
||||
-e MARIADB_USER=$MARIADB_USER \
|
||||
-e MARIADB_DATABASE=$MARIADB_DATABASE \
|
||||
-e MARIADB_PASSWORD=$MARIADB_PASSWORD
|
||||
-e MARIADB_PASSWORD=$MARIADB_PASSWORD \
|
||||
-e MARIADB_DATABASE=$MARIADB_DATABASE
|
||||
|
||||
# restart container
|
||||
container_restart standalone
|
||||
container_restart default
|
||||
|
||||
# get container logs
|
||||
run container_logs standalone
|
||||
[[ "$output" =~ "The credentials were set on first boot." ]]
|
||||
|
||||
# auth as MARIADB_USER and check if MARIADB_DATABASE exists
|
||||
run mysql_client standalone -u$MARIADB_USER -p$MARIADB_PASSWORD -e "SHOW DATABASES\G"
|
||||
run mysql_client default -u$MARIADB_USER -p$MARIADB_PASSWORD -e "SHOW DATABASES\G"
|
||||
[[ "$output" =~ "Database: $MARIADB_DATABASE" ]]
|
||||
}
|
||||
|
||||
@test "All the volumes exposed" {
|
||||
container_create standalone -d
|
||||
container_create default -d
|
||||
|
||||
# get container introspection details and check if volumes are exposed
|
||||
run container_inspect standalone --format {{.Mounts}}
|
||||
[[ "$output" =~ "$VOL_PREFIX/data" ]]
|
||||
[[ "$output" =~ "$VOL_PREFIX/conf" ]]
|
||||
[[ "$output" =~ "$VOL_PREFIX/logs" ]]
|
||||
run container_inspect default --format {{.Mounts}}
|
||||
[[ "$output" =~ "$VOL_PREFIX" ]]
|
||||
}
|
||||
|
||||
@test "Data gets generated in conf, data and logs if bind mounted in the host" {
|
||||
container_create_with_host_volumes standalone -d \
|
||||
-e MARIADB_USER=$MARIADB_USER \
|
||||
-e MARIADB_DATABASE=$MARIADB_DATABASE \
|
||||
-e MARIADB_PASSWORD=$MARIADB_PASSWORD
|
||||
@test "Data gets generated in volume if bind mounted in the host" {
|
||||
container_create_with_host_volumes default -d
|
||||
|
||||
# files expected in conf volume
|
||||
run container_exec standalone ls -la $VOL_PREFIX/conf/
|
||||
[[ "$output" =~ "my.cnf" ]]
|
||||
|
||||
# files expected in data volume (subset)
|
||||
run container_exec standalone ls -la $VOL_PREFIX/data/
|
||||
run container_exec default ls -la $VOL_PREFIX/data/
|
||||
[[ "$output" =~ "mysql" ]]
|
||||
[[ "$output" =~ "ibdata1" ]]
|
||||
|
||||
# files expected in logs volume
|
||||
run container_exec standalone ls -la $VOL_PREFIX/logs/
|
||||
[[ "$output" =~ "mysqld.log" ]]
|
||||
}
|
||||
|
||||
# https://github.com/bitnami/bitnami-docker-mariadb/issues/39
|
||||
@test "If host mounted, password and settings are preserved upon restart" {
|
||||
container_create_with_host_volumes standalone -d \
|
||||
-e MARIADB_USER=$MARIADB_USER \
|
||||
-e MARIADB_DATABASE=$MARIADB_DATABASE \
|
||||
-e MARIADB_PASSWORD=$MARIADB_PASSWORD
|
||||
|
||||
# restart container multiple times
|
||||
container_restart standalone
|
||||
container_restart standalone
|
||||
|
||||
# auth as MARIADB_USER and check of MARIADB_DATABASE exists
|
||||
run mysql_client standalone -u$MARIADB_USER -p$MARIADB_PASSWORD -e "SHOW DATABASES\G"
|
||||
[[ "$output" =~ "Database: $MARIADB_DATABASE" ]]
|
||||
run container_exec default ls -la $VOL_PREFIX/conf/
|
||||
[[ "$output" =~ "my.cnf" ]]
|
||||
}
|
||||
|
||||
@test "If host mounted, password and settings are preserved after deletion" {
|
||||
container_create_with_host_volumes standalone -d \
|
||||
container_create_with_host_volumes default -d \
|
||||
-e MARIADB_USER=$MARIADB_USER \
|
||||
-e MARIADB_DATABASE=$MARIADB_DATABASE \
|
||||
-e MARIADB_PASSWORD=$MARIADB_PASSWORD
|
||||
-e MARIADB_PASSWORD=$MARIADB_PASSWORD \
|
||||
-e MARIADB_DATABASE=$MARIADB_DATABASE
|
||||
|
||||
# stop and remove container
|
||||
container_remove standalone
|
||||
container_remove default
|
||||
container_create_with_host_volumes default -d
|
||||
|
||||
# recreate container without specifying any env parameters
|
||||
container_create_with_host_volumes standalone -d
|
||||
|
||||
# auth as MARIADB_USER and check of MARIADB_DATABASE exists
|
||||
run mysql_client standalone -u$MARIADB_USER -p$MARIADB_PASSWORD -e "SHOW DATABASES\G"
|
||||
run mysql_client default -u$MARIADB_USER -p$MARIADB_PASSWORD -e "SHOW DATABASES\G"
|
||||
[[ "$output" =~ "Database: $MARIADB_DATABASE" ]]
|
||||
}
|
||||
|
||||
@test "Configuration changes are preserved after deletion" {
|
||||
container_create_with_host_volumes standalone -d
|
||||
|
||||
# modify my.cnf
|
||||
container_exec standalone sed -i 's|^[#]*[ ]*max_allowed_packet[ ]*=.*|max_allowed_packet=64M|' $VOL_PREFIX/conf/my.cnf
|
||||
container_exec standalone sed -i 's|^[#]*[ ]*bind-address[ ]*=.*|bind-address=0.0.0.0|' $VOL_PREFIX/conf/my.cnf
|
||||
|
||||
# stop and remove container
|
||||
container_remove standalone
|
||||
|
||||
# relaunch container with host volumes
|
||||
container_create_with_host_volumes standalone -d
|
||||
|
||||
run container_exec standalone cat $VOL_PREFIX/conf/my.cnf
|
||||
[[ "$output" =~ "max_allowed_packet=64M" ]]
|
||||
[[ "$output" =~ "bind-address=0.0.0.0" ]]
|
||||
}
|
||||
|
||||
@test "Can't setup replication master without replication user" {
|
||||
# create replication master without specifying MARIADB_REPLICATION_USER
|
||||
run container_create master \
|
||||
-e MARIADB_USER=$MARIADB_USER \
|
||||
-e MARIADB_PASSWORD=$MARIADB_PASSWORD \
|
||||
-e MARIADB_DATABASE=$MARIADB_DATABASE \
|
||||
@test "Can't setup replication master without creating a replication user" {
|
||||
run container_create default \
|
||||
-e MARIADB_REPLICATION_MODE=master
|
||||
[[ "$output" =~ "you need to provide the MARIADB_REPLICATION_USER" ]]
|
||||
[[ "$output" =~ "provide the --replicationUser property as well" ]]
|
||||
}
|
||||
|
||||
@test "Can't setup replication slave without master host" {
|
||||
# create replication slave without specifying MARIADB_MASTER_HOST
|
||||
@test "Can't setup replication slave without specifying the master host" {
|
||||
run container_create slave0 \
|
||||
-e MARIADB_REPLICATION_MODE=slave
|
||||
[[ "$output" =~ "you need to provide the MARIADB_MASTER_HOST" ]]
|
||||
[[ "$output" =~ "provide the --masterHost property as well" ]]
|
||||
}
|
||||
|
||||
@test "Can't setup replication slave without database" {
|
||||
# create replication slave without specifying MARIADB_DATABASE
|
||||
run container_create slave0 \
|
||||
-e MARIADB_REPLICATION_MODE=slave \
|
||||
-e MARIADB_MASTER_HOST=master \
|
||||
-e MARIADB_MASTER_USER=$MARIADB_USER
|
||||
[[ "$output" =~ "you need to provide the MARIADB_DATABASE" ]]
|
||||
-e MARIADB_MASTER_HOST=master
|
||||
[[ "$output" =~ "provide the --database property as well" ]]
|
||||
}
|
||||
|
||||
@test "Can't setup replication slave without replication user" {
|
||||
# create replication slave without specifying MARIADB_REPLICATION_USER
|
||||
run container_create slave0 \
|
||||
-e MARIADB_REPLICATION_MODE=slave \
|
||||
-e MARIADB_MASTER_HOST=master \
|
||||
-e MARIADB_MASTER_USER=$MARIADB_USER \
|
||||
-e MARIADB_DATABASE=$MARIADB_DATABASE
|
||||
[[ "$output" =~ "you need to provide the MARIADB_REPLICATION_USER" ]]
|
||||
[[ "$output" =~ "provide the --replicationUser property as well" ]]
|
||||
}
|
||||
|
||||
@test "Master database is replicated on slave" {
|
||||
container_create master -d \
|
||||
-e MARIADB_USER=$MARIADB_USER \
|
||||
-e MARIADB_PASSWORD=$MARIADB_PASSWORD \
|
||||
-e MARIADB_DATABASE=$MARIADB_DATABASE \
|
||||
@test "Can setup master/slave replication with minimal configuration" {
|
||||
container_create default -d \
|
||||
-e MARIADB_REPLICATION_MODE=master \
|
||||
-e MARIADB_REPLICATION_USER=$MARIADB_REPLICATION_USER \
|
||||
-e MARIADB_REPLICATION_PASSWORD=$MARIADB_REPLICATION_PASSWORD
|
||||
-e MARIADB_DATABASE=$MARIADB_DATABASE
|
||||
|
||||
container_create slave0 -d \
|
||||
$(container_link master $CONTAINER_NAME) \
|
||||
$(container_link default $CONTAINER_NAME) \
|
||||
-e MARIADB_REPLICATION_MODE=slave \
|
||||
-e MARIADB_REPLICATION_USER=$MARIADB_REPLICATION_USER \
|
||||
-e MARIADB_MASTER_HOST=$CONTAINER_NAME \
|
||||
-e MARIADB_DATABASE=$MARIADB_DATABASE
|
||||
|
||||
mysql_client default -uroot $MARIADB_DATABASE -e \
|
||||
"CREATE TABLE users (id INT AUTO_INCREMENT, name VARCHAR(30), datum TIMESTAMP DEFAULT CURRENT_TIMESTAMP, PRIMARY KEY(id)); \
|
||||
INSERT INTO users(name) VALUES ('Marko');"
|
||||
|
||||
run mysql_client slave0 -uroot $MARIADB_DATABASE -e "SELECT * FROM users\G"
|
||||
[[ "$output" =~ "name: Marko" ]]
|
||||
}
|
||||
|
||||
@test "Can setup master/slave replication with root password" {
|
||||
container_create default -d \
|
||||
-e MARIADB_REPLICATION_MODE=master \
|
||||
-e MARIADB_REPLICATION_USER=$MARIADB_REPLICATION_USER \
|
||||
-e MARIADB_REPLICATION_PASSWORD=$MARIADB_REPLICATION_PASSWORD \
|
||||
-e MARIADB_ROOT_PASSWORD=$MARIADB_PASSWORD \
|
||||
-e MARIADB_DATABASE=$MARIADB_DATABASE
|
||||
|
||||
container_create slave0 -d \
|
||||
$(container_link default $CONTAINER_NAME) \
|
||||
-e MARIADB_REPLICATION_MODE=slave \
|
||||
-e MARIADB_REPLICATION_USER=$MARIADB_REPLICATION_USER \
|
||||
-e MARIADB_REPLICATION_PASSWORD=$MARIADB_REPLICATION_PASSWORD \
|
||||
-e MARIADB_MASTER_HOST=$CONTAINER_NAME \
|
||||
-e MARIADB_MASTER_PASSWORD=$MARIADB_PASSWORD \
|
||||
-e MARIADB_ROOT_PASSWORD=$MARIADB_PASSWORD \
|
||||
-e MARIADB_DATABASE=$MARIADB_DATABASE
|
||||
|
||||
mysql_client default -uroot -p$MARIADB_PASSWORD $MARIADB_DATABASE -e \
|
||||
"CREATE TABLE users (id INT AUTO_INCREMENT, name VARCHAR(30), datum TIMESTAMP DEFAULT CURRENT_TIMESTAMP, PRIMARY KEY(id)); \
|
||||
INSERT INTO users(name) VALUES ('Marko');"
|
||||
|
||||
run mysql_client slave0 -uroot -p$MARIADB_PASSWORD $MARIADB_DATABASE -e "SELECT * FROM users\G"
|
||||
[[ "$output" =~ "name: Marko" ]]
|
||||
}
|
||||
|
||||
@test "Can setup master/slave replication with password for replication user" {
|
||||
container_create default -d \
|
||||
-e MARIADB_REPLICATION_MODE=master \
|
||||
-e MARIADB_REPLICATION_USER=$MARIADB_REPLICATION_USER \
|
||||
-e MARIADB_REPLICATION_PASSWORD=$MARIADB_REPLICATION_PASSWORD \
|
||||
-e MARIADB_ROOT_PASSWORD=$MARIADB_PASSWORD \
|
||||
-e MARIADB_DATABASE=$MARIADB_DATABASE
|
||||
|
||||
container_create slave0 -d \
|
||||
$(container_link default $CONTAINER_NAME) \
|
||||
-e MARIADB_REPLICATION_MODE=slave \
|
||||
-e MARIADB_REPLICATION_USER=$MARIADB_REPLICATION_USER \
|
||||
-e MARIADB_REPLICATION_PASSWORD=$MARIADB_REPLICATION_PASSWORD \
|
||||
-e MARIADB_MASTER_HOST=$CONTAINER_NAME \
|
||||
-e MARIADB_MASTER_PASSWORD=$MARIADB_PASSWORD \
|
||||
-e MARIADB_ROOT_PASSWORD=$MARIADB_PASSWORD \
|
||||
-e MARIADB_DATABASE=$MARIADB_DATABASE
|
||||
|
||||
mysql_client default -uroot -p$MARIADB_PASSWORD $MARIADB_DATABASE -e \
|
||||
"CREATE TABLE users (id INT AUTO_INCREMENT, name VARCHAR(30), datum TIMESTAMP DEFAULT CURRENT_TIMESTAMP, PRIMARY KEY(id)); \
|
||||
INSERT INTO users(name) VALUES ('Marko');"
|
||||
|
||||
run mysql_client slave0 -uroot -p$MARIADB_PASSWORD $MARIADB_DATABASE -e "SELECT * FROM users\G"
|
||||
[[ "$output" =~ "name: Marko" ]]
|
||||
}
|
||||
|
||||
@test "Can setup master/slave replication with custom user without password" {
|
||||
container_create default -d \
|
||||
-e MARIADB_REPLICATION_MODE=master \
|
||||
-e MARIADB_REPLICATION_USER=$MARIADB_REPLICATION_USER \
|
||||
-e MARIADB_REPLICATION_PASSWORD=$MARIADB_REPLICATION_PASSWORD \
|
||||
-e MARIADB_USER=$MARIADB_USER \
|
||||
-e MARIADB_DATABASE=$MARIADB_DATABASE
|
||||
|
||||
container_create slave0 -d \
|
||||
$(container_link default $CONTAINER_NAME) \
|
||||
-e MARIADB_REPLICATION_MODE=slave \
|
||||
-e MARIADB_REPLICATION_USER=$MARIADB_REPLICATION_USER \
|
||||
-e MARIADB_REPLICATION_PASSWORD=$MARIADB_REPLICATION_PASSWORD \
|
||||
-e MARIADB_MASTER_HOST=$CONTAINER_NAME \
|
||||
-e MARIADB_MASTER_USER=$MARIADB_USER \
|
||||
-e MARIADB_USER=$MARIADB_USER \
|
||||
-e MARIADB_DATABASE=$MARIADB_DATABASE
|
||||
|
||||
mysql_client default -u$MARIADB_USER $MARIADB_DATABASE -e \
|
||||
"CREATE TABLE users (id INT AUTO_INCREMENT, name VARCHAR(30), datum TIMESTAMP DEFAULT CURRENT_TIMESTAMP, PRIMARY KEY(id)); \
|
||||
INSERT INTO users(name) VALUES ('Marko');"
|
||||
|
||||
run mysql_client slave0 -u$MARIADB_USER $MARIADB_DATABASE -e "SELECT * FROM users\G"
|
||||
[[ "$output" =~ "name: Marko" ]]
|
||||
}
|
||||
|
||||
@test "Can setup master/slave replication with custom user and password" {
|
||||
container_create default -d \
|
||||
-e MARIADB_REPLICATION_MODE=master \
|
||||
-e MARIADB_REPLICATION_USER=$MARIADB_REPLICATION_USER \
|
||||
-e MARIADB_REPLICATION_PASSWORD=$MARIADB_REPLICATION_PASSWORD \
|
||||
-e MARIADB_USER=$MARIADB_USER \
|
||||
-e MARIADB_PASSWORD=$MARIADB_PASSWORD \
|
||||
-e MARIADB_DATABASE=$MARIADB_DATABASE
|
||||
|
||||
container_create slave0 -d \
|
||||
$(container_link default $CONTAINER_NAME) \
|
||||
-e MARIADB_REPLICATION_MODE=slave \
|
||||
-e MARIADB_REPLICATION_USER=$MARIADB_REPLICATION_USER \
|
||||
-e MARIADB_REPLICATION_PASSWORD=$MARIADB_REPLICATION_PASSWORD \
|
||||
-e MARIADB_MASTER_HOST=$CONTAINER_NAME \
|
||||
-e MARIADB_MASTER_USER=$MARIADB_USER \
|
||||
-e MARIADB_MASTER_PASSWORD=$MARIADB_PASSWORD \
|
||||
-e MARIADB_USER=$MARIADB_USER \
|
||||
-e MARIADB_PASSWORD=$MARIADB_PASSWORD \
|
||||
-e MARIADB_DATABASE=$MARIADB_DATABASE \
|
||||
-e MARIADB_REPLICATION_MODE=slave \
|
||||
-e MARIADB_REPLICATION_USER=$MARIADB_REPLICATION_USER \
|
||||
-e MARIADB_REPLICATION_PASSWORD=$MARIADB_REPLICATION_PASSWORD
|
||||
-e MARIADB_DATABASE=$MARIADB_DATABASE
|
||||
|
||||
# create users table on master and insert a record
|
||||
mysql_client master -u$MARIADB_USER -p$MARIADB_PASSWORD $MARIADB_DATABASE -e \
|
||||
mysql_client default -u$MARIADB_USER -p$MARIADB_PASSWORD $MARIADB_DATABASE -e \
|
||||
"CREATE TABLE users (id INT AUTO_INCREMENT, name VARCHAR(30), datum TIMESTAMP DEFAULT CURRENT_TIMESTAMP, PRIMARY KEY(id)); \
|
||||
INSERT INTO users(name) VALUES ('Marko');"
|
||||
|
||||
# verify that record is replicated on slave0
|
||||
run mysql_client slave0 -u$MARIADB_USER -p$MARIADB_PASSWORD $MARIADB_DATABASE -e "SELECT * FROM users\G"
|
||||
[[ "$output" =~ "name: Marko" ]]
|
||||
}
|
||||
|
||||
@test "Can setup replication without password for replication user" {
|
||||
container_create master -d \
|
||||
-e MARIADB_USER=$MARIADB_USER \
|
||||
-e MARIADB_PASSWORD=$MARIADB_PASSWORD \
|
||||
-e MARIADB_DATABASE=$MARIADB_DATABASE \
|
||||
-e MARIADB_REPLICATION_MODE=master \
|
||||
-e MARIADB_REPLICATION_USER=$MARIADB_REPLICATION_USER
|
||||
|
||||
container_create slave0 -d \
|
||||
$(container_link master $CONTAINER_NAME) \
|
||||
-e MARIADB_MASTER_HOST=$CONTAINER_NAME \
|
||||
-e MARIADB_MASTER_USER=$MARIADB_USER \
|
||||
-e MARIADB_MASTER_PASSWORD=$MARIADB_PASSWORD \
|
||||
-e MARIADB_USER=$MARIADB_USER \
|
||||
-e MARIADB_PASSWORD=$MARIADB_PASSWORD \
|
||||
-e MARIADB_DATABASE=$MARIADB_DATABASE \
|
||||
-e MARIADB_REPLICATION_MODE=slave \
|
||||
-e MARIADB_REPLICATION_USER=$MARIADB_REPLICATION_USER
|
||||
|
||||
# create users table on master and insert a record
|
||||
mysql_client master -u$MARIADB_USER -p$MARIADB_PASSWORD $MARIADB_DATABASE -e \
|
||||
"CREATE TABLE users (id INT AUTO_INCREMENT, name VARCHAR(30), datum TIMESTAMP DEFAULT CURRENT_TIMESTAMP, PRIMARY KEY(id)); \
|
||||
INSERT INTO users(name) VALUES ('Marko');"
|
||||
|
||||
# verify that record is replicated on slave0
|
||||
run mysql_client slave0 -u$MARIADB_USER -p$MARIADB_PASSWORD $MARIADB_DATABASE -e "SELECT * FROM users\G"
|
||||
[[ "$output" =~ "name: Marko" ]]
|
||||
}
|
||||
|
||||
@test "Replication slave can fetch replication parameters from link alias \"master\"" {
|
||||
container_create master -d \
|
||||
-e MARIADB_USER=$MARIADB_USER \
|
||||
-e MARIADB_PASSWORD=$MARIADB_PASSWORD \
|
||||
-e MARIADB_DATABASE=$MARIADB_DATABASE \
|
||||
-e MARIADB_REPLICATION_MODE=master \
|
||||
-e MARIADB_REPLICATION_USER=$MARIADB_REPLICATION_USER \
|
||||
-e MARIADB_REPLICATION_PASSWORD=$MARIADB_REPLICATION_PASSWORD
|
||||
|
||||
# create replication slave0 linked to master with alias named master
|
||||
container_create slave0 -d \
|
||||
$(container_link master master) \
|
||||
-e MARIADB_REPLICATION_MODE=slave
|
||||
|
||||
# create users table on master and insert a new row
|
||||
mysql_client master -u$MARIADB_USER -p$MARIADB_PASSWORD $MARIADB_DATABASE -e \
|
||||
"CREATE TABLE users (id INT AUTO_INCREMENT, name VARCHAR(30), datum TIMESTAMP DEFAULT CURRENT_TIMESTAMP, PRIMARY KEY(id)); \
|
||||
INSERT INTO users(name) VALUES ('Marko');"
|
||||
|
||||
# check if row is replicated on slave0
|
||||
run mysql_client slave0 -u$MARIADB_USER -p$MARIADB_PASSWORD $MARIADB_DATABASE -e "SELECT * FROM users\G"
|
||||
[[ "$output" =~ "name: Marko" ]]
|
||||
}
|
||||
|
||||
@test "Slave synchronizes with the master (delayed start)" {
|
||||
container_create master -d \
|
||||
-e MARIADB_USER=$MARIADB_USER \
|
||||
-e MARIADB_PASSWORD=$MARIADB_PASSWORD \
|
||||
-e MARIADB_DATABASE=$MARIADB_DATABASE \
|
||||
container_create default -d \
|
||||
-e MARIADB_REPLICATION_MODE=master \
|
||||
-e MARIADB_REPLICATION_USER=$MARIADB_REPLICATION_USER \
|
||||
-e MARIADB_REPLICATION_PASSWORD=$MARIADB_REPLICATION_PASSWORD
|
||||
-e MARIADB_REPLICATION_PASSWORD=$MARIADB_REPLICATION_PASSWORD \
|
||||
-e MARIADB_USER=$MARIADB_USER \
|
||||
-e MARIADB_PASSWORD=$MARIADB_PASSWORD \
|
||||
-e MARIADB_DATABASE=$MARIADB_DATABASE
|
||||
|
||||
# create users table on master and insert a new row
|
||||
mysql_client master -u$MARIADB_USER -p$MARIADB_PASSWORD $MARIADB_DATABASE -e \
|
||||
"CREATE TABLE users (id INT AUTO_INCREMENT, name VARCHAR(30), datum TIMESTAMP DEFAULT CURRENT_TIMESTAMP, PRIMARY KEY(id)) ;
|
||||
mysql_client default -u$MARIADB_USER -p$MARIADB_PASSWORD $MARIADB_DATABASE -e \
|
||||
"CREATE TABLE users (id INT AUTO_INCREMENT, name VARCHAR(30), datum TIMESTAMP DEFAULT CURRENT_TIMESTAMP, PRIMARY KEY(id)); \
|
||||
INSERT INTO users(name) VALUES ('Marko');"
|
||||
|
||||
# start slave0 linked to the master
|
||||
container_create slave0 -d \
|
||||
$(container_link master $CONTAINER_NAME) \
|
||||
$(container_link default $CONTAINER_NAME) \
|
||||
-e MARIADB_REPLICATION_MODE=slave \
|
||||
-e MARIADB_REPLICATION_USER=$MARIADB_REPLICATION_USER \
|
||||
-e MARIADB_REPLICATION_PASSWORD=$MARIADB_REPLICATION_PASSWORD \
|
||||
-e MARIADB_MASTER_HOST=$CONTAINER_NAME \
|
||||
-e MARIADB_MASTER_USER=$MARIADB_USER \
|
||||
-e MARIADB_MASTER_PASSWORD=$MARIADB_PASSWORD \
|
||||
-e MARIADB_USER=$MARIADB_USER \
|
||||
-e MARIADB_PASSWORD=$MARIADB_PASSWORD \
|
||||
-e MARIADB_DATABASE=$MARIADB_DATABASE \
|
||||
-e MARIADB_REPLICATION_MODE=slave \
|
||||
-e MARIADB_REPLICATION_USER=$MARIADB_REPLICATION_USER \
|
||||
-e MARIADB_REPLICATION_PASSWORD=$MARIADB_REPLICATION_PASSWORD
|
||||
-e MARIADB_DATABASE=$MARIADB_DATABASE
|
||||
|
||||
# verify that master data is replicated on slave
|
||||
run mysql_client slave0 -u$MARIADB_USER -p$MARIADB_PASSWORD $MARIADB_DATABASE -e "SELECT * FROM users\G"
|
||||
[[ "$output" =~ "name: Marko" ]]
|
||||
}
|
||||
|
||||
@test "Replication status is preserved after deletion" {
|
||||
# create master container with host mounted volumes
|
||||
container_create_with_host_volumes master -d \
|
||||
-e MARIADB_USER=$MARIADB_USER \
|
||||
-e MARIADB_PASSWORD=$MARIADB_PASSWORD \
|
||||
-e MARIADB_DATABASE=$MARIADB_DATABASE \
|
||||
@test "Replication setup and state is preserved after restart" {
|
||||
container_create_with_host_volumes default -d \
|
||||
-e MARIADB_REPLICATION_MODE=master \
|
||||
-e MARIADB_REPLICATION_USER=$MARIADB_REPLICATION_USER \
|
||||
-e MARIADB_REPLICATION_PASSWORD=$MARIADB_REPLICATION_PASSWORD
|
||||
-e MARIADB_REPLICATION_PASSWORD=$MARIADB_REPLICATION_PASSWORD \
|
||||
-e MARIADB_USER=$MARIADB_USER \
|
||||
-e MARIADB_PASSWORD=$MARIADB_PASSWORD \
|
||||
-e MARIADB_DATABASE=$MARIADB_DATABASE
|
||||
|
||||
# create users table on master and insert a new row
|
||||
mysql_client master -u$MARIADB_USER -p$MARIADB_PASSWORD $MARIADB_DATABASE -e \
|
||||
"CREATE TABLE users (id INT AUTO_INCREMENT, name VARCHAR(30), datum TIMESTAMP DEFAULT CURRENT_TIMESTAMP, PRIMARY KEY(id)) ;
|
||||
mysql_client default -u$MARIADB_USER -p$MARIADB_PASSWORD $MARIADB_DATABASE -e \
|
||||
"CREATE TABLE users (id INT AUTO_INCREMENT, name VARCHAR(30), datum TIMESTAMP DEFAULT CURRENT_TIMESTAMP, PRIMARY KEY(id)); \
|
||||
INSERT INTO users(name) VALUES ('Marko');"
|
||||
|
||||
# create slave0 container with host mounted volumes, should replicate the master data
|
||||
container_create_with_host_volumes slave0 -d \
|
||||
$(container_link master $CONTAINER_NAME) \
|
||||
$(container_link default $CONTAINER_NAME) \
|
||||
-e MARIADB_REPLICATION_MODE=slave \
|
||||
-e MARIADB_REPLICATION_USER=$MARIADB_REPLICATION_USER \
|
||||
-e MARIADB_REPLICATION_PASSWORD=$MARIADB_REPLICATION_PASSWORD \
|
||||
-e MARIADB_MASTER_HOST=$CONTAINER_NAME \
|
||||
-e MARIADB_MASTER_USER=$MARIADB_USER \
|
||||
-e MARIADB_MASTER_PASSWORD=$MARIADB_PASSWORD \
|
||||
-e MARIADB_USER=$MARIADB_USER \
|
||||
-e MARIADB_PASSWORD=$MARIADB_PASSWORD \
|
||||
-e MARIADB_DATABASE=$MARIADB_DATABASE \
|
||||
-e MARIADB_REPLICATION_MODE=slave \
|
||||
-e MARIADB_REPLICATION_USER=$MARIADB_REPLICATION_USER \
|
||||
-e MARIADB_REPLICATION_PASSWORD=$MARIADB_REPLICATION_PASSWORD
|
||||
-e MARIADB_DATABASE=$MARIADB_DATABASE
|
||||
|
||||
# stop and remove master and slave0 containers
|
||||
container_remove master
|
||||
container_remove slave0
|
||||
container_restart default
|
||||
container_restart slave0
|
||||
|
||||
# start master and slave0 containers with existing host volumes and no additional env arguments other than MARIADB_REPLICATION_MODE
|
||||
container_create_with_host_volumes master -d -e MARIADB_REPLICATION_MODE=master
|
||||
container_create_with_host_volumes slave0 -d $(container_link master $CONTAINER_NAME) -e MARIADB_REPLICATION_MODE=slave
|
||||
mysql_client default -u$MARIADB_USER -p$MARIADB_PASSWORD $MARIADB_DATABASE -e "INSERT INTO users(name) VALUES ('Polo')"
|
||||
|
||||
run mysql_client slave0 -u$MARIADB_USER -p$MARIADB_PASSWORD $MARIADB_DATABASE -e "SELECT * FROM users\G"
|
||||
[[ "$output" =~ "name: Marko" ]]
|
||||
[[ "$output" =~ "name: Polo" ]]
|
||||
}
|
||||
|
||||
@test "Slave recovers if master is temporarily offine" {
|
||||
container_create_with_host_volumes default -d \
|
||||
-e MARIADB_REPLICATION_MODE=master \
|
||||
-e MARIADB_REPLICATION_USER=$MARIADB_REPLICATION_USER \
|
||||
-e MARIADB_REPLICATION_PASSWORD=$MARIADB_REPLICATION_PASSWORD \
|
||||
-e MARIADB_USER=$MARIADB_USER \
|
||||
-e MARIADB_PASSWORD=$MARIADB_PASSWORD \
|
||||
-e MARIADB_DATABASE=$MARIADB_DATABASE
|
||||
|
||||
mysql_client default -u$MARIADB_USER -p$MARIADB_PASSWORD $MARIADB_DATABASE -e \
|
||||
"CREATE TABLE users (id INT AUTO_INCREMENT, name VARCHAR(30), datum TIMESTAMP DEFAULT CURRENT_TIMESTAMP, PRIMARY KEY(id)); \
|
||||
INSERT INTO users(name) VALUES ('Marko');"
|
||||
|
||||
container_create_with_host_volumes slave0 -d \
|
||||
$(container_link default $CONTAINER_NAME) \
|
||||
-e MARIADB_REPLICATION_MODE=slave \
|
||||
-e MARIADB_REPLICATION_USER=$MARIADB_REPLICATION_USER \
|
||||
-e MARIADB_REPLICATION_PASSWORD=$MARIADB_REPLICATION_PASSWORD \
|
||||
-e MARIADB_MASTER_HOST=$CONTAINER_NAME \
|
||||
-e MARIADB_MASTER_USER=$MARIADB_USER \
|
||||
-e MARIADB_MASTER_PASSWORD=$MARIADB_PASSWORD \
|
||||
-e MARIADB_USER=$MARIADB_USER \
|
||||
-e MARIADB_PASSWORD=$MARIADB_PASSWORD \
|
||||
-e MARIADB_DATABASE=$MARIADB_DATABASE
|
||||
|
||||
container_restart default
|
||||
|
||||
mysql_client default -u$MARIADB_USER -p$MARIADB_PASSWORD $MARIADB_DATABASE -e "INSERT INTO users(name) VALUES ('Polo')"
|
||||
|
||||
# wait for slave to sync
|
||||
sleep 60
|
||||
|
||||
run mysql_client slave0 -u$MARIADB_USER -p$MARIADB_PASSWORD $MARIADB_DATABASE -e "SELECT * FROM users\G"
|
||||
[[ "$output" =~ "name: Marko" ]]
|
||||
[[ "$output" =~ "name: Polo" ]]
|
||||
}
|
||||
|
||||
@test "Replication setup and state is preserved after deletion" {
|
||||
container_create_with_host_volumes default -d \
|
||||
-e MARIADB_REPLICATION_MODE=master \
|
||||
-e MARIADB_REPLICATION_USER=$MARIADB_REPLICATION_USER \
|
||||
-e MARIADB_REPLICATION_PASSWORD=$MARIADB_REPLICATION_PASSWORD \
|
||||
-e MARIADB_USER=$MARIADB_USER \
|
||||
-e MARIADB_PASSWORD=$MARIADB_PASSWORD \
|
||||
-e MARIADB_DATABASE=$MARIADB_DATABASE
|
||||
|
||||
mysql_client default -u$MARIADB_USER -p$MARIADB_PASSWORD $MARIADB_DATABASE -e \
|
||||
"CREATE TABLE users (id INT AUTO_INCREMENT, name VARCHAR(30), datum TIMESTAMP DEFAULT CURRENT_TIMESTAMP, PRIMARY KEY(id)); \
|
||||
INSERT INTO users(name) VALUES ('Marko');"
|
||||
|
||||
container_create_with_host_volumes slave0 -d \
|
||||
$(container_link default $CONTAINER_NAME) \
|
||||
-e MARIADB_REPLICATION_MODE=slave \
|
||||
-e MARIADB_REPLICATION_USER=$MARIADB_REPLICATION_USER \
|
||||
-e MARIADB_REPLICATION_PASSWORD=$MARIADB_REPLICATION_PASSWORD \
|
||||
-e MARIADB_MASTER_HOST=$CONTAINER_NAME \
|
||||
-e MARIADB_MASTER_USER=$MARIADB_USER \
|
||||
-e MARIADB_MASTER_PASSWORD=$MARIADB_PASSWORD \
|
||||
-e MARIADB_USER=$MARIADB_USER \
|
||||
-e MARIADB_PASSWORD=$MARIADB_PASSWORD \
|
||||
-e MARIADB_DATABASE=$MARIADB_DATABASE
|
||||
|
||||
container_remove default
|
||||
container_remove slave0
|
||||
|
||||
container_create_with_host_volumes default -d \
|
||||
-e MARIADB_REPLICATION_MODE=master
|
||||
|
||||
container_create_with_host_volumes slave0 -d \
|
||||
$(container_link default $CONTAINER_NAME) \
|
||||
-e MARIADB_REPLICATION_MODE=slave \
|
||||
-e MARIADB_DATABASE=$MARIADB_DATABASE
|
||||
|
||||
mysql_client default -u$MARIADB_USER -p$MARIADB_PASSWORD $MARIADB_DATABASE -e "INSERT INTO users(name) VALUES ('Polo')"
|
||||
|
||||
# insert new row into the master database
|
||||
mysql_client master -u$MARIADB_USER -p$MARIADB_PASSWORD $MARIADB_DATABASE -e "INSERT INTO users(name) VALUES ('Polo')"
|
||||
|
||||
# verify that all previous and new data is replicated on slave0
|
||||
run mysql_client slave0 -u$MARIADB_USER -p$MARIADB_PASSWORD $MARIADB_DATABASE -e "SELECT * FROM users\G"
|
||||
[[ "$output" =~ "name: Marko" ]]
|
||||
[[ "$output" =~ "name: Polo" ]]
|
||||
|
||||
Reference in New Issue
Block a user