diff --git a/Dockerfile b/Dockerfile index 9502a57..5ef226d 100644 --- a/Dockerfile +++ b/Dockerfile @@ -3,12 +3,25 @@ FROM mariadb:11.5.2 # Set environment variables ENV TZ=America/Montreal +ENV TEMP_SQL_DIR=/temp-sql-files + +# Set the shell for safer execution +SHELL ["/bin/bash", "-o", "pipefail", "-c"] # Create a non-root user and group RUN groupadd -r dbuser && useradd -r -g dbuser dbuser -# Copy SQL files and set ownership -COPY *.sql /docker-entrypoint-initdb.d/ +# Copy all files into a temporary location +COPY . ${TEMP_SQL_DIR}/ + +# Flatten the directory structure and rename files to include folder names +RUN find "${TEMP_SQL_DIR:?}/" -type f -name "*.sql" | while read -r file; do \ + new_name=$(echo "$file" | sed "s|${TEMP_SQL_DIR:?}/||" | sed 's|/|_|g' | sed 's|^_||'); \ + cp "$file" "/docker-entrypoint-initdb.d/$new_name"; \ + done && \ + rm -rf "${TEMP_SQL_DIR:?}/" + +# Set ownership RUN chown -R dbuser:dbuser /docker-entrypoint-initdb.d # Ensure proper permissions for MariaDB directories diff --git a/procedures_auth.sql b/procedures/auth.sql similarity index 100% rename from procedures_auth.sql rename to procedures/auth.sql diff --git a/procedures_get_battle.sql b/procedures/get/battle.sql similarity index 100% rename from procedures_get_battle.sql rename to procedures/get/battle.sql diff --git a/procedures_get_building.sql b/procedures/get/building.sql similarity index 100% rename from procedures_get_building.sql rename to procedures/get/building.sql diff --git a/procedures_get_city.sql b/procedures/get/city.sql similarity index 100% rename from procedures_get_city.sql rename to procedures/get/city.sql diff --git a/procedures_get_island.sql b/procedures/get/island.sql similarity index 100% rename from procedures_get_island.sql rename to procedures/get/island.sql diff --git a/procedures_get_player.sql b/procedures/get/player.sql similarity index 100% rename from procedures_get_player.sql rename to procedures/get/player.sql diff --git a/procedures_get_unit.sql b/procedures/get/unit.sql similarity index 100% rename from procedures_get_unit.sql rename to procedures/get/unit.sql diff --git a/procedures_get_world.sql b/procedures/get/world.sql similarity index 100% rename from procedures_get_world.sql rename to procedures/get/world.sql