forked from sclorg/mysql-container
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implement s2i and general extendability support
This is very similar to the MariaDB: sclorg/mariadb-container#45 It adds extending support using [source-to-image](https://github.com/openshift/source-to-image). For example to build customized MySQL database image `my-mysql-centos7` with configuration in `~/image-configuration/` run: ``` $ s2i build ~/image-configuration/ centos/mysql-57-centos7 my-mysql-centos7 ``` The directory passed to `s2i build` can contain these directories: - `mysql-cfg/` - when starting the container, files from this directory will be used as a configuration for the `mysqld` daemon - `envsubst` command is run on this file to still allow customization of the image using environmental variables - `mysql-pre-init/` - shell scripts (`*.sh`) available in this directory are sourced before `mysqld` daemon is started - `mysql-init/` - shell scripts (`*.sh`) available in this directory are sourced when `mysqld` daemon is started locally - in this phase, use `${mysql_flags}` to connect to the locally running daemon, for example `mysql $mysql_flags < dump.sql` Variables that can be used in the scripts provided to s2i: - `$mysql_flags` -- arguments for the `mysql` tool that will connect to the locally running `mysqld` during initialization - `$MYSQL_RUNNING_AS_MASTER` -- variable defined when the container is run with `run-mysqld-master` command - `$MYSQL_RUNNING_AS_SLAVE` -- variable defined when the container is run with `run-mysqld-slave` command - `$MYSQL_DATADIR_FIRST_INIT` -- variable defined when the container was initialized from the empty data dir During `s2i build` all provided files are copied into `/opt/app-root/src` directory into the resulting image. If some configuration files are present in the destination directory, files with the same name are overwritten. Also only one file with the same name can be used for customization and user provided files are preferred over default files in `/usr/share/container-scripts/mysql/`- so it is possible to overwrite them. Same configuration directory structure can be used to customize the image every time the image is started using `docker run`. The directory has to be mounted into `/opt/app-root/src/` in the image (`-v ./image-configuration/:/opt/app-root/src/`). This overwrites customization built into the image.
- Loading branch information
Showing
42 changed files
with
601 additions
and
112 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
../s2i-common/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
../s2i-common/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
[mysqld] | ||
query-cache-limit=262144 | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
CREATE TABLE products (id INTEGER, name VARCHAR(256), price FLOAT, variant INTEGER); | ||
CREATE TABLE products_variant (id INTEGER, name VARCHAR(256)); | ||
INSERT INTO products_variant (id, name) VALUES ('1', 'blue'), ('2', 'green'); | ||
|
17 changes: 17 additions & 0 deletions
17
examples/extend-image/mysql-init/80-add-arbitrary-users.sh
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
create_arbitrary_users() { | ||
# Do not care what option is compulsory here, just create what is specified | ||
log_info "Creating user specified by MYSQL_OPERATIONS_USER (${MYSQL_OPERATIONS_USER}) ..." | ||
mysql $mysql_flags <<EOSQL | ||
CREATE USER '${MYSQL_OPERATIONS_USER}'@'%' IDENTIFIED BY '${MYSQL_OPERATIONS_PASSWORD}'; | ||
EOSQL | ||
|
||
log_info "Granting privileges to user ${MYSQL_OPERATIONS_USER} for ${MYSQL_DATABASE} ..." | ||
mysql $mysql_flags <<EOSQL | ||
GRANT ALL ON \`${MYSQL_DATABASE}\`.* TO '${MYSQL_OPERATIONS_USER}'@'%' ; | ||
FLUSH PRIVILEGES ; | ||
EOSQL | ||
} | ||
|
||
if ! [ -v MYSQL_RUNNING_AS_SLAVE ]; then | ||
create_arbitrary_users | ||
fi |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
init_arbitrary_database() { | ||
local thisdir | ||
local init_data_file | ||
thisdir=$(dirname ${BASH_SOURCE[0]}) | ||
init_data_file=$(readlink -f ${thisdir}/../mysql-data/init.sql) | ||
log_info "Initializing the arbitrary database from file ${init_data_file}..." | ||
mysql $mysql_flags ${MYSQL_DATABASE} < ${init_data_file} | ||
} | ||
|
||
if ! [ -v MYSQL_RUNNING_AS_SLAVE ] && $MYSQL_DATADIR_FIRST_INIT ; then | ||
init_arbitrary_database | ||
fi |
10 changes: 10 additions & 0 deletions
10
examples/extend-image/mysql-pre-init/80-check-arbitrary-users.sh
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
check_arbitrary_users() { | ||
if ! [[ -v MYSQL_OPERATIONS_USER && -v MYSQL_OPERATIONS_PASSWORD && -v MYSQL_DATABASE ]]; then | ||
echo "You need to specify all these variables: MYSQL_OPERATIONS_USER, MYSQL_OPERATIONS_PASSWORD, and MYSQL_DATABASE" | ||
return 1 | ||
fi | ||
} | ||
|
||
if ! [ -v MYSQL_RUNNING_AS_SLAVE ]; then | ||
check_arbitrary_users | ||
fi |
Oops, something went wrong.