fix: base_dir wip & outputs

This commit is contained in:
Andras Bacsai
2023-07-07 14:56:20 +02:00
parent a6d9f2d636
commit f38a9f36a1
3 changed files with 22 additions and 13 deletions

View File

@@ -132,7 +132,12 @@ class General extends Component
$domains = Str::of($this->application->fqdn)->trim()->explode(',')->map(function ($domain) { $domains = Str::of($this->application->fqdn)->trim()->explode(',')->map(function ($domain) {
return Str::of($domain)->trim()->lower(); return Str::of($domain)->trim()->lower();
}); });
if ($this->application->base_directory && $this->application->base_directory !== '/') {
$this->application->base_directory = rtrim($this->application->base_directory, '/');
}
if ($this->application->publish_directory && $this->application->publish_directory !== '/') {
$this->application->publish_directory = rtrim($this->application->publish_directory, '/');
}
$this->application->fqdn = $domains->implode(','); $this->application->fqdn = $domains->implode(',');
$this->application->save(); $this->application->save();
$this->emit('success', 'Application settings updated!'); $this->emit('success', 'Application settings updated!');

View File

@@ -19,6 +19,7 @@ use Illuminate\Foundation\Bus\Dispatchable;
use Illuminate\Queue\InteractsWithQueue; use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Queue\SerializesModels; use Illuminate\Queue\SerializesModels;
use Illuminate\Support\Collection; use Illuminate\Support\Collection;
use Illuminate\Support\Facades\Storage;
use Spatie\Url\Url; use Spatie\Url\Url;
use Illuminate\Support\Str; use Illuminate\Support\Str;
use Symfony\Component\Yaml\Yaml; use Symfony\Component\Yaml\Yaml;
@@ -48,6 +49,7 @@ class ApplicationDeploymentJob implements ShouldQueue
private string $container_name; private string $container_name;
private string $workdir; private string $workdir;
private string $build_workdir;
private string $build_image_name; private string $build_image_name;
private string $production_image_name; private string $production_image_name;
private bool $is_debug_enabled; private bool $is_debug_enabled;
@@ -76,6 +78,7 @@ class ApplicationDeploymentJob implements ShouldQueue
$this->private_key_location = save_private_key_for_server($this->server); $this->private_key_location = save_private_key_for_server($this->server);
$this->workdir = "/artifacts/{$this->deployment_uuid}"; $this->workdir = "/artifacts/{$this->deployment_uuid}";
$this->build_workdir = "{$this->workdir}" . rtrim($this->application->base_directory, '/');
$this->is_debug_enabled = $this->application->settings->is_debug_enabled; $this->is_debug_enabled = $this->application->settings->is_debug_enabled;
$this->container_name = generate_container_name($this->application->uuid, $this->pull_request_id); $this->container_name = generate_container_name($this->application->uuid, $this->pull_request_id);
@@ -104,6 +107,7 @@ class ApplicationDeploymentJob implements ShouldQueue
public function handle(): void public function handle(): void
{ {
ray()->measure();
$this->application_deployment_queue->update([ $this->application_deployment_queue->update([
'status' => ApplicationDeploymentStatus::IN_PROGRESS->value, 'status' => ApplicationDeploymentStatus::IN_PROGRESS->value,
]); ]);
@@ -116,31 +120,32 @@ class ApplicationDeploymentJob implements ShouldQueue
$this->next(ApplicationDeploymentStatus::FINISHED->value); $this->next(ApplicationDeploymentStatus::FINISHED->value);
} catch (\Exception $e) { } catch (\Exception $e) {
ray($e); ray($e);
$this->execute_remote_command([ $this->fail($e);
["echo '\nOops something is not okay, are you okay? 😢'"],
["echo '\n\n{$e->getMessage()}'"]
]);
$this->fail($e->getMessage());
} finally { } finally {
// if (isset($this->docker_compose)) { if (isset($this->docker_compose)) {
// Storage::disk('deployments')->put(Str::kebab($this->application->name) . '/docker-compose.yml', $this->docker_compose); Storage::disk('deployments')->put(Str::kebab($this->application->name) . '/docker-compose.yml', $this->docker_compose);
// } }
$this->execute_remote_command( $this->execute_remote_command(
[ [
"docker rm -f {$this->deployment_uuid} >/dev/null 2>&1", "docker rm -f {$this->deployment_uuid} >/dev/null 2>&1",
"hidden" => true, "hidden" => true,
] ]
); );
ray()->measure();
} }
} }
public function failed(Throwable $exception): void public function failed(Throwable $exception): void
{ {
ray($exception); $this->execute_remote_command(
["echo 'Oops something is not okay, are you okay? 😢'"],
["echo '{$exception->getMessage()}'"]
);
$this->next(ApplicationDeploymentStatus::FAILED->value); $this->next(ApplicationDeploymentStatus::FAILED->value);
} }
private function execute_in_builder(string $command) private function execute_in_builder(string $command)
{ {
return "docker exec {$this->deployment_uuid} bash -c '{$command} |& tee -a /proc/1/fd/1'"; return "docker exec {$this->deployment_uuid} bash -c '{$command}'";
// return "docker exec {$this->deployment_uuid} bash -c '{$command} |& tee -a /proc/1/fd/1; [ \$PIPESTATUS -eq 0 ] || exit \$PIPESTATUS'";
} }
private function deploy() private function deploy()
{ {
@@ -384,7 +389,6 @@ COPY ./nginx.conf /etc/nginx/conf.d/default.conf");
} }
$local_persistent_volumes[] = $volume_name . ':' . $persistentStorage->mount_path; $local_persistent_volumes[] = $volume_name . ':' . $persistentStorage->mount_path;
} }
ray('local_persistent_volumes', $local_persistent_volumes)->green();
return $local_persistent_volumes; return $local_persistent_volumes;
} }
private function generate_local_persistent_volumes_only_volume_names() private function generate_local_persistent_volumes_only_volume_names()

View File

@@ -44,7 +44,7 @@
</div> </div>
<div class="flex flex-col gap-2 xl:flex-row"> <div class="flex flex-col gap-2 xl:flex-row">
<x-forms.input placeholder="/" id="application.base_directory" label="Base Directory" <x-forms.input placeholder="/" id="application.base_directory" label="Base Directory"
helper="Directory to use as root. Useful for monorepos." /> helper="Directory to use as root. Useful for monorepos. WIP" disabled />
@if ($application->settings->is_static) @if ($application->settings->is_static)
<x-forms.input placeholder="/dist" id="application.publish_directory" label="Publish Directory" <x-forms.input placeholder="/dist" id="application.publish_directory" label="Publish Directory"
required /> required />