Skip to content

Commit

Permalink
Refactor entrypoint.sh script to improve performance (#48)
Browse files Browse the repository at this point in the history
  • Loading branch information
Codycody31 authored Dec 7, 2023
1 parent 4efef97 commit 7135665
Showing 1 changed file with 48 additions and 47 deletions.
95 changes: 48 additions & 47 deletions docker/entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,57 +2,58 @@

set -Eeo pipefail

if expr "$1" : "apache" 1>/dev/null || [ "$1" = "php-fpm" ]; then

ATISGENDIR=/var/www/html
ARTISAN="php ${ATISGENDIR}/artisan"

# Push env vars for cron
echo "Loading env vars for cron"
env > /etc/environment

# Start cron
echo "Starting cron"
cron -L 2

# Run supervisor
echo "Starting supervisord"
supervisord -c /etc/supervisor/supervisord.conf

# Ensure storage directories are present
STORAGE=${ATISGENDIR}/storage
mkdir -p ${STORAGE}/logs
mkdir -p ${STORAGE}/app/public
mkdir -p ${STORAGE}/framework/views
mkdir -p ${STORAGE}/framework/cache
mkdir -p ${STORAGE}/framework/sessions
chown -R www-data:www-data ${STORAGE}
chmod -R g+rw ${STORAGE}

# Generate key if not set
if [ -z "${APP_KEY:-}" -o "$APP_KEY" = "ChangeMeBy32KeyLengthOrGenerated" ]; then
${ARTISAN} key:generate --no-interaction
else
echo "APP_KEY already set"
fi

# Link public storage
ATISGENDIR=/var/www/html
ARTISAN="php ${ATISGENDIR}/artisan"

# Push env vars for cron
echo "Loading env vars for cron"
env >/etc/environment

# Start cron
echo "Starting cron"
cron -L 2

# Run supervisor
echo "Starting supervisord"
supervisord -c /etc/supervisor/supervisord.conf

# Ensure storage directories are present
STORAGE=${ATISGENDIR}/storage
mkdir -p ${STORAGE}/logs
mkdir -p ${STORAGE}/app/public
mkdir -p ${STORAGE}/framework/views
mkdir -p ${STORAGE}/framework/cache
mkdir -p ${STORAGE}/framework/sessions
chown -R www-data:www-data ${STORAGE}
chmod -R g+rw ${STORAGE}

# Generate key if not set
if [ -z "${APP_KEY:-}" -o "$APP_KEY" = "ChangeMeBy32KeyLengthOrGenerated" ]; then
${ARTISAN} key:generate --no-interaction
else
echo "APP_KEY already set"
fi

# Link public storage
if [ -d "${ATISGENDIR}/public/storage" ]; then
echo "Public storage already linked"
else
${ARTISAN} storage:link
fi

# Run migrations
${ARTISAN} migrate --force
# Run migrations
${ARTISAN} migrate --force

# Generate the sitemap, we queue it so that apache can start up before it runs
${ARTISAN} sitemap:queue
# Generate the sitemap, we queue it so that apache can start up before it runs
${ARTISAN} sitemap:queue

# Configure the site
${ARTISAN} site:configure
# Configure the site
${ARTISAN} site:configure

# Install laravel backpack
${ARTISAN} backpack:install --no-interaction
# Install laravel backpack
${ARTISAN} backpack:install --no-interaction

# Write to a file the current time
${ARTISAN} uptime
fi
# Write to a file the current time
${ARTISAN} uptime

exec "$@"
exec "$@"

0 comments on commit 7135665

Please sign in to comment.