panel
panel copied to clipboard
Add operation mode to docker container for scaled deployments
Is there an existing feature request for this?
- [X] I have searched the existing issues before opening this feature request.
Describe the feature you would like to see.
Having an environmental variable, such as SERVER_MODE which will allow you to select between mode MASTER and SLAVE. As I understand only one container can be running the cron and queue worker so it would be nice to have an option where when the env variable is set the docker container would disable those services in the container. This would then allow that small amount of users running docker swarm or k8s to scale their deployment.
Describe the solution you'd like.
This can be implemented through editing the entrypoint.sh file and adding an additional configuration fire for supervisord without the queue worker which would replace the default one just like the nginx file. My bash ain't perfect but this is how I image a solution would look like.
#!/bin/ash -e
cd /app
mkdir -p /var/log/panel/logs/ /var/log/supervisord/ /var/log/nginx/ /var/log/php7/ \
&& chmod 777 /var/log/panel/logs/ \
&& ln -s /var/log/panel/logs/ /app/storage/logs/
## Set mode to master if not set
if [[ -z $SERVER_MODE ]]; then
echo -e "SERVER_MODE not specified, defaulting to MASTER"
SERVER_MODE=MASTER
fi
## check for .env file and generate app keys if missing
if [ -f /app/var/.env ]; then
echo "external vars exist."
rm -rf /app/.env
ln -s /app/var/.env /app/
else
echo "external vars don't exist."
rm -rf /app/.env
touch /app/var/.env
## manually generate a key because key generate --force fails
if [ "$SERVER_MODE" == "MASTER" ]; then
if [ -z $APP_KEY ]; then
echo -e "Generating key."
APP_KEY=$(cat /dev/urandom | tr -dc 'a-zA-Z0-9' | fold -w 32 | head -n 1)
echo -e "Generated app key: $APP_KEY"
echo -e "APP_KEY=$APP_KEY" > /app/var/.env
else
echo -e "APP_KEY exists in environment, using that."
echo -e "APP_KEY=$APP_KEY" > /app/var/.env
fi
else
if [ -z $APP_KEY ]; then
echo -e "No APP_KEY will not work in slave mode"
else
echo -e "APP_KEY exists in environment, using that."
echo -e "APP_KEY=$APP_KEY" > /app/var/.env
fi
fi
ln -s /app/var/.env /app/
fi
echo "Checking if https is required."
if [ -f /etc/nginx/http.d/panel.conf ]; then
echo "Using nginx config already in place."
if [ $LE_EMAIL ]; then
echo "Checking for cert update"
certbot certonly -d $(echo $APP_URL | sed 's~http[s]*://~~g') --standalone -m $LE_EMAIL --agree-tos -n
else
echo "No letsencrypt email is set"
fi
else
echo "Checking if letsencrypt email is set."
if [ -z $LE_EMAIL ]; then
echo "No letsencrypt email is set using http config."
cp .github/docker/default.conf /etc/nginx/http.d/panel.conf
else
echo "writing ssl config"
cp .github/docker/default_ssl.conf /etc/nginx/http.d/panel.conf
echo "updating ssl config for domain"
sed -i "s|<domain>|$(echo $APP_URL | sed 's~http[s]*://~~g')|g" /etc/nginx/http.d/panel.conf
echo "generating certs"
certbot certonly -d $(echo $APP_URL | sed 's~http[s]*://~~g') --standalone -m $LE_EMAIL --agree-tos -n
fi
echo "Removing the default nginx config"
rm -rf /etc/nginx/http.d/default.conf
fi
if [[ -z $DB_PORT ]]; then
echo -e "DB_PORT not specified, defaulting to 3306"
DB_PORT=3306
fi
## check for DB up before starting the panel
echo "Checking database status."
until nc -z -v -w30 $DB_HOST $DB_PORT
do
echo "Waiting for database connection..."
# wait for 1 seconds before check again
sleep 1
done
## make sure the db is set up
if [ "$SERVER_MODE" == "MASTER" ]; then
echo -e "Migrating and Seeding D.B"
php artisan migrate --seed --force
## start cronjobs for the queue
echo -e "Starting cron jobs."
crond -L /var/log/crond -l 5
fi
if [ "$SERVER_MODE" == "SLAVE" ]; then
## remove queue worker from /etc/supervisord.conf
rm -rf /etc/supervisord.conf
## copy supervisord slave config without the queue worker
cp .github/docker/supervisord-slave.conf /etc/supervisord.conf
fi
echo -e "Starting supervisord."
exec "$@"
Additional context to this request.
I just built a container with this entrypoint and an additional supervisord file and it seems to work.