Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 199dc92

Browse files
clessgLagoja
andauthored
MySQL Plugin: create and link my.cnf to allow configuring MySQL (#2468)
## Summary Adds a `$MYSQL_CONF` env var to the MySQL Plugin to allow a custom `my.cnf` (MySQL config file). MySQL does not provide an environment variable, command line flag, or anything else to change the location (it's always computed as `$MYSQL_HOME/my.cnf`), so we simply create a symlink there pointing to the user's config. ## How was it tested? - Forked devbox, made changes to the mysql plugin, and ensured everything worked in a custom project. --------- Co-authored-by: John Lago <[email protected]>
1 parent f3a5af4 commit 199dc92

File tree

9 files changed

+58
-36
lines changed

9 files changed

+58
-36
lines changed

docs/app/docs/devbox_examples/databases/mysql.md

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,11 +46,16 @@ MYSQL_BASEDIR=.devbox/nix/profile/default
4646
MYSQL_HOME=./.devbox/virtenv/mysql/run
4747
MYSQL_DATADIR=./.devbox/virtenv/mysql/data
4848
MYSQL_UNIX_PORT=./.devbox/virtenv/mysql/run/mysql.sock
49-
MYSQL_PID_FILE=./.devbox/mysql/run/mysql.pid
49+
MYSQL_PID_FILE=./.devbox/virtenv/mysql/run/mysql.pid
50+
MYSQL_CONF=./devbox.d/mysql/my.cnf
5051
```
5152

5253
### Files
5354

55+
The following helper file will be created in your project directory:
56+
57+
* \{PROJECT_DIR\}/devbox.d/mysql/my.cnf
58+
5459
The plugin will also create the following helper files in your project's `.devbox/virtenv` folder:
5560

5661
* mysql/flake.nix

plugins/builtins.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,8 @@ var builtInMap = map[*regexp.Regexp]string{
2828
regexp.MustCompile(`^(apache|apacheHttpd)$`): "apacheHttpd",
2929
regexp.MustCompile(`^(gradle|gradle_[0-9])$`): "gradle",
3030
regexp.MustCompile(`^(ghc|haskell\.compiler\.(.*))$`): "haskell",
31-
regexp.MustCompile(`^mariadb(-embedded)?_?[0-9]*$`): "mariadb",
32-
regexp.MustCompile(`^mysql?[0-9]*$`): "mysql",
31+
regexp.MustCompile(`(^mariadb(-embedded)?_?[0-9]*$|^mysql$)`): "mariadb",
32+
regexp.MustCompile(`^mysql(80|57|50)$`): "mysql",
3333
regexp.MustCompile(`^nodejs(-slim)?_?[0-9]*$`): "nodejs",
3434
regexp.MustCompile(`^php[0-9]*$`): "php",
3535
regexp.MustCompile(`^python3[0-9]*Packages.pip$`): "pip",

plugins/builtins_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ func TestBuiltInMap(t *testing.T) {
2020
"mariadb": "mariadb",
2121
"mariadb_1011": "mariadb",
2222
"mariadb-embedded": "mariadb",
23-
"mysql": "mysql",
23+
"mysql": "mariadb",
2424
"mysql80": "mysql",
2525
"python3Packages.pip": "pip",
2626
"python": "python",

plugins/mariadb.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,8 @@
1313
"{{ .Virtenv }}/run": "",
1414
"{{ .Virtenv }}/flake/flake.nix": "mariadb/flake.nix",
1515
"{{ .Virtenv }}/setup_db.sh": "mariadb/setup_db.sh",
16-
"{{ .Virtenv }}/process-compose.yaml": "mariadb/process-compose.yaml"
16+
"{{ .Virtenv }}/process-compose.yaml": "mariadb/process-compose.yaml",
17+
"{{ .DevboxDir }}/my.cnf": "mariadb/my.cnf"
1718
},
1819
"packages": {
1920
"path:{{ .Virtenv }}/flake": {},

plugins/mariadb/my.cnf

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
# MySQL configuration file
2+
3+
[mariadb]
4+
log_error=mysql.log

plugins/mariadb/setup_db.sh

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,3 +6,7 @@ if [ ! -d "$MYSQL_DATADIR" ]; then
66
--datadir=$MYSQL_DATADIR --basedir=$MYSQL_BASEDIR \
77
--pid-file=$MYSQL_PID_FILE
88
fi
9+
10+
if [ -e "$MYSQL_CONF" ]; then
11+
ln -fs "$MYSQL_CONF" "$MYSQL_HOME/my.cnf"
12+
fi

plugins/mysql.json

Lines changed: 28 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,31 @@
11
{
2-
"name": "mysql",
3-
"version": "0.0.3",
4-
"description": "* This plugin wraps mysqld and mysql_install_db to work in your local project\n* This plugin will create a new database for your project in MYSQL_DATADIR if one doesn't exist on shell init. This DB will be started in `insecure` mode, so be sure to add a root password after creation if needed.\n* Use mysqld to manually start the server, and `mysqladmin -u root shutdown` to manually stop it",
5-
"env": {
6-
"MYSQL_BASEDIR": "{{ .DevboxProfileDefault }}",
7-
"MYSQL_HOME": "{{ .Virtenv }}/run",
8-
"MYSQL_DATADIR": "{{ .Virtenv }}/data",
9-
"MYSQL_UNIX_PORT": "{{ .Virtenv }}/run/mysql.sock",
10-
"MYSQL_PID_FILE": "{{ .Virtenv }}/run/mysql.pid"
11-
},
12-
"create_files": {
13-
"{{ .Virtenv }}/run": "",
14-
"{{ .Virtenv }}/flake/flake.nix": "mysql/flake.nix",
15-
"{{ .Virtenv }}/setup_db.sh": "mysql/setup_db.sh",
16-
"{{ .Virtenv }}/process-compose.yaml": "mysql/process-compose.yaml"
17-
},
18-
"packages": {
19-
"path:{{ .Virtenv }}/flake": {},
20-
"glibcLocales": {
21-
"version": "latest",
22-
"platforms": ["x86_64-linux", "aarch64-linux"]
23-
}
24-
},
25-
"__remove_trigger_package": true,
26-
"shell": {
27-
"init_hook": [
28-
"bash {{ .Virtenv }}/setup_db.sh"
29-
]
2+
"name": "mysql",
3+
"version": "0.0.4",
4+
"description": "* This plugin wraps mysqld and mysql_install_db to work in your local project\n* This plugin will create a new database for your project in MYSQL_DATADIR if one doesn't exist on shell init. This DB will be started in `insecure` mode, so be sure to add a root password after creation if needed.\n* Use mysqld to manually start the server, and `mysqladmin -u root shutdown` to manually stop it",
5+
"env": {
6+
"MYSQL_BASEDIR": "{{ .DevboxProfileDefault }}",
7+
"MYSQL_HOME": "{{ .Virtenv }}/run",
8+
"MYSQL_DATADIR": "{{ .Virtenv }}/data",
9+
"MYSQL_UNIX_PORT": "{{ .Virtenv }}/run/mysql.sock",
10+
"MYSQL_PID_FILE": "{{ .Virtenv }}/run/mysql.pid",
11+
"MYSQL_CONF": "{{ .DevboxDir }}/my.cnf"
12+
},
13+
"create_files": {
14+
"{{ .Virtenv }}/run": "",
15+
"{{ .Virtenv }}/flake/flake.nix": "mysql/flake.nix",
16+
"{{ .Virtenv }}/setup_db.sh": "mysql/setup_db.sh",
17+
"{{ .Virtenv }}/process-compose.yaml": "mysql/process-compose.yaml",
18+
"{{ .DevboxDir }}/my.cnf": "mysql/my.cnf"
19+
},
20+
"packages": {
21+
"path:{{ .Virtenv }}/flake": {},
22+
"glibcLocales": {
23+
"version": "latest",
24+
"platforms": ["x86_64-linux", "aarch64-linux"]
3025
}
26+
},
27+
"__remove_trigger_package": true,
28+
"shell": {
29+
"init_hook": ["bash {{ .Virtenv }}/setup_db.sh"]
3130
}
31+
}

plugins/mysql/my.cnf

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
# MySQL configuration file
2+
3+
# [mysqld]
4+
# skip-log-bin

plugins/mysql/setup_db.sh

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,11 @@
11
#! bash
22

33
if [ ! -d "$MYSQL_DATADIR" ]; then
4-
# Install the Database
5-
mkdir $MYSQL_DATADIR
6-
mysqld --initialize-insecure
4+
# Install the Database
5+
mkdir $MYSQL_DATADIR
6+
mysqld --initialize-insecure
77
fi
8+
9+
if [ -e "$MYSQL_CONF" ]; then
10+
ln -fs "$MYSQL_CONF" "$MYSQL_HOME/my.cnf"
11+
fi

0 commit comments

Comments
 (0)