fix: new logging for deployment jobs

fix: git based docker compose files
This commit is contained in:
Andras Bacsai
2023-11-27 11:54:55 +01:00
parent fae97e4dee
commit 8d86d53292
21 changed files with 247 additions and 168 deletions

View File

@@ -8,6 +8,7 @@ use Spatie\Activitylog\Models\Activity;
use Illuminate\Support\Str;
use RuntimeException;
use Symfony\Component\Yaml\Yaml;
use Visus\Cuid2\Cuid2;
class Application extends BaseModel
{
@@ -47,6 +48,10 @@ class Application extends BaseModel
$application->environment_variables_preview()->delete();
});
}
public function deployableComposeBuildPack()
{
return $this->build_pack === 'dockercompose' && $this->docker_compose_raw;
}
public function link()
{
return route('project.application.configuration', [
@@ -592,4 +597,42 @@ class Application extends BaseModel
return collect([]);
}
}
function loadComposeFile($isInit = false)
{
$initialDockerComposeLocation = $this->docker_compose_location;
if ($this->build_pack === 'dockercompose') {
if ($isInit && $this->docker_compose_raw) {
return;
}
$uuid = new Cuid2();
['commands' => $cloneCommand] = $this->generateGitImportCommands(deployment_uuid: $uuid, only_checkout: true, exec_in_docker: false, custom_base_dir: '.');
$workdir = rtrim($this->base_directory, '/');
$composeFile = $this->docker_compose_location;
$commands = collect([
"mkdir -p /tmp/{$uuid} && cd /tmp/{$uuid}",
$cloneCommand,
"git sparse-checkout init --cone",
"git sparse-checkout set .$workdir$composeFile",
"git read-tree -mu HEAD",
"cat .$workdir$composeFile",
]);
$composeFileContent = instant_remote_process($commands, $this->destination->server, false);
if (!$composeFileContent) {
$this->docker_compose_location = $initialDockerComposeLocation;
$this->save();
throw new \Exception("Could not load compose file from $workdir$composeFile");
} else {
$this->docker_compose_raw = $composeFileContent;
$this->save();
}
$commands = collect([
"rm -rf /tmp/{$uuid}",
]);
instant_remote_process($commands, $this->destination->server, false);
return [
'parsedServices' => $this->parseCompose(),
'initialDockerComposeLocation' => $this->docker_compose_location
];
}
}
}