Why does the new Laravel configuration run the cache step during runtime instead of build time?

Since a recent update of the Fly CLI, the entrypoint for a Laravel app includes the caching commands. I love that it’s building those caches, but why isn’t this part of the build step? Below you can find the entrypoint.sh:

#!/usr/bin/env sh

if [ $# -gt 0 ];then
    # If we passed a command, run it as root
    exec "$@"
else
    # Otherwise start the web server

    ## Prepare Laravel caches
    /usr/bin/php /var/www/html/artisan config:cache --no-ansi -q
    /usr/bin/php /var/www/html/artisan route:cache --no-ansi -q
    /usr/bin/php /var/www/html/artisan view:cache --no-ansi -q
    chown -R webuser:webgroup /var/www/html

    exec /init
fi
1 Like

Ah, It would be because the secret APP_KEY (which is needed to make the cache) isn’t available at build-time. It’s NULL. And so that would result in errors/exceptions. So those :cache commands need to be run when APP_KEY is available, which is at run-time.

Check out this thread from @fideloper-fly for more:

1 Like

Brilliant. Thank you for taking the time to help me :+1:

1 Like

Yeah, those are best added to the ENTRYPOINT script IMO, rather than as a step in the Dockerfile.