diff --git a/Dockerfile b/Dockerfile index f4478e2..4c8de95 100644 --- a/Dockerfile +++ b/Dockerfile @@ -7,5 +7,22 @@ FROM --platform=linux/amd64 openresty/openresty:1.21.4.1-4-centos7 # not ENV TZ "Asia/Shanghai" ENV TZ Asia/Shanghai +# configure the mirror of yum. +# https://mirrors.163.com/.help/centos.html +RUN wget https://mirrors.163.com/.help/CentOS7-Base-163.repo \ + && mv /etc/yum.repos.d/CentOS-Base.repo /etc/yum.repos.d/CentOS-Base.repo.backup \ + && mv CentOS7-Base-163.repo /etc/yum.repos.d/CentOS7-Base-163.repo \ + && yum clean all && yum makecache + +# install the crontab and logrotate for log rotating. +RUN yum -y install logrotate crontabs + +# add logrotate to crontab +COPY ./conf/logrotate/logrotate.conf /etc/logrotate.d +RUN echo "0 0 * * * /etc/cron.daily/logrotate" >> mycrontab \ + && crontab mycrontab \ + && rm mycrontab + + WORKDIR /dist COPY . /dist/ diff --git a/conf/logrotate/logrotate.conf b/conf/logrotate/logrotate.conf new file mode 100644 index 0000000..d0aff95 --- /dev/null +++ b/conf/logrotate/logrotate.conf @@ -0,0 +1,23 @@ +/dist/logs/ngxway.access.log { + su root root + daily + compress + rotate 7 + missingok + notifempty + create 777 root root + dateext + dateformat -%Y-%m-%d.log +} + +/dist/logs/ngxway.error.log { + su root root + daily + compress + rotate 7 + missingok + notifempty + create 777 root root + dateext + dateformat -%Y-%m-%d.log +} diff --git a/scripts/logs/logrotate.sh b/scripts/logs/logrotate.sh new file mode 100644 index 0000000..e69de29