mirror of
https://github.com/aljazceru/CTFd.git
synced 2025-12-17 05:54:19 +01:00
Update docker files (#598)
* Add redis to docker-compose, bump worker count to 4 * Add workers & missing SECRET_KEY error * Remove uwsgi specific files * Parse database host in `docker-entrypoint.sh`. Closes #587
This commit is contained in:
46
ctfd.ini
46
ctfd.ini
@@ -1,46 +0,0 @@
|
|||||||
# UWSGI Configuration File
|
|
||||||
# Install uwsgi (sudo apt-get install uwsgi), copy this file to
|
|
||||||
# /etc/uwsgi/apps-available and then link it in /etc/uwsgi/apps-enabled
|
|
||||||
# Only two lines below (commented) need to be changed for your config.
|
|
||||||
# Then, you can use something like the following in your nginx config:
|
|
||||||
#
|
|
||||||
# # SERVER_ROOT is not / (e.g. /ctf)
|
|
||||||
# location = /ctf { rewrite ^ /ctf/; }
|
|
||||||
# location /ctf {
|
|
||||||
# include uwsgi_params;
|
|
||||||
# uwsgi_pass unix:/run/uwsgi/app/ctfd/socket;
|
|
||||||
# }
|
|
||||||
#
|
|
||||||
# # SERVER_ROOT is /
|
|
||||||
# location / {
|
|
||||||
# include uwsgi_params;
|
|
||||||
# wsgi_pass unix:/run/uwsgi/app/ctfd/socket;
|
|
||||||
# }
|
|
||||||
[uwsgi]
|
|
||||||
# Where you've put CTFD
|
|
||||||
chdir = /var/www/ctfd/
|
|
||||||
# If SCRIPT_ROOT is not /
|
|
||||||
#mount = /ctf=wsgi.py
|
|
||||||
# SCRIPT_ROOT is /
|
|
||||||
mount = /=wsgi.py
|
|
||||||
|
|
||||||
# You shouldn't need to change anything past here
|
|
||||||
plugin = python
|
|
||||||
module = wsgi
|
|
||||||
|
|
||||||
master = true
|
|
||||||
processes = 1
|
|
||||||
threads = 1
|
|
||||||
|
|
||||||
vacuum = true
|
|
||||||
|
|
||||||
manage-script-name = true
|
|
||||||
wsgi-file = wsgi.py
|
|
||||||
callable = app
|
|
||||||
|
|
||||||
die-on-term = true
|
|
||||||
|
|
||||||
# If you're not on debian/ubuntu, replace with uid/gid of web user
|
|
||||||
uid = www-data
|
|
||||||
gid = www-data
|
|
||||||
|
|
||||||
@@ -10,6 +10,8 @@ services:
|
|||||||
- UPLOAD_FOLDER=/var/uploads
|
- UPLOAD_FOLDER=/var/uploads
|
||||||
- LOG_FOLDER=/var/log/CTFd
|
- LOG_FOLDER=/var/log/CTFd
|
||||||
- DATABASE_URL=mysql+pymysql://root:ctfd@db/ctfd
|
- DATABASE_URL=mysql+pymysql://root:ctfd@db/ctfd
|
||||||
|
- REDIS_URL=redis://cache:6379
|
||||||
|
- WORKERS=4
|
||||||
volumes:
|
volumes:
|
||||||
- .data/CTFd/logs:/var/log/CTFd
|
- .data/CTFd/logs:/var/log/CTFd
|
||||||
- .data/CTFd/uploads:/var/uploads
|
- .data/CTFd/uploads:/var/uploads
|
||||||
@@ -32,7 +34,15 @@ services:
|
|||||||
networks:
|
networks:
|
||||||
internal:
|
internal:
|
||||||
# This command is required to set important mariadb defaults
|
# This command is required to set important mariadb defaults
|
||||||
command: [mysqld, --character-set-server=utf8mb4, --collation-server=utf8mb4_unicode_ci, --wait_timeout=28800]
|
command: [mysqld, --character-set-server=utf8mb4, --collation-server=utf8mb4_unicode_ci, --wait_timeout=28800, --log-warnings=0]
|
||||||
|
|
||||||
|
cache:
|
||||||
|
image: redis:4
|
||||||
|
restart: always
|
||||||
|
volumes:
|
||||||
|
- .data/redis:/data
|
||||||
|
networks:
|
||||||
|
internal:
|
||||||
|
|
||||||
networks:
|
networks:
|
||||||
default:
|
default:
|
||||||
|
|||||||
@@ -1,23 +1,35 @@
|
|||||||
#!/bin/sh
|
#!/bin/sh
|
||||||
|
|
||||||
|
# Check that a .ctfd_secret_key file or SECRET_KEY envvar is set
|
||||||
|
if [ ! -f .ctfd_secret_key ] && [ -z "$SECRET_KEY" ]; then
|
||||||
|
if [ $WORKERS -gt 1 ]; then
|
||||||
|
echo "[ ERROR ] You are configured to use more than 1 worker."
|
||||||
|
echo "[ ERROR ] To do this, you must define the SECRET_KEY environment variable or create a .ctfd_secret_key file."
|
||||||
|
echo "[ ERROR ] Exiting..."
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Check that the database is available
|
||||||
if [ -n "$DATABASE_URL" ]
|
if [ -n "$DATABASE_URL" ]
|
||||||
then
|
then
|
||||||
# https://stackoverflow.com/a/29793382
|
database=`echo $DATABASE_URL | awk -F[@//] '{print $4}'`
|
||||||
echo "Waiting on MySQL"
|
echo "Waiting for $database to be ready"
|
||||||
while ! mysqladmin ping -h db --silent; do
|
while ! mysqladmin ping -h $database --silent; do
|
||||||
# Show some progress
|
# Show some progress
|
||||||
echo -n '.';
|
echo -n '.';
|
||||||
sleep 1;
|
sleep 1;
|
||||||
done
|
done
|
||||||
echo "Ready"
|
echo "$database is ready"
|
||||||
# Give it another second.
|
# Give it another second.
|
||||||
sleep 1;
|
sleep 1;
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
# Start CTFd
|
||||||
echo "Starting CTFd"
|
echo "Starting CTFd"
|
||||||
gunicorn 'CTFd:create_app()' \
|
gunicorn 'CTFd:create_app()' \
|
||||||
--bind '0.0.0.0:8000' \
|
--bind '0.0.0.0:8000' \
|
||||||
--workers 1 \
|
--workers $WORKERS \
|
||||||
--worker-class 'gevent' \
|
--worker-class 'gevent' \
|
||||||
--access-logfile "${LOG_FOLDER:-/opt/CTFd/CTFd/logs}/access.log" \
|
--access-logfile "${LOG_FOLDER:-/opt/CTFd/CTFd/logs}/access.log" \
|
||||||
--error-logfile "${LOG_FOLDER:-/opt/CTFd/CTFd/logs}/error.log"
|
--error-logfile "${LOG_FOLDER:-/opt/CTFd/CTFd/logs}/error.log"
|
||||||
|
|||||||
Reference in New Issue
Block a user