Skip to content

Commit 5389fc4

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

File tree

3 files changed

+49
-3
lines changed

3 files changed

+49
-3
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

+14-2
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,19 @@
11
#!/bin/bash
22

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

5-
: "${CONTAINER_MODE:=app}"
66
: "${CONTAINER_PORT:=8000}"
7+
: "${CONTAINER_MANUAL_SETUP:=}"
8+
: "${CONTAINER_MODE:=app}"
79
: "${CONTAINER_WORKER_DELAY:=10}"
810
: "${CONTAINER_WORKER_SLEEP:=5}"
911
: "${CONTAINER_WORKER_TIMEOUT:=300}"
1012
: "${CONTAINER_WORKER_TRIES:=3}"
1113

1214
: "${TEST_DB_CONNECTION:=true}"
1315
: "${TEST_CACHE_CONNECTION:=true}"
16+
: "${TEST_SMTP_CONNECTION:=false}"
1417
: "${TEST_CONNECTION_TIMEOUT:=20}"
1518

1619
: "${APP_ENV:=production}"
@@ -21,6 +24,9 @@ ARTISAN="php -d variables_order=EGPCS /laravel/artisan"
2124
_test_connection() {
2225
local count=0
2326
local type="${1}"
27+
local status
28+
29+
echo "🆗 Testing ${type} connection..."
2430

2531
while [ "$count" -lt "$TEST_CONNECTION_TIMEOUT" ]; do
2632
php -f "/common/test_${type}_connection.php" > /dev/null 2>&1
@@ -52,6 +58,12 @@ _test_connections() {
5258
else
5359
_test_connection "cache"
5460
fi
61+
62+
if [ "$TEST_SMTP_CONNECTION" != "true" ]; then
63+
echo "⏭ Skipping SMTP connection test..."
64+
else
65+
_test_connection "smtp"
66+
fi
5567
}
5668

5769
_migrate() {

0 commit comments

Comments
 (0)