diff --git a/Dockerfile b/Dockerfile index d535c4b..c361c83 100644 --- a/Dockerfile +++ b/Dockerfile @@ -5,7 +5,7 @@ FROM dunglas/frankenphp:${frankenphp_version}-php${php_version} AS base WORKDIR /laravel SHELL ["/bin/bash", "-eou", "pipefail", "-c"] -ENV SERVER_NAME=:80 +ENV SERVER_NAME=:8000 ENV OCTANE_SERVER=frankenphp ARG user=laravel diff --git a/src/common/test_smtp_connection.php b/src/common/test_smtp_connection.php new file mode 100644 index 0000000..5ff11d1 --- /dev/null +++ b/src/common/test_smtp_connection.php @@ -0,0 +1,34 @@ +make(Illuminate\Contracts\Console\Kernel::class); +$kernel->bootstrap(); + +try { + $dsn = sprintf( + 'smtp://%s:%s@%s:%d', + config('mail.mailers.smtp.username'), + config('mail.mailers.smtp.password'), + config('mail.mailers.smtp.host'), + config('mail.mailers.smtp.port') + ); + + if (config('mail.mailers.smtp.encryption') === 'tls') { + $dsn .= '?encryption=tls'; + } + + $transport = Transport::fromDsn($dsn); + $mailer = new Mailer($transport); + + $transport->start(); + + exit(0); +} catch (Exception $e) { + echo 'SMTP connection error: ' . $e->getMessage(); + exit(1); +} diff --git a/src/entrypoint.sh b/src/entrypoint.sh index 56e17df..b3f5945 100644 --- a/src/entrypoint.sh +++ b/src/entrypoint.sh @@ -1,9 +1,11 @@ #!/bin/bash -set -e +set -euo pipefail +trap 'echo "Error on line $LINENO"' ERR -: "${CONTAINER_MODE:=app}" : "${CONTAINER_PORT:=8000}" +: "${CONTAINER_MANUAL_SETUP:=false}" +: "${CONTAINER_MODE:=app}" : "${CONTAINER_WORKER_DELAY:=10}" : "${CONTAINER_WORKER_SLEEP:=5}" : "${CONTAINER_WORKER_TIMEOUT:=300}" @@ -11,6 +13,7 @@ set -e : "${TEST_DB_CONNECTION:=true}" : "${TEST_CACHE_CONNECTION:=true}" +: "${TEST_SMTP_CONNECTION:=false}" : "${TEST_CONNECTION_TIMEOUT:=20}" : "${APP_ENV:=production}" @@ -21,6 +24,9 @@ ARTISAN="php -d variables_order=EGPCS /laravel/artisan" _test_connection() { local count=0 local type="${1}" + local status + + echo "🆗 Testing ${type} connection..." while [ "$count" -lt "$TEST_CONNECTION_TIMEOUT" ]; do php -f "/common/test_${type}_connection.php" > /dev/null 2>&1 @@ -52,6 +58,12 @@ _test_connections() { else _test_connection "cache" fi + + if [ "$TEST_SMTP_CONNECTION" != "true" ]; then + echo "⏭ Skipping SMTP connection test..." + else + _test_connection "smtp" + fi } _migrate() {