mirror of https://github.com/JohnHammond/CTFd.git
Fix logging without root in container (#966)
* Catch IOError issues (i.e. permission issues) with writing to log files * Related to #844 * Logs now have a sys.stdout handler * Update Dockerfile to create and chown/chmod the folders used by `docker-compose` to store files/logs (`/var/log/CTFd`, `/var/uploads`)selenium-screenshot-testing
parent
ad5df80979
commit
367498fd72
|
@ -35,6 +35,7 @@ from sqlalchemy.exc import InvalidRequestError, IntegrityError
|
||||||
import datetime
|
import datetime
|
||||||
import logging
|
import logging
|
||||||
import os
|
import os
|
||||||
|
import sys
|
||||||
|
|
||||||
|
|
||||||
def init_template_filters(app):
|
def init_template_filters(app):
|
||||||
|
@ -85,6 +86,7 @@ def init_logs(app):
|
||||||
'registrations': os.path.join(log_dir, 'registrations.log')
|
'registrations': os.path.join(log_dir, 'registrations.log')
|
||||||
}
|
}
|
||||||
|
|
||||||
|
try:
|
||||||
for log in logs.values():
|
for log in logs.values():
|
||||||
if not os.path.exists(log):
|
if not os.path.exists(log):
|
||||||
open(log, 'a').close()
|
open(log, 'a').close()
|
||||||
|
@ -102,6 +104,20 @@ def init_logs(app):
|
||||||
logger_registrations.addHandler(
|
logger_registrations.addHandler(
|
||||||
registration_log
|
registration_log
|
||||||
)
|
)
|
||||||
|
except IOError:
|
||||||
|
pass
|
||||||
|
|
||||||
|
stdout = logging.StreamHandler(stream=sys.stdout)
|
||||||
|
|
||||||
|
logger_submissions.addHandler(
|
||||||
|
stdout
|
||||||
|
)
|
||||||
|
logger_logins.addHandler(
|
||||||
|
stdout
|
||||||
|
)
|
||||||
|
logger_registrations.addHandler(
|
||||||
|
stdout
|
||||||
|
)
|
||||||
|
|
||||||
logger_submissions.propagate = 0
|
logger_submissions.propagate = 0
|
||||||
logger_logins.propagate = 0
|
logger_logins.propagate = 0
|
||||||
|
|
|
@ -4,7 +4,7 @@ RUN apk update && \
|
||||||
RUN adduser -D -u 1001 -s /bin/bash ctfd
|
RUN adduser -D -u 1001 -s /bin/bash ctfd
|
||||||
|
|
||||||
WORKDIR /opt/CTFd
|
WORKDIR /opt/CTFd
|
||||||
RUN mkdir -p /opt/CTFd
|
RUN mkdir -p /opt/CTFd /var/log/CTFd /var/uploads
|
||||||
|
|
||||||
COPY requirements.txt .
|
COPY requirements.txt .
|
||||||
|
|
||||||
|
@ -20,6 +20,7 @@ RUN for d in CTFd/plugins/*; do \
|
||||||
|
|
||||||
RUN chmod +x /opt/CTFd/docker-entrypoint.sh
|
RUN chmod +x /opt/CTFd/docker-entrypoint.sh
|
||||||
RUN chown -R 1001:1001 /opt/CTFd
|
RUN chown -R 1001:1001 /opt/CTFd
|
||||||
|
RUN chown -R 1001:1001 /var/log/CTFd /var/uploads
|
||||||
|
|
||||||
USER 1001
|
USER 1001
|
||||||
EXPOSE 8000
|
EXPOSE 8000
|
||||||
|
|
Loading…
Reference in New Issue