Skip to content

Commit e5c1e68

Browse files
committed
Add AUTORUN_LARAVEL_SKIP_IF_NOT_FOUND environment variable
- Introduced `AUTORUN_LARAVEL_SKIP_IF_NOT_FOUND` to allow the Laravel Automations script to exit gracefully if Laravel is not detected in `APP_BASE_DIR`, preventing container failure. - Updated documentation to reflect this new variable and its usage, particularly in shared image scenarios before the first `composer install`. - Enhanced the entrypoint script to support this new behavior, improving flexibility for development environments.
1 parent a7fb85e commit e5c1e68

3 files changed

Lines changed: 9 additions & 0 deletions

File tree

docs/content/docs/3.framework-guides/1.laravel/1.automations.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ In order for this script to run,`AUTORUN_ENABLED` must be set to `true`. Once th
3131
| `AUTORUN_LARAVEL_MIGRATION_TIMEOUT` | `30` | Number of seconds to wait for database connection before timing out during migrations. |
3232
| `AUTORUN_LARAVEL_OPTIMIZE` | `true` | `php artisan optimize`: Optimizes the application. |
3333
| `AUTORUN_LARAVEL_ROUTE_CACHE` | `true` | `php artisan route:cache`: Caches the routes. |
34+
| `AUTORUN_LARAVEL_SKIP_IF_NOT_FOUND` | `false` | When `true`, the script will exit gracefully (without error) if Laravel is not detected in `APP_BASE_DIR`, instead of failing the container. Useful when `AUTORUN_ENABLED=true` is set on a shared image where Laravel may not always be present (e.g. before the first `composer install`). |
3435
| `AUTORUN_LARAVEL_STORAGE_LINK` | `true` | `php artisan storage:link`: Creates a symbolic link from `public/storage` to `storage/app/public`. |
3536
| `AUTORUN_LARAVEL_VIEW_CACHE` | `true` | `php artisan view:cache`: Caches the views. |
3637

@@ -153,6 +154,8 @@ In most cases, this is due to a bug in their application code that causes a migr
153154
If a failure occurs in the Laravel Automations script, it will exit with a non-zero exit code -- preventing the container from starting.
154155
::
155156

157+
If you need the container to start even when Laravel is not yet present (for example, before the first `composer install` in development), set `AUTORUN_LARAVEL_SKIP_IF_NOT_FOUND=true`. The script will exit silently with a zero exit code instead of failing. The skip will be logged when `AUTORUN_DEBUG=true` or `LOG_OUTPUT_LEVEL=debug` is set.
158+
156159
If you are experiencing issues, you can enable the `AUTORUN_DEBUG` environment variable to get more detailed output of what could be going wrong.
157160

158161
If you need even more information, you can set `LOG_OUTPUT_LEVEL` to `debug` to get **A TON** of output of what's exactly happening.

docs/content/docs/8.reference/1.environment-variable-specification.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ Setting environment variables all depends on what method you're using to run you
4242
`AUTORUN_LARAVEL_MIGRATION_SKIP_DB_CHECK`<br />*Default: "false"*|Skip the database connection check before running migrations. <br />ℹ️ Requires `AUTORUN_ENABLED = true` to run.| all
4343
`AUTORUN_LARAVEL_MIGRATION_TIMEOUT`<br />*Default: "30"*|The number of seconds to wait for the database to come online before attempting `php artisan migrate`.. <br />ℹ️ Requires `AUTORUN_ENABLED = true` to run.| all
4444
`AUTORUN_LARAVEL_ROUTE_CACHE`<br />*Default: "true"*|Automatically run "php artisan route:cache" on container start. <br />ℹ️ Requires `AUTORUN_ENABLED = true` to run.| all
45+
`AUTORUN_LARAVEL_SKIP_IF_NOT_FOUND`<br />*Default: "false"*|When set to `true`, the Laravel Automations script will exit gracefully (without error) if Laravel is not detected in `APP_BASE_DIR`, instead of failing the container. Useful when `AUTORUN_ENABLED=true` is set on a shared image where Laravel may not always be present (e.g. before the first `composer install`). <br />ℹ️ Requires `AUTORUN_ENABLED = true` to have any effect.| all
4546
`AUTORUN_LARAVEL_STORAGE_LINK`<br />*Default: "true"*|Automatically run "php artisan storage:link" on container start. <br />ℹ️ Requires `AUTORUN_ENABLED = true` to run.| all
4647
`AUTORUN_LARAVEL_VIEW_CACHE`<br />*Default: "true"*|Automatically run "php artisan view:cache" on container start. <br />ℹ️ Requires `AUTORUN_ENABLED = true` to run.| all
4748
`CADDY_ADMIN`<br />*Default: "off"*|Enable Caddy admin interface. (<a target="_blank" href="https://caddyserver.com/docs/caddyfile/options#admin">Official docs</a>)|frankenphp

src/common/etc/entrypoint.d/50-laravel-automations.sh

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ script_name="laravel-automations"
99
# Set default values for Laravel automations
1010
: "${AUTORUN_ENABLED:=false}"
1111
: "${AUTORUN_DEBUG:=false}"
12+
: "${AUTORUN_LARAVEL_SKIP_IF_NOT_FOUND:=false}"
1213

1314
# Set default values for storage link
1415
: "${AUTORUN_LARAVEL_STORAGE_LINK:=true}"
@@ -469,6 +470,10 @@ if laravel_is_installed; then
469470
artisan_optimize
470471
fi
471472
else
473+
if [ "$AUTORUN_LARAVEL_SKIP_IF_NOT_FOUND" = "true" ]; then
474+
debug_log "Laravel not detected in $APP_BASE_DIR. Skipping automations (AUTORUN_LARAVEL_SKIP_IF_NOT_FOUND=true)."
475+
exit 0
476+
fi
472477
echo "$script_name: Could not detect Laravel installation."
473478
echo "ℹ️ Check that the application is installed in $APP_BASE_DIR"
474479
exit 1

0 commit comments

Comments
 (0)