Skip to content

Commit

Permalink
➕ Add S3 connections test
Browse files Browse the repository at this point in the history
  • Loading branch information
bdsoha committed Jan 22, 2025
1 parent 3ba0803 commit 40e3372
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 21 deletions.
29 changes: 29 additions & 0 deletions src/common/test_s3_connection.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<?php

require '/laravel/vendor/autoload.php';

use Illuminate\Support\Facades\Storage;

$app = require_once '/laravel/bootstrap/app.php';
$kernel = $app->make(Illuminate\Contracts\Console\Kernel::class);
$kernel->bootstrap();

try {
$disk = Storage::disk('s3');

$testFileName = 's3_connection_test_' . time() . '.txt';

$disk->put($testFileName, 's3_test_value');

if ('s3_test_value' === $disk->get($testFileName)) {
$disk->delete($testFileName);
exit(0);
}

echo 'S3 store is not working properly: Test value mismatch.';
exit(1);

} catch (Exception $e) {
echo 'S3 connection error: ' . $e->getMessage();
exit(1);
}
35 changes: 14 additions & 21 deletions src/entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,6 @@ trap 'echo "Error on line $LINENO"' ERR
: "${CONTAINER_WORKER_SLEEP:=5}"
: "${CONTAINER_WORKER_TIMEOUT:=300}"
: "${CONTAINER_WORKER_TRIES:=3}"

: "${TEST_DB_CONNECTION:=true}"
: "${TEST_CACHE_CONNECTION:=true}"
: "${TEST_SMTP_CONNECTION:=false}"
: "${TEST_CONNECTION_TIMEOUT:=10}"

: "${APP_ENV:=production}"
Expand Down Expand Up @@ -47,23 +43,20 @@ _test_connection() {
}

_test_connections() {
if [ "$TEST_DB_CONNECTION" != "true" ]; then
echo "⏭ Skipping database connection test..."
else
_test_connection "database"
fi

if [ "$TEST_CACHE_CONNECTION" != "true" ]; then
echo "⏭ Skipping cache connection test..."
else
_test_connection "cache"
fi

if [ "$TEST_SMTP_CONNECTION" != "true" ]; then
echo "⏭ Skipping SMTP connection test..."
else
_test_connection "smtp"
fi
declare -A connections=(
[database]="${TEST_DB_CONNECTION:-true}"
[cache]="${TEST_CACHE_CONNECTION:-true}"
[s3]="${TEST_S3_CONNECTION:-false}"
[smtp]="${TEST_SMTP_CONNECTION:-false}"
)

for service in "${!connections[@]}"; do
if [ "${connections[$service]}" != "true" ]; then
echo "⏭ Skipping $service connection test..."
else
_test_connection "$service"
fi
done
}

_migrate() {
Expand Down

0 comments on commit 40e3372

Please sign in to comment.