Skip to content

Commit af6fa64

Browse files
authored
Merge pull request #207 from open-runtimes/new-runtimes-group
2 parents 88e1b0b + 7955031 commit af6fa64

4 files changed

Lines changed: 8 additions & 15 deletions

File tree

app/controllers.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
use Utopia\Orchestration\Adapter\DockerAPI;
2121

2222
Http::get('/v1/runtimes/:runtimeId/logs')
23-
->groups(['api'])
23+
->groups(['api', 'runtimes'])
2424
->desc("Get live stream of logs of a runtime")
2525
->param('runtimeId', '', new Text(64), 'Runtime unique ID.')
2626
->param('timeout', '600', new Text(16), 'Maximum logs timeout.', true)
@@ -119,7 +119,7 @@
119119
});
120120

121121
Http::get('/v1/runtimes/:runtimeId')
122-
->groups(['api'])
122+
->groups(['api', 'runtimes'])
123123
->desc("Get a runtime by its ID")
124124
->param('runtimeId', '', new Text(64), 'Runtime unique ID.')
125125
->inject('runner')
@@ -130,7 +130,7 @@
130130
});
131131

132132
Http::delete('/v1/runtimes/:runtimeId')
133-
->groups(['api'])
133+
->groups(['api', 'runtimes'])
134134
->desc('Delete a runtime')
135135
->param('runtimeId', '', new Text(64), 'Runtime unique ID.')
136136
->inject('response')
@@ -142,7 +142,7 @@
142142
});
143143

144144
Http::post('/v1/runtimes/:runtimeId/executions')
145-
->groups(['api'])
145+
->groups(['api', 'runtimes'])
146146
->alias('/v1/runtimes/:runtimeId/execution')
147147
->desc('Create an execution')
148148
// Execution-related

app/http.php

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
require_once __DIR__ . '/controllers.php';
99

1010
use OpenRuntimes\Executor\Runner\Docker;
11-
use OpenRuntimes\Executor\StorageFactory;
1211
use Swoole\Runtime;
1312
use Utopia\Console;
1413
use Utopia\Http\Http;
@@ -37,9 +36,8 @@
3736
System::getEnv('OPR_EXECUTOR_DOCKER_HUB_USERNAME', ''),
3837
System::getEnv('OPR_EXECUTOR_DOCKER_HUB_PASSWORD', '')
3938
));
40-
$storageFactory = new StorageFactory();
4139
$networks = explode(',', System::getEnv('OPR_EXECUTOR_NETWORK') ?: 'openruntimes-runtimes');
42-
$runner = new Docker($orchestration, $storageFactory, $networks);
40+
$runner = new Docker($orchestration, $networks);
4341
Http::setResource('runner', fn () => $runner);
4442

4543
$payloadSize = 22 * (1024 * 1024);

src/Executor/Runner/Docker.php

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -28,24 +28,19 @@ class Docker extends Adapter
2828
{
2929
private Table $activeRuntimes;
3030
private Stats $stats;
31-
private StorageFactory $storageFactory;
3231
/**
3332
* @var string[]
3433
*/
3534
private array $networks;
3635

3736
/**
3837
* @param Orchestration $orchestration
39-
* @param StorageFactory $storageFactory
4038
* @param string[] $networks
4139
*/
4240
public function __construct(
4341
private readonly Orchestration $orchestration,
44-
StorageFactory $storageFactory,
4542
array $networks
4643
) {
47-
$this->storageFactory = $storageFactory;
48-
4944
$this->activeRuntimes = new Table(4096);
5045

5146
$this->activeRuntimes->column('version', Table::TYPE_STRING, 32);
@@ -461,7 +456,7 @@ public function createRuntime(
461456
$tmpLogging = "/{$tmpFolder}logging"; // Build logs
462457
$tmpLogs = "/{$tmpFolder}logs"; // Runtime logs
463458

464-
$sourceDevice = $this->storageFactory->getDevice("/", System::getEnv('OPR_EXECUTOR_CONNECTION_STORAGE'));
459+
$sourceDevice = StorageFactory::getDevice("/", System::getEnv('OPR_EXECUTOR_CONNECTION_STORAGE'));
465460
$localDevice = new Local();
466461

467462
try {
@@ -588,7 +583,7 @@ public function createRuntime(
588583
$size = $localDevice->getFileSize($tmpBuild);
589584
$container['size'] = $size;
590585

591-
$destinationDevice = $this->storageFactory->getDevice($destination, System::getEnv('OPR_EXECUTOR_CONNECTION_STORAGE'));
586+
$destinationDevice = StorageFactory::getDevice($destination, System::getEnv('OPR_EXECUTOR_CONNECTION_STORAGE'));
592587
$path = $destinationDevice->getPath(\uniqid() . '.' . \pathinfo($tmpBuild, PATHINFO_EXTENSION));
593588

594589
if (!$localDevice->transfer($tmpBuild, $path, $destinationDevice)) {

src/Executor/StorageFactory.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ class StorageFactory
2323
* @param ?string $connection DSN connection string. If empty or null, the local device will be used.
2424
* @return Device
2525
*/
26-
public function getDevice(string $root, ?string $connection = ''): Device
26+
public static function getDevice(string $root, ?string $connection = ''): Device
2727
{
2828
$connection = $connection ?? '';
2929
$acl = 'private';

0 commit comments

Comments
 (0)