push docker version

This commit is contained in:
2025-08-21 18:36:36 +02:00
parent f3427963e9
commit 421bc13383
21 changed files with 4815 additions and 109 deletions
+85
View File
@@ -0,0 +1,85 @@
ARG DEBIAN_FRONTEND=noninteractive
ARG VMANGOS_REPOSITORY_URL=https://github.com/vmangos/core.git
ARG VMANGOS_REVISION=development
ARG VMANGOS_WORLD_DB_REPOSITORY_URL=https://github.com/brotalnia/database.git
ARG VMANGOS_WORLD_DB_DUMP_NAME=world_full_14_june_2021
ARG VMANGOS_WORLD_DB_DUMP_NEW_FILE=/sql/world-new.sql
FROM mariadb:11.8 AS setup
ARG DEBIAN_FRONTEND
ARG VMANGOS_REPOSITORY_URL
ARG VMANGOS_REVISION
ARG VMANGOS_WORLD_DB_REPOSITORY_URL
ARG VMANGOS_WORLD_DB_DUMP_NAME
RUN \
apt update -y && \
apt install -y \
git \
p7zip-full && \
git clone "${VMANGOS_REPOSITORY_URL}" /core && \
cd /core && \
git checkout "${VMANGOS_REVISION}" && \
git clone "${VMANGOS_WORLD_DB_REPOSITORY_URL}" /database && \
mkdir -p /sql/custom && \
mkdir -p /sql/migrations && \
cd /core/sql && \
mv characters.sql /sql && \
mv logon.sql /sql && \
mv logs.sql /sql && \
cd /core/sql/migrations && \
chmod +x merge.sh && \
./merge.sh && \
mv characters_db_updates.sql /sql/migrations && \
mv logon_db_updates.sql /sql/migrations && \
mv logs_db_updates.sql /sql/migrations && \
mv world_db_updates.sql /sql/migrations && \
cd /database && \
7z e ${VMANGOS_WORLD_DB_DUMP_NAME}.7z && \
mv ${VMANGOS_WORLD_DB_DUMP_NAME}.sql /sql/world.sql && \
rm -rf /core /database && \
apt remove -y \
git \
p7zip-full && \
apt autoremove -y && \
apt clean -y && \
rm -rf /var/lib/apt/lists/*
FROM mariadb:11.8
ARG VMANGOS_WORLD_DB_DUMP_NEW_FILE
ENV MARIADB_AUTO_UPGRADE=1
ENV MARIADB_USER=mangos
ENV MARIADB_PASSWORD=mangos
ENV MARIADB_ROOT_PASSWORD=password
ENV VMANGOS_REALMLIST_NAME=VMaNGOS
ENV VMANGOS_REALMLIST_ADDRESS=127.0.0.1
ENV VMANGOS_REALMLIST_PORT=8085
ENV VMANGOS_REALMLIST_ICON=1
ENV VMANGOS_REALMLIST_TIMEZONE=0
ENV VMANGOS_REALMLIST_ALLOWED_SECURITY_LEVEL=0
ENV VMANGOS_WORLD_DB_DUMP_NEW_FILE=${VMANGOS_WORLD_DB_DUMP_NEW_FILE}
ENV VMANGOS_ENABLE_AUTOMATIC_WORLD_DB_CORRECTIONS=1
ENV VMANGOS_PROCESS_CUSTOM_SQL=1
COPY --from=setup /sql /sql
RUN \
mkdir -p /opt/scripts && \
mkdir /always-initdb.d
COPY ./docker/database/db-functions.sh /opt/scripts
COPY ./docker/database/create-db.sh /docker-entrypoint-initdb.d
COPY ./docker/database/update-db.sh /always-initdb.d
COPY ./docker/database/docker-entrypoint.sh /entrypoint.sh
RUN \
chmod +x /docker-entrypoint-initdb.d/create-db.sh && \
chmod +x /always-initdb.d/update-db.sh && \
chmod +x /entrypoint.sh
ENTRYPOINT ["/entrypoint.sh"]
CMD ["mariadbd"]
+41
View File
@@ -0,0 +1,41 @@
#!/usr/bin/env bash
. "/opt/scripts/db-functions.sh"
if [ "${VMANGOS_ENABLE_AUTOMATIC_WORLD_DB_CORRECTIONS:-0}" = "1" ]; then
echo "[vmangos-deploy]: [x] Automatic world database corrections are enabled"
else
echo "[vmangos-deploy]: [ ] Automatic world database corrections are disabled"
fi
if [ "${VMANGOS_PROCESS_CUSTOM_SQL:-0}" = "1" ]; then
echo "[vmangos-deploy]: [x] Custom SQL processing is enabled"
else
echo "[vmangos-deploy]: [ ] Custom SQL processing is disabled"
fi
create_database "mangos"
create_database "characters"
create_database "realmd"
create_database "logs"
grant_permissions "mangos"
grant_permissions "characters"
grant_permissions "realmd"
grant_permissions "logs"
import_dump "mangos" "/sql/world.sql"
import_dump "characters" "/sql/characters.sql"
import_dump "realmd" "/sql/logon.sql"
import_dump "logs" "/sql/logs.sql"
import_updates "mangos" "/sql/migrations/world_db_updates.sql"
import_updates "characters" "/sql/migrations/characters_db_updates.sql"
import_updates "realmd" "/sql/migrations/logon_db_updates.sql"
import_updates "logs" "/sql/migrations/logs_db_updates.sql"
configure_realm
if [ "${VMANGOS_PROCESS_CUSTOM_SQL:-0}" = "1" ]; then
process_custom_sql "/sql/custom"
fi
+172
View File
@@ -0,0 +1,172 @@
#!/usr/bin/env bash
create_database() {
local db_name="$1"
local silent=${2:-false}
if [ "$silent" = false ]; then
echo "[vmangos-deploy]: Creating database '$db_name'"
fi
mariadb -u root -p"$MARIADB_ROOT_PASSWORD" -e \
"CREATE DATABASE IF NOT EXISTS \`$db_name\` DEFAULT CHARSET utf8 COLLATE utf8_general_ci;"
}
drop_database() {
local db_name="$1"
local silent=${2:-false}
if [ "$silent" = false ]; then
echo "[vmangos-deploy]: Dropping database '$db_name'"
fi
mariadb -u root -p"$MARIADB_ROOT_PASSWORD" -e \
"DROP DATABASE IF EXISTS \`$db_name\`;"
}
grant_permissions() {
local db_name="$1"
local silent=${2:-false}
if [ "$silent" = false ]; then
echo "[vmangos-deploy]: Granting permissions to database user '$MARIADB_USER' for database '$db_name'"
fi
mariadb -u root -p"$MARIADB_ROOT_PASSWORD" -e \
"GRANT ALL ON \`$db_name\`.* TO '$MARIADB_USER'@'%'; \
FLUSH PRIVILEGES;"
}
import_data() {
local db_name="$1"
local file="$2"
mariadb -u root -p"$MARIADB_ROOT_PASSWORD" "$db_name" < "$file"
return $?
}
import_dump() {
local db_name="$1"
local dump_file="$2"
echo "[vmangos-deploy]: Importing initial data for database '$db_name'"
import_data "$db_name" "$dump_file"
return $?
}
import_updates() {
local db_name="$1"
local update_file="$2"
if [ ! -e "$update_file" ]; then
# The update file not existing is not an error, so we return 0 (success)
# here
return 0
fi
echo "[vmangos-deploy]: Importing potential updates for database '$db_name'"
import_data "$db_name" "$update_file"
return $?
}
configure_realm() {
echo "[vmangos-deploy]: Configuring realm '$VMANGOS_REALMLIST_NAME'"
mariadb -u root -p"$MARIADB_ROOT_PASSWORD" "realmd" -e \
"INSERT INTO \`realmlist\` (\`name\`, \`address\`, \`port\`, \`icon\`, \`timezone\`, \`allowedSecurityLevel\`) VALUES ('$VMANGOS_REALMLIST_NAME', '$VMANGOS_REALMLIST_ADDRESS', '$VMANGOS_REALMLIST_PORT', '$VMANGOS_REALMLIST_ICON', '$VMANGOS_REALMLIST_TIMEZONE', '$VMANGOS_REALMLIST_ALLOWED_SECURITY_LEVEL');"
}
create_world_db_corrections_table() {
mariadb -u root -p"$MARIADB_ROOT_PASSWORD" "maintenance" -e \
"CREATE TABLE IF NOT EXISTS \`world_db_corrections\` ( \
\`id\` INT NOT NULL, \
\`reason\` VARCHAR(255) NOT NULL, \
\`date\` DATE NOT NULL, \
\`is_applied\` BOOLEAN NOT NULL DEFAULT FALSE, \
PRIMARY KEY (\`id\`) \
);"
}
populate_world_db_corrections_table() {
mariadb -u root -p"$MARIADB_ROOT_PASSWORD" "maintenance" -e \
"INSERT INTO \`world_db_corrections\` (\`id\`, \`reason\`, \`date\`) \
SELECT 1, 'migration edits in vmangos/core@fe6fcb4', '2025-02-22' \
WHERE NOT EXISTS ( \
SELECT 1 FROM \`world_db_corrections\` WHERE \`id\` = 1 \
); \
INSERT INTO \`world_db_corrections\` (\`id\`, \`reason\`, \`date\`) \
SELECT 2, 'migration edits in vmangos/core@9e6d4ac', '2025-02-23' \
WHERE NOT EXISTS ( \
SELECT 2 FROM \`world_db_corrections\` WHERE \`id\` = 2 \
); \
INSERT INTO \`world_db_corrections\` (\`id\`, \`reason\`, \`date\`) \
SELECT 3, 'migration edits in vmangos/core@07c7832', '2025-02-25' \
WHERE NOT EXISTS ( \
SELECT 3 FROM \`world_db_corrections\` WHERE \`id\` = 3 \
); \
INSERT INTO \`world_db_corrections\` (\`id\`, \`reason\`, \`date\`) \
SELECT 4, 'migration edits in vmangos/core@f485dfa', '2025-03-22' \
WHERE NOT EXISTS ( \
SELECT 4 FROM \`world_db_corrections\` WHERE \`id\` = 4 \
); \
INSERT INTO \`world_db_corrections\` (\`id\`, \`reason\`, \`date\`) \
SELECT 5, 'migration edits in vmangos/core@33fcf97', '2025-07-05' \
WHERE NOT EXISTS ( \
SELECT 5 FROM \`world_db_corrections\` WHERE \`id\` = 5 \
);"
}
check_if_world_db_correction_is_required() {
local result=$(mariadb -u root -p"$MARIADB_ROOT_PASSWORD" "maintenance" -N -s -e \
"WITH
db_creation AS (
SELECT DATE(CONVERT_TZ(MIN(\`CREATE_TIME\`), @@session.time_zone, '+00:00')) as world_db_created_at
FROM \`INFORMATION_SCHEMA\`.\`TABLES\`
WHERE \`TABLE_SCHEMA\` = 'mangos'
),
latest_correction AS (
SELECT DATE(\`date\`) as correction_date, \`reason\`, \`is_applied\`
FROM \`world_db_corrections\`
WHERE \`id\` = (SELECT MAX(\`id\`) FROM \`world_db_corrections\`)
)
SELECT CONCAT_WS('|',
IF(
NOT \`is_applied\` AND correction_date >= world_db_created_at,
'true',
'false'
),
\`reason\`
)
FROM latest_correction, db_creation;")
echo "$result"
}
mark_world_db_corrections_as_applied() {
mariadb -u root -p"$MARIADB_ROOT_PASSWORD" "maintenance" -e \
"UPDATE \`world_db_corrections\` SET \`is_applied\` = true;"
}
process_custom_sql() {
local file_directory="$1"
if [ ! -d "$file_directory" ]; then
echo "[vmangos-deploy]: WARNING: Custom SQL file directory '$file_directory' does not exist" >&2
return 0
fi
file_count=$(find "$file_directory" -name "*.sql" -type f | wc -l)
echo "[vmangos-deploy]: Found $file_count custom SQL file(s) to process"
if [ "$file_count" -gt 0 ]; then
find "$file_directory" -name "*.sql" -type f | sort | while read -r sql_file; do
echo "[vmangos-deploy]: Processing custom SQL file '$(basename "$sql_file")'"
import_data "mangos" "$sql_file"
if [ $? -ne 0 ]; then
echo "[vmangos-deploy]: ERROR: Failed to process custom SQL file '$(basename "$sql_file")'" >&2
fi
done
fi
}
+100
View File
@@ -0,0 +1,100 @@
#!/usr/bin/env bash
set -eo pipefail
source "$(which docker-entrypoint.sh)"
docker_mariadb_upgrade_including_user_tables() {
if [ -z "$MARIADB_AUTO_UPGRADE" ] \
|| [ "$MARIADB_AUTO_UPGRADE" = 0 ]; then
mysql_note "MariaDB upgrade (mariadb-upgrade or creating healthcheck users) required, but skipped due to \$MARIADB_AUTO_UPGRADE setting"
return
fi
mysql_note "Starting temporary server"
docker_temp_server_start "$@" --skip-grant-tables \
--loose-innodb_buffer_pool_dump_at_shutdown=0
mysql_note "Temporary server started."
docker_mariadb_backup_system
if [ ! -f "$DATADIR"/.my-healthcheck.cnf ]; then
mysql_note "Creating healthcheck users"
local createHealthCheckUsers
createHealthCheckUsers=$(create_healthcheck_users)
docker_process_sql --dont-use-mysql-root-password --binary-mode <<-EOSQL
-- Healthcheck users shouldn't be replicated
SET @@SESSION.SQL_LOG_BIN=0;
-- we need the SQL_MODE NO_BACKSLASH_ESCAPES mode to be clear for the password to be set
SET @@SESSION.SQL_MODE=REPLACE(@@SESSION.SQL_MODE, 'NO_BACKSLASH_ESCAPES', '');
FLUSH PRIVILEGES;
$createHealthCheckUsers
EOSQL
mysql_note "Stopping temporary server"
docker_temp_server_stop
mysql_note "Temporary server stopped"
if _check_if_upgrade_is_needed; then
# need a restart as FLUSH PRIVILEGES isn't reversable
mysql_note "Restarting temporary server for upgrade"
docker_temp_server_start "$@" --skip-grant-tables \
--loose-innodb_buffer_pool_dump_at_shutdown=0
else
return 0
fi
fi
mysql_note "Starting mariadb-upgrade"
mariadb-upgrade
mysql_note "Finished mariadb-upgrade"
mysql_note "Stopping temporary server"
docker_temp_server_stop
mysql_note "Temporary server stopped"
}
mysql_note "Custom entrypoint script for MariaDB Server ${MARIADB_VERSION} started."
mysql_check_config "$@"
# Load various environment variables
docker_setup_env "$@"
docker_create_db_directories
# If container is started as root user, restart as dedicated mysql user
if [ "$(id -u)" = "0" ]; then
mysql_note "Switching to dedicated user 'mysql'"
exec gosu mysql "${BASH_SOURCE[0]}" "$@"
fi
# there's no database, so it needs to be initialized
if [ -z "$DATABASE_ALREADY_EXISTS" ]; then
docker_verify_minimum_env
docker_mariadb_init "$@"
# run always-run hooks if they exist
elif test -n "$(shopt -s nullglob; echo /always-initdb.d/*)"; then
# MDEV-27636 mariadb_upgrade --check-if-upgrade-is-needed cannot be run offline
#if mariadb-upgrade --check-if-upgrade-is-needed; then
if _check_if_upgrade_is_needed; then
docker_mariadb_upgrade_including_user_tables "$@"
fi
mysql_note "Starting temporary server"
docker_temp_server_start "$@"
mysql_note "Temporary server started."
docker_process_init_files /always-initdb.d/*
mysql_note "Stopping temporary server"
docker_temp_server_stop
mysql_note "Temporary server stopped"
echo
mysql_note "MariaDB init process done. Ready for start up."
echo
# MDEV-27636 mariadb_upgrade --check-if-upgrade-is-needed cannot be run offline
#elif mariadb-upgrade --check-if-upgrade-is-needed; then
elif _check_if_upgrade_is_needed; then
docker_mariadb_upgrade_including_user_tables "$@"
fi
exec "$@"
+74
View File
@@ -0,0 +1,74 @@
#!/usr/bin/env bash
# vmangos-deploy
# Copyright (C) 2023-2025 Michael Serajnik https://github.com/mserajnik
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
. "/opt/scripts/db-functions.sh"
if [ "${VMANGOS_ENABLE_AUTOMATIC_WORLD_DB_CORRECTIONS:-0}" = "1" ]; then
echo "[vmangos-deploy]: [x] Automatic world database corrections are enabled"
else
echo "[vmangos-deploy]: [ ] Automatic world database corrections are disabled"
fi
if [ "${VMANGOS_PROCESS_CUSTOM_SQL:-0}" = "1" ]; then
echo "[vmangos-deploy]: [x] Custom SQL processing is enabled"
else
echo "[vmangos-deploy]: [ ] Custom SQL processing is disabled"
fi
if [ "${VMANGOS_ENABLE_AUTOMATIC_WORLD_DB_CORRECTIONS:-0}" = "1" ]; then
create_database "maintenance" true
grant_permissions "maintenance" true
create_world_db_corrections_table
populate_world_db_corrections_table
result=$(check_if_world_db_correction_is_required)
requires_correction=$(echo "$result" | cut -d'|' -f1)
reason=$(echo "$result" | cut -d'|' -f2)
if [ "$requires_correction" = "true" ]; then
echo "[vmangos-deploy]: World database correction required because of $reason, re-creating world database"
drop_database "mangos"
create_database "mangos"
grant_permissions "mangos"
import_dump "mangos" "/sql/world.sql"
mark_world_db_corrections_as_applied
fi
else
echo "[vmangos-deploy]: Automatic world database corrections are disabled"
drop_database "maintenance" true
fi
if [ -e "$VMANGOS_WORLD_DB_DUMP_NEW_FILE" ]; then
echo "[vmangos-deploy]: '$VMANGOS_WORLD_DB_DUMP_NEW_FILE' exists, re-creating world database"
drop_database "mangos"
create_database "mangos"
grant_permissions "mangos"
import_dump "mangos" "$VMANGOS_WORLD_DB_DUMP_NEW_FILE"
fi
import_updates "mangos" "/sql/migrations/world_db_updates.sql"
import_updates "characters" "/sql/migrations/characters_db_updates.sql"
import_updates "realmd" "/sql/migrations/logon_db_updates.sql"
import_updates "logs" "/sql/migrations/logs_db_updates.sql"
if [ "${VMANGOS_PROCESS_CUSTOM_SQL:-0}" = "1" ]; then
process_custom_sql "/sql/custom"
fi