Skip to content

Commit

Permalink
Merge pull request #265 from Automattic/mariadb-extra-options
Browse files Browse the repository at this point in the history
feat(mariadb): pass extra options to `mariadb`
  • Loading branch information
sjinks authored Jun 23, 2024
2 parents 94776c3 + 6b1a871 commit 9269733
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 7 deletions.
7 changes: 6 additions & 1 deletion features/src/mariadb/devcontainer-feature.json
Original file line number Diff line number Diff line change
@@ -1,14 +1,19 @@
{
"name": "MariaDB",
"id": "mariadb",
"version": "1.2.0",
"version": "1.3.0",
"description": "Sets up MariaDB into the Dev Environment",
"options": {
"installDatabaseToWorkspaces": {
"type": "boolean",
"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,
Expand Down
6 changes: 4 additions & 2 deletions features/src/mariadb/entrypoint.alpine.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -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
3 changes: 2 additions & 1 deletion features/src/mariadb/entrypoint.deb.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -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} &
6 changes: 4 additions & 2 deletions features/src/mariadb/install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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

Expand Down
3 changes: 2 additions & 1 deletion features/src/mariadb/service-run.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -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}

0 comments on commit 9269733

Please sign in to comment.