Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 8 additions & 5 deletions entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -37,34 +37,37 @@ if ${SSL_SELF_SIGNED:=true}; then
ln -s /etc/nginx/sites-available/fbctf-ssl.conf /etc/nginx/sites-enabled/fbctf-ssl.conf
else
ln -s /etc/nginx/sites-available/fbctf.conf /etc/nginx/sites-enabled/fbctf.conf
sed -i -r -e '/private static bool \$s_secure/ {s/true/false/}' /var/www/fbctf/src/SessionUtils.php
sed -i -r -e '/private static bool \$s_secure/ {s/true/false/}' $CTF_PATH/src/SessionUtils.php
fi

# Forward request and error logs to docker log collector
ln -sf /dev/stdout /var/log/nginx/access.log \
&& ln -sf /dev/stderr /var/log/nginx/error.log

# Set linked mysql container as mysql host
echo -e "[client]\nhost=mysql" > ~/.my.cnf

echo -e "[client]\nhost=$MYSQL_HOST" > ~/.my.cnf

# Wait for the mysql container to be ready
while ! nc -z mysql 3306; do
echo "Waiting for mysql to start";
while ! mysqlshow -u$MYSQL_USER -p$MYSQL_PASSWORD > /dev/null 2>&1; do
Copy link
Owner

@AlexGaspar AlexGaspar May 20, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do you want to change this? Is it because we're not sure netcat is installed?

Edit: Oh, didn't see your commit use mysqlshow to prevent secured containers failing. What do you mean?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if you secure your container like -cap-drop net-raw netcat will not work plus an open port does not mean the db is ready.

echo "Waiting for mysql to be ready";
sleep 1;
done;

# Don't errase the database if it exists
# Don't errase the database if it exists & has table
if [ $(mysql -N -s -u $MYSQL_USER --password=$MYSQL_PASSWORD -e \
"select count(*) from information_schema.tables where \
table_schema='$MYSQL_DATABASE';") -ge 1 ]; then
echo "Database already created... skipping creation..."
else
echo "creating DB"
import_empty_db "$MYSQL_USER" "$MYSQL_PASSWORD" "$MYSQL_DATABASE" "$CTF_PATH" "prod"
fi

# Configuring settings.ini
cat "$CTF_PATH/settings.tmpl.ini" \
| sed "s/MYSQL_PORT/$MYSQL_PORT/g" \
| sed "s/MYSQL_HOST/$MYSQL_HOST/g" \
| sed "s/MYSQL_DATABASE/$MYSQL_DATABASE/g" \
| sed "s/MYSQL_USER/$MYSQL_USER/g" \
| sed "s/MYSQL_PASSWORD/$MYSQL_PASSWORD/g" \
Expand Down
3 changes: 1 addition & 2 deletions templates/fbctf.conf
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,11 @@ server {

location ~ \.php$ {
try_files $uri =404;
#fastcgi_pass unix:/var/run/hhvm/sock;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
error_page 400 401 402 403 404 500 /error.php;
client_max_body_size 25M;
}
}
4 changes: 2 additions & 2 deletions templates/settings.tmpl.ini
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
; Values are replaced by env variables at boot time

DB_HOST = 'mysql'
DB_HOST = 'MYSQL_HOST'
DB_PORT = 'MYSQL_PORT'
DB_NAME = 'MYSQL_DATABASE'
DB_USERNAME = 'MYSQL_USER'
DB_PASSWORD = 'MYSQL_PASSWORD'

MC_HOST = 'memcached'
MC_HOST = 'MEMCACHED_HOST'
MC_PORT = 'MEMCACHED_PORT'