From 3bd31bd65d2d6c945e23cddae86d52ed7c28174d Mon Sep 17 00:00:00 2001 From: Peter Goodhall Date: Sat, 9 Aug 2025 18:20:25 +0100 Subject: [PATCH] Improve startup script and PHP config in Dockerfile Dockerfile now configures PHP for larger file uploads and increased resource limits. The startup script checks for existing config files before processing, cleans input variables to remove trailing whitespace, and improves sed usage for reliability. --- Dockerfile | 7 +++++++ script.sh | 43 +++++++++++++++++++++++++++++-------------- 2 files changed, 36 insertions(+), 14 deletions(-) diff --git a/Dockerfile b/Dockerfile index 4e3c04b8..c3c516f8 100644 --- a/Dockerfile +++ b/Dockerfile @@ -28,5 +28,12 @@ RUN apt-get update && apt-get install -y \ COPY script.sh /usr/local/bin/startup.sh RUN sed -i 's/\r$//' /usr/local/bin/startup.sh && chmod +x /usr/local/bin/startup.sh +# Configure PHP for larger file uploads (30MB) +RUN echo "upload_max_filesize = 30M" >> /usr/local/etc/php/conf.d/uploads.ini \ + && echo "post_max_size = 35M" >> /usr/local/etc/php/conf.d/uploads.ini \ + && echo "memory_limit = 64M" >> /usr/local/etc/php/conf.d/uploads.ini \ + && echo "max_execution_time = 300" >> /usr/local/etc/php/conf.d/uploads.ini \ + && echo "max_input_time = 300" >> /usr/local/etc/php/conf.d/uploads.ini + # Expose port 80 EXPOSE 80 \ No newline at end of file diff --git a/script.sh b/script.sh index 776ebfeb..b4cf4631 100755 --- a/script.sh +++ b/script.sh @@ -60,22 +60,37 @@ if [ ! -d "$DEST_DIR" ]; then mkdir -p $DEST_DIR fi +# Check if configuration has already been processed +if [ -f "$DEST_DIR/database.php" ] && [ -f "$DEST_DIR/config.php" ]; then + echo "Configuration files already exist, skipping processing..." +else + echo "Processing configuration files..." + + # Use sed with a different delimiter (`|`) to avoid conflicts with special characters + # Strip any trailing whitespace/newlines from variables before using them + CLEAN_DATABASE=$(echo "${MYSQL_DATABASE}" | tr -d '\r\n') + CLEAN_USER=$(echo "${MYSQL_USER}" | tr -d '\r\n') + CLEAN_PASSWORD=$(echo "${MYSQL_PASSWORD}" | tr -d '\r\n') + CLEAN_HOST=$(echo "${MYSQL_HOST}" | tr -d '\r\n') + CLEAN_LOCATOR=$(echo "${BASE_LOCATOR}" | tr -d '\r\n') + CLEAN_URL=$(echo "${WEBSITE_URL}" | tr -d '\r\n') + CLEAN_DIRECTORY=$(echo "${DIRECTORY}" | tr -d '\r\n') + + sed -i "s|%DATABASE%|${CLEAN_DATABASE}|g" $DATABASE_FILE + sed -i "s|%USERNAME%|${CLEAN_USER}|g" $DATABASE_FILE + sed -i "s|%PASSWORD%|${CLEAN_PASSWORD}|g" $DATABASE_FILE + sed -i "s|%HOSTNAME%|${CLEAN_HOST}|g" $DATABASE_FILE + sed -i "s|%baselocator%|${CLEAN_LOCATOR}|g" $CONFIG_FILE + sed -i "s|%websiteurl%|${CLEAN_URL}|g" $CONFIG_FILE + sed -i "s|%directory%|${CLEAN_DIRECTORY}|g" $CONFIG_FILE -# Use sed with a different delimiter (`|`) to avoid conflicts with special characters -sed -i "s|%DATABASE%|${MYSQL_DATABASE}|g" $DATABASE_FILE -sed -i "s|%USERNAME%|${MYSQL_USER}|g" $DATABASE_FILE -sed -i "s|%PASSWORD%|${MYSQL_PASSWORD}|g" $DATABASE_FILE -sed -i "s|%HOSTNAME%|${MYSQL_HOST}|g" $DATABASE_FILE -sed -i "s|%baselocator%|${BASE_LOCATOR}|g" $CONFIG_FILE -sed -i "s|%websiteurl%|${WEBSITE_URL}|g" $CONFIG_FILE -sed -i "s|%directory%|${DIRECTORY}|g" $CONFIG_FILE + # Move the files to the destination directory + mv $CONFIG_FILE $DEST_DIR + mv $DATABASE_FILE $DEST_DIR -# Move the files to the destination directory -mv $CONFIG_FILE $DEST_DIR -mv $DATABASE_FILE $DEST_DIR - -# Delete the /install directory -rm -rf /install + # Delete the /install directory + rm -rf /install +fi echo "Replacement complete."