feat: catch docker remove errors elegantly
This commit is contained in:
parent
dea2873845
commit
6ab1095280
|
@ -652,14 +652,14 @@ App::delete('/v1/deployments/:deploymentId')
|
|||
|
||||
// Remove all the build containers
|
||||
foreach ($buildIds as $buildId) {
|
||||
$status = $orchestration->remove('build-stage-' . $buildId, true);
|
||||
if ($status) {
|
||||
Console::success("Removed build container: $buildId for deployment: " . $deploymentId);
|
||||
} else {
|
||||
Console::error("Failed to remove build container: $buildId for deployment: " . $deploymentId);
|
||||
try {
|
||||
Console::info('Deleting build container : ' . $buildId);
|
||||
$status = $orchestration->remove('build-stage-' . $buildId, true);
|
||||
} catch (Throwable $th) {
|
||||
Console::error($th->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
$orchestrationPool->put($orchestration);
|
||||
|
||||
$response
|
||||
|
|
|
@ -358,7 +358,7 @@ class DeletesV1 extends Worker
|
|||
$executor = new Executor();
|
||||
foreach ($deploymentIds as $deploymentId) {
|
||||
try {
|
||||
$executor->deleteRuntime($deploymentId, $projectId);
|
||||
$executor->deleteRuntime($deploymentId, $buildIds[$deploymentId], $projectId);
|
||||
} catch (Throwable $th) {
|
||||
Console::error($th->getMessage());
|
||||
}
|
||||
|
@ -373,6 +373,7 @@ class DeletesV1 extends Worker
|
|||
protected function deleteDeployment(Document $document, string $projectId): void
|
||||
{
|
||||
$dbForProject = $this->getProjectDB($projectId);
|
||||
$deploymentId = $document->getId();
|
||||
|
||||
/**
|
||||
* Delete deployment files
|
||||
|
@ -390,8 +391,8 @@ class DeletesV1 extends Worker
|
|||
$buildIds = [];
|
||||
$storageBuilds = new Local(APP_STORAGE_BUILDS . '/app-' . $projectId);
|
||||
$this->deleteByGroup('builds', [
|
||||
new Query('deploymentId', Query::TYPE_EQUAL, [$document->getId()])
|
||||
], $dbForProject, function (Document $document) use ($storageBuilds) {
|
||||
new Query('deploymentId', Query::TYPE_EQUAL, [$deploymentId])
|
||||
], $dbForProject, function (Document $document) use ($storageBuilds, &$buildIds) {
|
||||
$buildIds[] = $document->getId();
|
||||
if ($storageBuilds->delete($document->getAttribute('outputPath', ''), true)) {
|
||||
Console::success('Deleted build files: ' . $document->getAttribute('outputPath', ''));
|
||||
|
@ -405,7 +406,7 @@ class DeletesV1 extends Worker
|
|||
*/
|
||||
try {
|
||||
$executor = new Executor();
|
||||
$executor->deleteRuntime($document->getId(), $projectId);
|
||||
$executor->deleteRuntime($deploymentId, $buildIds, $projectId);
|
||||
} catch (Throwable $th) {
|
||||
Console::error($th->getMessage());
|
||||
}
|
||||
|
|
|
@ -63,7 +63,7 @@ class Executor
|
|||
return $response['body'];
|
||||
}
|
||||
|
||||
public function deleteRuntime(string $deploymentId, string $projectId)
|
||||
public function deleteRuntime(string $deploymentId, array $buildIds, string $projectId)
|
||||
{
|
||||
$route = "/deployments/$deploymentId";
|
||||
$headers = [
|
||||
|
@ -72,14 +72,14 @@ class Executor
|
|||
'x-appwrite-executor-key' => App::getEnv('_APP_EXECUTOR_SECRET', '')
|
||||
];
|
||||
$params = [
|
||||
'buildIds' => $buildIds[$deploymentId] ?? [],
|
||||
'buildIds' => $buildIds,
|
||||
];
|
||||
|
||||
$response = $this->call(self::METHOD_DELETE, $route, $headers, $params, true, 30);
|
||||
|
||||
$status = $response['headers']['status-code'];
|
||||
if ($status >= 400) {
|
||||
throw new \Exception('Error deleting deplyoment: ' . $deploymentId , $status);
|
||||
throw new \Exception('Error deleting deployment: ' . $deploymentId , $status);
|
||||
}
|
||||
|
||||
return $response['body'];
|
||||
|
|
Loading…
Reference in a new issue