Skip to content

Commit 9624726

Browse files
committed
➕ Add SMTP connections test
1 parent 088c36d commit 9624726

File tree

3 files changed

+47
-2
lines changed

3 files changed

+47
-2
lines changed

Dockerfile

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ FROM dunglas/frankenphp:${frankenphp_version}-php${php_version} AS base
55
WORKDIR /laravel
66
SHELL ["/bin/bash", "-eou", "pipefail", "-c"]
77

8-
ENV SERVER_NAME=:80
8+
ENV SERVER_NAME=:8000
99
ENV OCTANE_SERVER=frankenphp
1010
ARG user=laravel
1111

src/common/test_smtp_connection.php

+34
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
<?php
2+
3+
require 'vendor/autoload.php';
4+
5+
use Symfony\Component\Mailer\Transport;
6+
use Symfony\Component\Mailer\Mailer;
7+
8+
$app = require_once 'bootstrap/app.php';
9+
$kernel = $app->make(Illuminate\Contracts\Console\Kernel::class);
10+
$kernel->bootstrap();
11+
12+
try {
13+
$dsn = sprintf(
14+
'smtp://%s:%s@%s:%d',
15+
config('mail.mailers.smtp.username'),
16+
config('mail.mailers.smtp.password'),
17+
config('mail.mailers.smtp.host'),
18+
config('mail.mailers.smtp.port')
19+
);
20+
21+
if (config('mail.mailers.smtp.encryption') === 'tls') {
22+
$dsn .= '?encryption=tls';
23+
}
24+
25+
$transport = Transport::fromDsn($dsn);
26+
$mailer = new Mailer($transport);
27+
28+
$transport->start();
29+
30+
exit(0);
31+
} catch (Exception $e) {
32+
echo 'SMTP connection error: ' . $e->getMessage();
33+
exit(1);
34+
}

src/entrypoint.sh

+12-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
#!/bin/bash
22

3-
set -e
3+
set -euo pipefail
4+
trap 'echo "Error on line $LINENO"' ERR
45

56
: "${CONTAINER_MODE:=app}"
67
: "${CONTAINER_PORT:=8000}"
@@ -11,6 +12,7 @@ set -e
1112

1213
: "${TEST_DB_CONNECTION:=true}"
1314
: "${TEST_CACHE_CONNECTION:=true}"
15+
: "${TEST_SMTP_CONNECTION:=false}"
1416
: "${TEST_CONNECTION_TIMEOUT:=20}"
1517

1618
: "${APP_ENV:=production}"
@@ -21,6 +23,9 @@ ARTISAN="php -d variables_order=EGPCS /laravel/artisan"
2123
_test_connection() {
2224
local count=0
2325
local type="${1}"
26+
local status
27+
28+
echo "🆗 Testing ${type} connection..."
2429

2530
while [ "$count" -lt "$TEST_CONNECTION_TIMEOUT" ]; do
2631
php -f "/common/test_${type}_connection.php" > /dev/null 2>&1
@@ -52,6 +57,12 @@ _test_connections() {
5257
else
5358
_test_connection "cache"
5459
fi
60+
61+
if [ "$TEST_SMTP_CONNECTION" != "true" ]; then
62+
echo "⏭ Skipping SMTP connection test..."
63+
else
64+
_test_connection "smtp"
65+
fi
5566
}
5667

5768
_migrate() {

0 commit comments

Comments
 (0)