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
selenium-screenshot-testing
Kevin Chung 2018-03-25 04:25:33 -04:00 committed by GitHub
parent aedd753f4e
commit b78589d20d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 28 additions and 55 deletions

View File

@ -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

View File

@ -10,6 +10,8 @@ services:
- UPLOAD_FOLDER=/var/uploads
- LOG_FOLDER=/var/log/CTFd
- DATABASE_URL=mysql+pymysql://root:ctfd@db/ctfd
- REDIS_URL=redis://cache:6379
- WORKERS=4
volumes:
- .data/CTFd/logs:/var/log/CTFd
- .data/CTFd/uploads:/var/uploads
@ -32,7 +34,15 @@ services:
networks:
internal:
# 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:
default:

View File

@ -1,23 +1,35 @@
#!/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" ]
then
# https://stackoverflow.com/a/29793382
echo "Waiting on MySQL"
while ! mysqladmin ping -h db --silent; do
database=`echo $DATABASE_URL | awk -F[@//] '{print $4}'`
echo "Waiting for $database to be ready"
while ! mysqladmin ping -h $database --silent; do
# Show some progress
echo -n '.';
sleep 1;
done
echo "Ready"
echo "$database is ready"
# Give it another second.
sleep 1;
fi
# Start CTFd
echo "Starting CTFd"
gunicorn 'CTFd:create_app()' \
--bind '0.0.0.0:8000' \
--workers 1 \
--workers $WORKERS \
--worker-class 'gevent' \
--access-logfile "${LOG_FOLDER:-/opt/CTFd/CTFd/logs}/access.log" \
--error-logfile "${LOG_FOLDER:-/opt/CTFd/CTFd/logs}/error.log"

View File

@ -1,3 +0,0 @@
from CTFd import create_app
app = create_app()