From 6b1a871556ca14774e9c603f6cbafe53c4e75372 Mon Sep 17 00:00:00 2001 From: Volodymyr Kolesnykov Date: Sun, 23 Jun 2024 03:52:24 +0300 Subject: [PATCH] feat(mariadb): pass extra options to `mariadb` --- features/src/mariadb/devcontainer-feature.json | 7 ++++++- features/src/mariadb/entrypoint.alpine.tpl | 6 ++++-- features/src/mariadb/entrypoint.deb.tpl | 3 ++- features/src/mariadb/install.sh | 6 ++++-- features/src/mariadb/service-run.tpl | 3 ++- 5 files changed, 18 insertions(+), 7 deletions(-) diff --git a/features/src/mariadb/devcontainer-feature.json b/features/src/mariadb/devcontainer-feature.json index e9b9bef..5507fa6 100644 --- a/features/src/mariadb/devcontainer-feature.json +++ b/features/src/mariadb/devcontainer-feature.json @@ -1,7 +1,7 @@ { "name": "MariaDB", "id": "mariadb", - "version": "1.2.0", + "version": "1.3.0", "description": "Sets up MariaDB into the Dev Environment", "options": { "installDatabaseToWorkspaces": { @@ -9,6 +9,11 @@ "default": false, "description": "Set MariaDB data directory to /workspaces/mysql-data to persist data between container rebuilds (GHCS)" }, + "extra-options": { + "type": "string", + "default": "", + "description": "Extra options to pass to the MariaDB server" + }, "install-runit-service": { "type": "boolean", "default": true, diff --git a/features/src/mariadb/entrypoint.alpine.tpl b/features/src/mariadb/entrypoint.alpine.tpl index c53d666..9308ad9 100755 --- a/features/src/mariadb/entrypoint.alpine.tpl +++ b/features/src/mariadb/entrypoint.alpine.tpl @@ -16,19 +16,21 @@ if [ ! -d "${MARIADB_DATADIR}/mysql" ]; then fi if [ -x /sbin/chpst ]; then + # shellcheck disable=SC2086,SC2154 # there could be multiple options in EXTRA_OPTIONS exec chpst -u "${MARIADB_USER}:${MARIADB_USER}" \ mysqld \ --datadir="${MARIADB_DATADIR}" \ --sql-mode=ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION \ --max_allowed_packet=67M \ --skip_networking=0 \ - --bind-address=127.0.0.1 & + --bind-address=127.0.0.1 ${EXTRA_OPTIONS} & else + # shellcheck disable=SC2086 # there could be multiple options in EXTRA_OPTIONS exec su-exec "${MARIADB_USER}:${MARIADB_USER}" \ mysqld \ --datadir="${MARIADB_DATADIR}" \ --sql-mode=ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION \ --max_allowed_packet=67M \ --skip_networking=0 \ - --bind-address=127.0.0.1 & + --bind-address=127.0.0.1 ${EXTRA_OPTIONS} & fi diff --git a/features/src/mariadb/entrypoint.deb.tpl b/features/src/mariadb/entrypoint.deb.tpl index 073f0dd..6023585 100755 --- a/features/src/mariadb/entrypoint.deb.tpl +++ b/features/src/mariadb/entrypoint.deb.tpl @@ -18,10 +18,11 @@ fi MY_UID="$(id -u "${MARIADB_USER}")" MY_GID="$(id -g "${MARIADB_USER}")" +# shellcheck disable=SC2086,SC2154 # there could be multiple options in EXTRA_OPTIONS exec setpriv --reuid="${MY_UID}" --regid="${MY_GID}" --inh-caps=-all --init-groups \ mysqld \ --datadir="${MARIADB_DATADIR}" \ --sql-mode=ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION \ --max_allowed_packet=67M \ --skip_networking=0 \ - --bind-address=127.0.0.1 & + --bind-address=127.0.0.1 ${EXTRA_OPTIONS} & diff --git a/features/src/mariadb/install.sh b/features/src/mariadb/install.sh index 40d3e0f..7ae4c51 100755 --- a/features/src/mariadb/install.sh +++ b/features/src/mariadb/install.sh @@ -14,6 +14,7 @@ echo '(*) Installing MariaDB...' : "${_REMOTE_USER:?"_REMOTE_USER is required"}" : "${INSTALLDATABASETOWORKSPACES:=}" : "${INSTALL_RUNIT_SERVICE:=true}" +: "${EXTRA_OPTIONS:=""}" if [ "${_REMOTE_USER}" = "root" ]; then MARIADB_USER=mysql @@ -93,17 +94,18 @@ fi export MARIADB_USER export MARIADB_DATADIR +export EXTRA_OPTIONS if [ "${INSTALL_RUNIT_SERVICE}" = 'true' ] && [ -d /etc/sv ]; then install -D -d -m 0755 -o root -g root /etc/service /etc/sv/mariadb # shellcheck disable=SC2016 - envsubst '$MARIADB_USER $MARIADB_DATADIR' < service-run.tpl > /etc/sv/mariadb/run && chmod 0755 /etc/sv/mariadb/run + envsubst '$MARIADB_USER $MARIADB_DATADIR $EXTRA_OPTIONS' < service-run.tpl > /etc/sv/mariadb/run && chmod 0755 /etc/sv/mariadb/run ln -sf /etc/sv/mariadb /etc/service/mariadb fi if [ -d /var/lib/entrypoint.d ]; then # shellcheck disable=SC2016 - envsubst '$MARIADB_USER $MARIADB_DATADIR' < "${ENTRYPOINT}" > /var/lib/entrypoint.d/50-mariadb + envsubst '$MARIADB_USER $MARIADB_DATADIR $EXTRA_OPTIONS' < "${ENTRYPOINT}" > /var/lib/entrypoint.d/50-mariadb chmod 0755 /var/lib/entrypoint.d/50-mariadb fi diff --git a/features/src/mariadb/service-run.tpl b/features/src/mariadb/service-run.tpl index 90cbf2d..d1c53c7 100755 --- a/features/src/mariadb/service-run.tpl +++ b/features/src/mariadb/service-run.tpl @@ -15,10 +15,11 @@ if [ ! -d "${MARIADB_DATADIR}/mysql" ]; then mysql_install_db --auth-root-authentication-method=normal --skip-test-db --user="${MARIADB_USER}" --datadir="${MARIADB_DATADIR}" fi +# shellcheck disable=SC2086,SC2154 # there could be multiple options in EXTRA_OPTIONS exec chpst -u "${MARIADB_USER}:${MARIADB_USER}" \ mysqld \ --datadir="${MARIADB_DATADIR}" \ --sql-mode=ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION \ --max_allowed_packet=67M \ --skip_networking=0 \ - --bind-address=127.0.0.1 + --bind-address=127.0.0.1 ${EXTRA_OPTIONS}