feat: Improve error handling in loadComposeFile method
This commit is contained in:
parent
893339fc8e
commit
4225ec7060
@ -1081,45 +1081,55 @@ public function loadComposeFile($isInit = false)
|
|||||||
'git read-tree -mu HEAD',
|
'git read-tree -mu HEAD',
|
||||||
"cat .$workdir$composeFile",
|
"cat .$workdir$composeFile",
|
||||||
]);
|
]);
|
||||||
$composeFileContent = instant_remote_process($commands, $this->destination->server, false);
|
try {
|
||||||
if (! $composeFileContent) {
|
$composeFileContent = instant_remote_process($commands, $this->destination->server);
|
||||||
|
} catch (\Exception $e) {
|
||||||
|
if (str($e->getMessage())->contains('No such file')) {
|
||||||
|
throw new \RuntimeException("Docker Compose file not found at: $workdir$composeFile<br><br>Check if you used the right extension (.yaml or .yml) in the compose file name.");
|
||||||
|
}
|
||||||
|
if (str($e->getMessage())->contains('fatal: repository') && str($e->getMessage())->contains('does not exist')) {
|
||||||
|
if ($this->deploymentType() === 'deploy_key') {
|
||||||
|
throw new \RuntimeException('Your deploy key does not have access to the repository. Please check your deploy key and try again.');
|
||||||
|
}
|
||||||
|
throw new \RuntimeException('Repository does not exist. Please check your repository URL and try again.');
|
||||||
|
}
|
||||||
|
throw new \RuntimeException($e->getMessage());
|
||||||
|
} finally {
|
||||||
$this->docker_compose_location = $initialDockerComposeLocation;
|
$this->docker_compose_location = $initialDockerComposeLocation;
|
||||||
$this->save();
|
$this->save();
|
||||||
$commands = collect([
|
$commands = collect([
|
||||||
"rm -rf /tmp/{$uuid}",
|
"rm -rf /tmp/{$uuid}",
|
||||||
]);
|
]);
|
||||||
instant_remote_process($commands, $this->destination->server, false);
|
instant_remote_process($commands, $this->destination->server, false);
|
||||||
throw new \RuntimeException("Docker Compose file not found at: $workdir$composeFile<br><br>Check if you used the right extension (.yaml or .yml) in the compose file name.");
|
}
|
||||||
} else {
|
if ($composeFileContent) {
|
||||||
$this->docker_compose_raw = $composeFileContent;
|
$this->docker_compose_raw = $composeFileContent;
|
||||||
$this->save();
|
$this->save();
|
||||||
}
|
$parsedServices = $this->parseCompose();
|
||||||
|
if ($this->docker_compose_domains) {
|
||||||
$commands = collect([
|
$json = collect(json_decode($this->docker_compose_domains));
|
||||||
"rm -rf /tmp/{$uuid}",
|
$names = collect(data_get($parsedServices, 'services'))->keys()->toArray();
|
||||||
]);
|
$jsonNames = $json->keys()->toArray();
|
||||||
instant_remote_process($commands, $this->destination->server, false);
|
$diff = array_diff($jsonNames, $names);
|
||||||
$parsedServices = $this->parseCompose();
|
$json = $json->filter(function ($value, $key) use ($diff) {
|
||||||
if ($this->docker_compose_domains) {
|
return ! in_array($key, $diff);
|
||||||
$json = collect(json_decode($this->docker_compose_domains));
|
});
|
||||||
$names = collect(data_get($parsedServices, 'services'))->keys()->toArray();
|
if ($json) {
|
||||||
$jsonNames = $json->keys()->toArray();
|
$this->docker_compose_domains = json_encode($json);
|
||||||
$diff = array_diff($jsonNames, $names);
|
} else {
|
||||||
$json = $json->filter(function ($value, $key) use ($diff) {
|
$this->docker_compose_domains = null;
|
||||||
return ! in_array($key, $diff);
|
}
|
||||||
});
|
$this->save();
|
||||||
if ($json) {
|
|
||||||
$this->docker_compose_domains = json_encode($json);
|
|
||||||
} else {
|
|
||||||
$this->docker_compose_domains = null;
|
|
||||||
}
|
}
|
||||||
$this->save();
|
|
||||||
|
return [
|
||||||
|
'parsedServices' => $parsedServices,
|
||||||
|
'initialDockerComposeLocation' => $this->docker_compose_location,
|
||||||
|
];
|
||||||
|
} else {
|
||||||
|
throw new \RuntimeException("Docker Compose file not found at: $workdir$composeFile<br><br>Check if you used the right extension (.yaml or .yml) in the compose file name.");
|
||||||
}
|
}
|
||||||
|
|
||||||
return [
|
|
||||||
'parsedServices' => $parsedServices,
|
|
||||||
'initialDockerComposeLocation' => $this->docker_compose_location,
|
|
||||||
];
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function parseContainerLabels(?ApplicationPreview $preview = null)
|
public function parseContainerLabels(?ApplicationPreview $preview = null)
|
||||||
|
Loading…
Reference in New Issue
Block a user