Podman REST API
Flexisip-Account-ManagerコンテナからFlexisipコンテナへのAPIリクエスト
Podmanを動かすユーザー側で以下を実行(podman composeコマンドを有効にするため既に実行済)。
$ systemctl --user enable --now podman.socket
これで Podman の REST API ソケットが起動します。パスは以下のようになります。
- rootless(ユーザー):
/run/user/1000/podman/podman.sock
- root権限:
/run/podman/podman.sock
Podman REST API : exec
rootlessモードのAPIソケットを、php-fpm(Laravel)コンテナと共有するため、ボリュームマッピングを追加。
このソケットを介して、flexisipコンテナのflexisip_pusherの実行をリクエストできるようにします。
docker-compose.yml
......
......
php-fpm:
container_name: php-fpm
.....
.....
volumes:
......
......
# for execution of flexisip_pusher on ubuntu-flexisip container by podman api socket
- /run/user/1000/podman/podman.sock:/run/user/1000/podman/podman.sock
.....
.....
php-fpmコンテナ内でcurlによるテストを実施
実行セッションを作成(セッションID取得)
# curl --unix-socket /run/user/1000/podman/podman.sock \
-X POST http://d/v4.0.0/libpod/containers/ubuntu-flexisip/exec \
-H "Content-Type: application/json" \
-d '{
"Cmd": ["/opt/belledonne-communications/bin/flexisip_pusher", "--pn-provider", "xxx", "--pn-param", "yyy", "--pn-prid", "zzz", "--customPayload", "{\"token\":\"abc123\"}"],
"AttachStdout": true,
"AttachStderr": true
}'
{"Id":"45317c07503b74f6c807ac0cc85f8651eff882d8cf0857340236039c644340af"}
セッションIDを指定して実行
# curl --unix-socket /run/user/1000/podman/podman.sock \
-X POST http://d/v4.0.0/libpod/exec/45317c07503b74f6c807ac0cc85f8651eff882d8cf0857340236039c644340af/start \
-H "Content-Type: application/json" \
-d '{"Detach":false,"Tty":false,"AttachStdout":true,"AttachStderr":true}' \
--output -
VWriting logs in : /var/opt/belledonne-communications/log/flexisip/flexisip-pusher.log
DError, caught an unexpected exception: provider [xxx] not supported
O2025-04-26 02:06:11:590 flexisip-message- Unregistering module info [B2bua]...
2025-04-26 02:06:11:590 flexisip-message- Unregistering module info [DoSProtection]...
2025-04-26 02:06:11:590 flexisip-message- Unregistering module info [Authentication]...
2025-04-26 02:06:11:590 flexisip-message- Unregistering module info [Capabilities]...
�2025-04-26 02:06:11:590 flexisip-message- Unregistering module info [ContactRouteInserter]...
2025-04-26 02:06:11:590 flexisip-message- Unregistering module info [Forward]...
�2025-04-26 02:06:11:590 flexisip-message- Unregistering module info [GarbageIn]...
2025-04-26 02:06:11:590 flexisip-message- Unregistering module info [GatewayAdapter]...
V2025-04-26 02:06:11:590 flexisip-message- Unregistering module info [LoadBalancer]...
�2025-04-26 02:06:11:590 flexisip-message- Unregistering module info [MediaRelay]...
2025-04-26 02:06:11:590 flexisip-message- Unregistering module info [NatHelper]...
R2025-04-26 02:06:11:590 flexisip-message- Unregistering module info [Redirect]...
�2025-04-26 02:06:11:590 flexisip-message- Unregistering module info [Presence]...
2025-04-26 02:06:11:590 flexisip-message- Unregistering module info [PushNotification]...
�2025-04-26 02:06:11:590 flexisip-message- Unregistering module info [RegEvent]...
2025-04-26 02:06:11:590 flexisip-message- Unregistering module info [Registrar]...
�2025-04-26 02:06:11:590 flexisip-message- Unregistering module info [Router]...
2025-04-26 02:06:11:590 flexisip-message- Unregistering module info [SanityChecker]...
]2025-04-26 02:06:11:590 flexisip-message- Unregistering module info [StatisticsCollector]...
T2025-04-26 02:06:11:590 flexisip-message- Unregistering module info [Transcoder]...
sendToke() をAPIリクエスト対応へ入換え(追加箇所のみ掲載)
flexiapi/app/Libraries/FlexisipPusherConnector.php
use Illuminate\Support\Facades\Http;
public function sendToken(string $token)
{
$payload = json_encode(['token' => $token]);
if (!empty($this->pusherPath)) {
$cmd = [
$this->pusherPath,
'--pn-provider', $this->pnProvider,
'--pn-param', $this->pnParam,
'--pn-prid', $this->pnPrid,
'--customPayload', $payload,
];
if (in_array($this->pnProvider, ['apns', 'apns.dev'])) {
$cmd[] = '--apple-push-type';
$cmd[] = 'Background';
}
if ($this->pusherFirebaseKey) {
$cmd[] = '--key';
$cmd[] = $this->pusherFirebaseKey;
}
$containerId = 'ubuntu-flexisip';
$socketPath = '/run/user/1000/podman/podman.sock';
// create exec session
$execCreate = Http::withOptions([
'curl' => [
CURLOPT_UNIX_SOCKET_PATH => $socketPath,
]
])->withHeaders([
'Content-Type' => 'application/json',
])->post("http://d/v4.0.0/libpod/containers/{$containerId}/exec", [
'cmd' => $cmd,
'tty' => false,
'detach' => false,
]);
if (!$execCreate->successful()) {
Log::error('Failed to create exec session', ['body' => $execCreate->body()]);
return false;
}
$execId = $execCreate->json()['Id'] ?? null;
if (!$execId) {
Log::error('Exec ID missing');
return false;
}
// execute exec session
$execStart = Http::withOptions([
'curl' => [
CURLOPT_UNIX_SOCKET_PATH => $socketPath,
]
])->withHeaders([
'Content-Type' => 'application/json',
])->post("http://d/v4.0.0/libpod/exec/{$execId}/start", [
'Detach' => false,
'Tty' => false,
]);
if (!$execStart->successful()) {
Log::error('Failed to start exec session', ['body' => $execStart->body()]);
return false;
}
Log::info('Pusher executed via Podman', ['output' => $execStart->body()]);
return true;
}
Log::error('Pusher path not configured');
return false;
}
sendToken()テスト
tests/Feature/FlexisipPusherTest.php
<?php
namespace Tests\Feature;
use Tests\TestCase;
use App\Libraries\FlexisipPusherConnector;
class FlexisipPusherTest extends TestCase
{
public function test_send_token()
{
// Dummy data for testing
$provider = 'fcm';
$param = 'yourappid';
$prid = 'yourprid';
$token = 'dummy_push_token';
// Create instance
$pusher = new FlexisipPusherConnector($provider, $param, $prid);
// Execute
$result = $pusher->sendToken($token);
// Assert the result
$this->assertTrue($result, 'Pusher should return true');
}
}
テスト実行
# php artisan test --filter=FlexisipPusherTest
またはPHPUnitで直接実行
# vendor/bin/phpunit --filter=FlexisipPusherTest