Skip to content

Commit 3ba0803

Browse files
committed
βž• Add SMTP connections test
1 parent 088c36d commit 3ba0803

File tree

4 files changed

+62
-9
lines changed

4 files changed

+62
-9
lines changed

β€ŽDockerfile

Lines changed: 1 addition & 1 deletion
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

β€ŽREADME.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,4 +17,4 @@
1717
| `CONTAINER_WORKER_TIMEOUT` | `300` | worker |
1818
| `TEST_DB_CONNECTION` | `true` | `*` |
1919
| `TEST_CACHE_CONNECTION` | `true` | `*` |
20-
| `TEST_CONNECTION_TIMEOUT` | `20` | `*` |
20+
| `TEST_CONNECTION_TIMEOUT` | `10` | `*` |
Lines changed: 34 additions & 0 deletions
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

Lines changed: 26 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,20 @@
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}"
14-
: "${TEST_CONNECTION_TIMEOUT:=20}"
16+
: "${TEST_SMTP_CONNECTION:=false}"
17+
: "${TEST_CONNECTION_TIMEOUT:=10}"
1518

1619
: "${APP_ENV:=production}"
1720
: "${APP_DEBUG:=false}"
@@ -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
@@ -44,14 +50,20 @@ _test_connections() {
4450
if [ "$TEST_DB_CONNECTION" != "true" ]; then
4551
echo "⏭ Skipping database connection test..."
4652
else
47-
_test_connection "db"
53+
_test_connection "database"
4854
fi
4955

5056
if [ "$TEST_CACHE_CONNECTION" != "true" ]; then
5157
echo "⏭ Skipping cache connection test..."
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() {
@@ -71,13 +83,20 @@ _setup() {
7183
if [ -d "/laravel/app/public/storage" ]; then
7284
echo "βœ… Storage already linked..."
7385
else
74-
echo "πŸ” Linking the storage..."
86+
echo "πŸ—‚οΈ Linking the storage..."
7587
${ARTISAN} storage:link
7688
fi
7789

90+
echo "βš™οΈ Creating config cache..."
7891
${ARTISAN} config:cache
79-
${ARTISAN} events:cache
92+
93+
echo "πŸƒ Creating event cache..."
94+
${ARTISAN} event:cache
95+
96+
echo "🚏 Creating route cache..."
8097
${ARTISAN} route:cache
98+
99+
echo "πŸ–ΌοΈ Creating view cache..."
81100
${ARTISAN} view:cache
82101
}
83102

@@ -97,7 +116,7 @@ _run() {
97116
--delay="$CONTAINER_WORKER_DELAY"
98117
;;
99118
horizon)
100-
echo "Running horizon..."
119+
echo "🌀️ Running horizon..."
101120
exec ${ARTISAN} horizon
102121
;;
103122
scheduler)

0 commit comments

Comments
Β (0)