Added cleaning logs to discard older logs as not need while developing
This commit is contained in:
@@ -3,7 +3,7 @@ FROM debian:bookworm
|
|||||||
|
|
||||||
# Install apache2 and PHP and PHP modules
|
# Install apache2 and PHP and PHP modules
|
||||||
RUN apt update && \
|
RUN apt update && \
|
||||||
apt install -y apache2 curl unzip php8.2 php8.2-curl php8.2-cli php8.2-mysqli php8.2-gd php8.2-zip php8.2-dom php8.2-mbstring && \
|
apt install -y apache2 curl cron unzip php8.2 php8.2-curl php8.2-cli php8.2-mysqli php8.2-gd php8.2-zip php8.2-dom php8.2-mbstring && \
|
||||||
curl -sS https://getcomposer.org/installer | php -- --install-dir=/usr/local/bin --filename=composer && \
|
curl -sS https://getcomposer.org/installer | php -- --install-dir=/usr/local/bin --filename=composer && \
|
||||||
apt clean && \
|
apt clean && \
|
||||||
rm -rf /var/lib/apt/lists/*
|
rm -rf /var/lib/apt/lists/*
|
||||||
@@ -17,5 +17,13 @@ WORKDIR /var/www/html
|
|||||||
COPY ../../composer.json ./
|
COPY ../../composer.json ./
|
||||||
RUN composer install --no-interaction
|
RUN composer install --no-interaction
|
||||||
|
|
||||||
|
COPY ./docker/php/clean_logs.sh /root/clean_logs.sh
|
||||||
|
RUN chmod +x /root/clean_logs.sh
|
||||||
|
|
||||||
|
# Add cron job for log cleanup
|
||||||
|
RUN echo "* * * * * /root/clean_old_logs.sh" > /etc/cron.d/clean_old_logs && \
|
||||||
|
chmod 0644 /etc/cron.d/clean_old_logs && \
|
||||||
|
crontab /etc/cron.d/clean_old_logs
|
||||||
|
|
||||||
# Start Apache in the foreground
|
# Start Apache in the foreground
|
||||||
CMD ["apachectl", "-D", "FOREGROUND"]
|
CMD ["apachectl", "-D", "FOREGROUND"]
|
||||||
|
|||||||
11
docker/php/clean_logs.sh
Normal file
11
docker/php/clean_logs.sh
Normal file
@@ -0,0 +1,11 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
|
||||||
|
# Variables
|
||||||
|
LOG_DIR="/var/log/apache2"
|
||||||
|
ERROR_LOG="${LOG_DIR}/error.log"
|
||||||
|
ACCESS_LOG="${LOG_DIR}/access.log"
|
||||||
|
LINES_TO_KEEP=50
|
||||||
|
|
||||||
|
# Truncate logs to keep only the last 50 lines
|
||||||
|
tail -n $LINES_TO_KEEP $ERROR_LOG > ${ERROR_LOG}.tmp && mv ${ERROR_LOG}.tmp $ERROR_LOG
|
||||||
|
tail -n $LINES_TO_KEEP $ACCESS_LOG > ${ACCESS_LOG}.tmp && mv ${ACCESS_LOG}.tmp $ACCESS_LOG
|
||||||
Reference in New Issue
Block a user