Skip to content

Migrate mariadb to s6v3 #110

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Oct 11, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/external_trigger.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ jobs:
fi
echo "**** External trigger running off of master branch. To disable this trigger, set a Github secret named \"PAUSE_EXTERNAL_TRIGGER_MARIADB_MASTER\". ****"
echo "**** Retrieving external version ****"
EXT_RELEASE=$(curl -sL "http://dl-cdn.alpinelinux.org/alpine/v3.14/main/x86_64/APKINDEX.tar.gz" | tar -xz -C /tmp \
EXT_RELEASE=$(curl -sL "http://dl-cdn.alpinelinux.org/alpine/v3.16/main/x86_64/APKINDEX.tar.gz" | tar -xz -C /tmp \
&& awk '/^P:'"mariadb"'$/,/V:/' /tmp/APKINDEX | sed -n 2p | sed 's/^V://')
if [ -z "${EXT_RELEASE}" ] || [ "${EXT_RELEASE}" == "null" ]; then
echo "**** Can't retrieve external version, exiting ****"
Expand Down
5 changes: 3 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM ghcr.io/linuxserver/baseimage-alpine:3.14
FROM ghcr.io/linuxserver/baseimage-alpine:3.16

# set version label
ARG BUILD_DATE
Expand All @@ -14,7 +14,7 @@ ENV DATADIR=$MYSQL_DIR/databases
RUN \
echo "**** install runtime packages ****" && \
if [ -z ${MARIADB_VERSION+x} ]; then \
MARIADB_VERSION=$(curl -sL "http://dl-cdn.alpinelinux.org/alpine/v3.14/main/x86_64/APKINDEX.tar.gz" | tar -xz -C /tmp \
MARIADB_VERSION=$(curl -sL "http://dl-cdn.alpinelinux.org/alpine/v3.16/main/x86_64/APKINDEX.tar.gz" | tar -xz -C /tmp \
&& awk '/^P:mariadb$/,/V:/' /tmp/APKINDEX | sed -n 2p | sed 's/^V://'); \
fi && \
apk add --no-cache \
Expand All @@ -36,4 +36,5 @@ COPY root/ /

# ports and volumes
EXPOSE 3306

VOLUME /config
5 changes: 3 additions & 2 deletions Dockerfile.aarch64
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM ghcr.io/linuxserver/baseimage-alpine:arm64v8-3.14
FROM ghcr.io/linuxserver/baseimage-alpine:arm64v8-3.16

# set version label
ARG BUILD_DATE
Expand All @@ -14,7 +14,7 @@ ENV DATADIR=$MYSQL_DIR/databases
RUN \
echo "**** install runtime packages ****" && \
if [ -z ${MARIADB_VERSION+x} ]; then \
MARIADB_VERSION=$(curl -sL "http://dl-cdn.alpinelinux.org/alpine/v3.14/main/x86_64/APKINDEX.tar.gz" | tar -xz -C /tmp \
MARIADB_VERSION=$(curl -sL "http://dl-cdn.alpinelinux.org/alpine/v3.16/main/x86_64/APKINDEX.tar.gz" | tar -xz -C /tmp \
&& awk '/^P:mariadb$/,/V:/' /tmp/APKINDEX | sed -n 2p | sed 's/^V://'); \
fi && \
apk add --no-cache \
Expand All @@ -36,4 +36,5 @@ COPY root/ /

# ports and volumes
EXPOSE 3306

VOLUME /config
5 changes: 3 additions & 2 deletions Dockerfile.armhf
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM ghcr.io/linuxserver/baseimage-alpine:arm32v7-3.14
FROM ghcr.io/linuxserver/baseimage-alpine:arm32v7-3.16

# set version label
ARG BUILD_DATE
Expand All @@ -14,7 +14,7 @@ ENV DATADIR=$MYSQL_DIR/databases
RUN \
echo "**** install runtime packages ****" && \
if [ -z ${MARIADB_VERSION+x} ]; then \
MARIADB_VERSION=$(curl -sL "http://dl-cdn.alpinelinux.org/alpine/v3.14/main/x86_64/APKINDEX.tar.gz" | tar -xz -C /tmp \
MARIADB_VERSION=$(curl -sL "http://dl-cdn.alpinelinux.org/alpine/v3.16/main/x86_64/APKINDEX.tar.gz" | tar -xz -C /tmp \
&& awk '/^P:mariadb$/,/V:/' /tmp/APKINDEX | sed -n 2p | sed 's/^V://'); \
fi && \
apk add --no-cache \
Expand All @@ -36,4 +36,5 @@ COPY root/ /

# ports and volumes
EXPOSE 3306

VOLUME /config
4 changes: 2 additions & 2 deletions Jenkinsfile
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@ pipeline {
DEV_DOCKERHUB_IMAGE = 'lsiodev/mariadb'
PR_DOCKERHUB_IMAGE = 'lspipepr/mariadb'
DIST_IMAGE = 'alpine'
DIST_TAG = '3.14'
DIST_REPO = 'http://dl-cdn.alpinelinux.org/alpine/v3.14/main/'
DIST_TAG = '3.16'
DIST_REPO = 'http://dl-cdn.alpinelinux.org/alpine/v3.16/main/'
DIST_REPO_PACKAGES = 'mariadb'
MULTIARCH='true'
CI='true'
Expand Down
5 changes: 3 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -159,11 +159,11 @@ Container images are configured using parameters passed at runtime (such as thos
| `-p 3306` | Mariadb listens on this port. |
| `-e PUID=1000` | for UserID - see below for explanation |
| `-e PGID=1000` | for GroupID - see below for explanation |
| `-e MYSQL_ROOT_PASSWORD=ROOT_ACCESS_PASSWORD` | Set this to root password for installation (minimum 4 characters). |
| `-e MYSQL_ROOT_PASSWORD=ROOT_ACCESS_PASSWORD` | Set this to root password for installation (minimum 4 characters & non-alphanumeric passwords must be properly escaped). |
| `-e TZ=Europe/London` | Specify a timezone to use EG Europe/London. |
| `-e MYSQL_DATABASE=USER_DB_NAME` | Specify the name of a database to be created on image startup. |
| `-e MYSQL_USER=MYSQL_USER` | This user will have superuser access to the database specified by MYSQL_DATABASE (do not use root here). |
| `-e MYSQL_PASSWORD=DATABASE_PASSWORD` | Set this to the password you want to use for you MYSQL_USER (minimum 4 characters). |
| `-e MYSQL_PASSWORD=DATABASE_PASSWORD` | Set this to the password you want to use for you MYSQL_USER (minimum 4 characters & non-alphanumeric passwords must be properly escaped). |
| `-e REMOTE_SQL=http://URL1/your.sql,https://URL2/your.sql` | Set this to ingest sql files from an http/https endpoint (comma seperated array). |
| `-v /config` | Contains the db itself and all assorted settings. |

Expand Down Expand Up @@ -276,6 +276,7 @@ Once registered you can define the dockerfile to use with `-f Dockerfile.aarch64

## Versions

* **11.10.22:** - Rebase master to Alpine 3.16, migrate to s6v3, remove password escape logic which caused problems for a small subset of users.
* **06.07.21:** - Rebase master to alpine.
* **03.07.21:** - Rebase to 3.14.
* **08.02.21:** - Fix new installs.
Expand Down
4 changes: 2 additions & 2 deletions jenkins-vars.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ repo_vars:
- DEV_DOCKERHUB_IMAGE = 'lsiodev/mariadb'
- PR_DOCKERHUB_IMAGE = 'lspipepr/mariadb'
- DIST_IMAGE = 'alpine'
- DIST_TAG = '3.14'
- DIST_REPO = 'http://dl-cdn.alpinelinux.org/alpine/v3.14/main/'
- DIST_TAG = '3.16'
- DIST_REPO = 'http://dl-cdn.alpinelinux.org/alpine/v3.16/main/'
- DIST_REPO_PACKAGES = 'mariadb'
- MULTIARCH='true'
- CI='true'
Expand Down
5 changes: 3 additions & 2 deletions readme-vars.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ param_container_name: "{{ project_name }}"
param_usage_include_net: false
param_usage_include_env: true
param_env_vars:
- { env_var: "MYSQL_ROOT_PASSWORD", env_value: "ROOT_ACCESS_PASSWORD", desc: "Set this to root password for installation (minimum 4 characters)." }
- { env_var: "MYSQL_ROOT_PASSWORD", env_value: "ROOT_ACCESS_PASSWORD", desc: "Set this to root password for installation (minimum 4 characters & non-alphanumeric passwords must be properly escaped)." }
- { env_var: "TZ", env_value: "Europe/London", desc: "Specify a timezone to use EG Europe/London." }
param_usage_include_vols: true
param_volumes:
Expand All @@ -41,7 +41,7 @@ opt_param_usage_include_env: true
opt_param_env_vars:
- { env_var: "MYSQL_DATABASE", env_value: "USER_DB_NAME", desc: "Specify the name of a database to be created on image startup." }
- { env_var: "MYSQL_USER", env_value: "MYSQL_USER", desc: "This user will have superuser access to the database specified by MYSQL_DATABASE (do not use root here)." }
- { env_var: "MYSQL_PASSWORD", env_value: "DATABASE_PASSWORD", desc: "Set this to the password you want to use for you MYSQL_USER (minimum 4 characters)." }
- { env_var: "MYSQL_PASSWORD", env_value: "DATABASE_PASSWORD", desc: "Set this to the password you want to use for you MYSQL_USER (minimum 4 characters & non-alphanumeric passwords must be properly escaped)." }
- { env_var: "REMOTE_SQL", env_value: "http://URL1/your.sql,https://URL2/your.sql", desc: "Set this to ingest sql files from an http/https endpoint (comma seperated array)." }
opt_param_usage_include_vols: false
opt_param_usage_include_ports: false
Expand Down Expand Up @@ -96,6 +96,7 @@ app_setup_block: |

# changelog
changelogs:
- { date: "11.10.22:", desc: "Rebase master to Alpine 3.16, migrate to s6v3, remove password escape logic which caused problems for a small subset of users." }
- { date: "06.07.21:", desc: "Rebase master to alpine." }
- { date: "03.07.21:", desc: "Rebase to 3.14." }
- { date: "08.02.21:", desc: "Fix new installs." }
Expand Down
22 changes: 0 additions & 22 deletions root/etc/cont-init.d/30-config

This file was deleted.

27 changes: 27 additions & 0 deletions root/etc/s6-overlay/s6-rc.d/init-mariadb-config/run
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
#!/usr/bin/with-contenv bash

# make folders if required
mkdir -p \
"${DATADIR}" \
/config/log/mysql \
/var/run/mysqld

# configure mariadb-server.cnf
sed -i "s|.*skip-networking.*|#skip-networking|g" /etc/my.cnf.d/mariadb-server.cnf

# setup custom cnf file
if [[ ! -f /config/custom.cnf ]]; then
cp /defaults/my.cnf /config/custom.cnf
fi

if [[ ! -L /etc/my.cnf.d/custom.cnf && -f /etc/my.cnf.d/custom.cnf ]]; then
rm /etc/my.cnf.d/custom.cnf
fi

if [[ ! -L /etc/my.cnf.d/custom.cnf ]]; then
ln -s /config/custom.cnf /etc/my.cnf.d/custom.cnf
fi

# set permissions
chmod -R 777 \
/var/run/mysqld
1 change: 1 addition & 0 deletions root/etc/s6-overlay/s6-rc.d/init-mariadb-config/type
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
oneshot
1 change: 1 addition & 0 deletions root/etc/s6-overlay/s6-rc.d/init-mariadb-config/up
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/etc/s6-overlay/s6-rc.d/init-mariadb-config/run
35 changes: 17 additions & 18 deletions root/etc/cont-init.d/40-initialise-db → ...6-overlay/s6-rc.d/init-mariadb-initdb/run
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,10 @@ start_mysql(){

# test for existence of mysql folder in datadir and start initialise if not present
# BEGIN: No indentation due to heredocs
if [ ! -d "${DATADIR}/mysql" ]; then
if [[ ! -d "${DATADIR}/mysql" ]]; then

# load env file if it exists
if [ -f "/config/env" ]; then
if [[ -f "/config/env" ]]; then
source /config/env
fi

Expand All @@ -31,33 +31,32 @@ EOSQL
NOPASS_SET=$(mktemp)
cat > "${NOPASS_SET}" <<-EOFPASS
#################################################################
# No root password or too short a password ,min of 4 characters #
# No root password will be set, this is not a good thing #
# You shoud set one after initialisation with the command #
# mysqladmin -u root password <PASSWORD> #
# No root password or too short a password, min of 4 characters #
# No root password will be set, this is not a good thing #
# You shoud set one after initialisation with the command #
# mysqladmin -u root password <PASSWORD> #
#################################################################
EOFPASS

# test for empty password variable, if it's set to 0 or less than 4 characters
if [ -z "${MYSQL_ROOT_PASSWORD}" ]; then
if [[ -z "${MYSQL_ROOT_PASSWORD}" ]]; then
TEST_LEN="0"
else
TEST_LEN=${#MYSQL_ROOT_PASSWORD}
fi
MYSQL_ROOT_PASSWORD=$(sed -E 's/('\'')/\\\1/g' <<< "${MYSQL_ROOT_PASSWORD}")
if [ "${TEST_LEN}" -lt "4" ]; then

if [[ "${TEST_LEN}" -lt "4" ]]; then
MYSQL_PASS="CREATE USER 'root'@'%' IDENTIFIED BY '' ;"
else
MYSQL_PASS="CREATE USER 'root'@'%' IDENTIFIED BY '${MYSQL_ROOT_PASSWORD}' ;"
fi

# Make sure all user and database settings are set and pass is more than 4 characters
# At the end change to default database created with environment variables to run init and remote scripts there
if [ "${MYSQL_USER+x}" ] && \
[ "${MYSQL_DATABASE+x}" ] && \
[ "${MYSQL_PASSWORD+x}" ] && \
[ "${#MYSQL_PASSWORD}" -gt "3" ]; then
MYSQL_PASSWORD=$(sed -E 's/('\'')/\\\1/g' <<< "${MYSQL_PASSWORD}")
if [[ "${MYSQL_USER+x}" ]] && \
[[ "${MYSQL_DATABASE+x}" ]] && \
[[ "${MYSQL_PASSWORD+x}" ]] && \
[[ "${#MYSQL_PASSWORD}" -gt "3" ]]; then
read -r -d '' MYSQL_DB_SETUP << EOM
CREATE DATABASE \`${MYSQL_DATABASE}\`;
CREATE USER '${MYSQL_USER}'@'%' IDENTIFIED BY '${MYSQL_PASSWORD}';
Expand All @@ -77,18 +76,18 @@ EONEWSQL
echo "Setting Up Initial Databases"

# add all sql from a user defined directory on first init
if [ -e "/config/initdb.d" ] && [ -n "$(/bin/ls -A /config/initdb.d/*.sql 2>/dev/null)" ]; then
if [[ -e "/config/initdb.d" ]] && [[ -n "$(/bin/ls -A /config/initdb.d/*.sql 2>/dev/null)" ]]; then
cat /config/initdb.d/*.sql >> "${tempSqlFile}"
fi

chown -R abc:abc "${tempSqlFile}"


# ingest remote sql if REMOTE_SQL is set
if [ -n "${REMOTE_SQL+set}" ]; then
if [[ -n "${REMOTE_SQL+set}" ]]; then
IFS=, read -ra URLS <<< "${REMOTE_SQL}"
for URL in "${URLS[@]}"; do
if [ "$(curl -I -sL -w "%{http_code}" "${URL}" -o /dev/null)" == 200 ]; then
if [[ "$(curl -I -sL -w "%{http_code}" "${URL}" -o /dev/null)" == 200 ]]; then
curl -sL "${URL}" >> "${tempSqlFile}"
fi
done
Expand All @@ -109,7 +108,7 @@ wait "${pid}"
echo "Database Setup Completed"

# display a message about password if not set or too short
if [ "${TEST_LEN}" -lt "4" ]; then
if [[ "${TEST_LEN}" -lt "4" ]]; then
printf '\n\n\n%s\n\n\n' "$(<"${NOPASS_SET}")"
sleep 5s
fi
Expand Down
1 change: 1 addition & 0 deletions root/etc/s6-overlay/s6-rc.d/init-mariadb-initdb/type
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
oneshot
1 change: 1 addition & 0 deletions root/etc/s6-overlay/s6-rc.d/init-mariadb-initdb/up
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/etc/s6-overlay/s6-rc.d/init-mariadb-initdb/run
Empty file.
5 changes: 5 additions & 0 deletions root/etc/s6-overlay/s6-rc.d/svc-mariadb/finish
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#!/usr/bin/with-contenv bash

echo "Caught SIGTERM signal!"

kill -TERM "$(cat /var/run/mysqld/mysqld.pid)" 2>/dev/null
1 change: 1 addition & 0 deletions root/etc/s6-overlay/s6-rc.d/svc-mariadb/notification-fd
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
3
10 changes: 10 additions & 0 deletions root/etc/s6-overlay/s6-rc.d/svc-mariadb/run
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#!/usr/bin/with-contenv bash

s6-notifyoncheck -d -n 300 -w 1000 -c "nc -z localhost 3306" \
s6-setuidgid abc \
/usr/bin/mariadbd-safe \
--datadir="${DATADIR}" \
--pid-file=/var/run/mysqld/mysqld.pid \
--user=abc &

wait
1 change: 1 addition & 0 deletions root/etc/s6-overlay/s6-rc.d/svc-mariadb/type
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
longrun
Empty file.
Empty file.
Empty file.
17 changes: 0 additions & 17 deletions root/etc/services.d/mariadb/run

This file was deleted.