wip
This commit is contained in:
parent
2e8b1134b9
commit
ab588d37c0
@ -27,19 +27,39 @@ class DeployApplication extends Component
|
|||||||
$this->application = Application::find($this->applicationId)->first();
|
$this->application = Application::find($this->applicationId)->first();
|
||||||
$this->destination = $this->application->destination->getMorphClass()::where('id', $this->application->destination->id)->first();
|
$this->destination = $this->application->destination->getMorphClass()::where('id', $this->application->destination->id)->first();
|
||||||
}
|
}
|
||||||
|
protected function setDeploymentUuid()
|
||||||
public function start()
|
|
||||||
{
|
{
|
||||||
// Create Deployment ID
|
// Create Deployment ID
|
||||||
$this->deployment_uuid = new Cuid2(7);
|
$this->deployment_uuid = new Cuid2(7);
|
||||||
$this->parameters['deployment_uuid'] = $this->deployment_uuid;
|
$this->parameters['deployment_uuid'] = $this->deployment_uuid;
|
||||||
|
}
|
||||||
|
protected function redirectToDeployment()
|
||||||
|
{
|
||||||
|
return redirect()->route('project.applications.deployment', $this->parameters);
|
||||||
|
}
|
||||||
|
public function start()
|
||||||
|
{
|
||||||
|
$this->setDeploymentUuid();
|
||||||
|
|
||||||
dispatch(new DeployApplicationJob(
|
dispatch(new DeployApplicationJob(
|
||||||
deployment_uuid: $this->deployment_uuid,
|
deployment_uuid: $this->deployment_uuid,
|
||||||
application_uuid: $this->application->uuid,
|
application_uuid: $this->application->uuid,
|
||||||
|
force_rebuild: false,
|
||||||
));
|
));
|
||||||
|
|
||||||
return redirect()->route('project.applications.deployment', $this->parameters);
|
return $this->redirectToDeployment();
|
||||||
|
}
|
||||||
|
public function forceRebuild()
|
||||||
|
{
|
||||||
|
$this->setDeploymentUuid();
|
||||||
|
|
||||||
|
dispatch(new DeployApplicationJob(
|
||||||
|
deployment_uuid: $this->deployment_uuid,
|
||||||
|
application_uuid: $this->application->uuid,
|
||||||
|
force_rebuild: true,
|
||||||
|
));
|
||||||
|
|
||||||
|
return $this->redirectToDeployment();
|
||||||
}
|
}
|
||||||
|
|
||||||
public function stop()
|
public function stop()
|
||||||
|
@ -43,6 +43,7 @@ class DeployApplicationJob implements ShouldQueue
|
|||||||
public function __construct(
|
public function __construct(
|
||||||
public string $deployment_uuid,
|
public string $deployment_uuid,
|
||||||
public string $application_uuid,
|
public string $application_uuid,
|
||||||
|
public bool $force_rebuild = false,
|
||||||
) {
|
) {
|
||||||
$this->application = Application::query()
|
$this->application = Application::query()
|
||||||
->where('uuid', $this->application_uuid)
|
->where('uuid', $this->application_uuid)
|
||||||
@ -86,7 +87,7 @@ class DeployApplicationJob implements ShouldQueue
|
|||||||
|
|
||||||
// Set wildcard domain
|
// Set wildcard domain
|
||||||
if (!$this->application->settings->is_bot && !$this->application->fqdn && $wildcard_domain) {
|
if (!$this->application->settings->is_bot && !$this->application->fqdn && $wildcard_domain) {
|
||||||
$this->application->fqdn = $this->application->uuid . '.' . $wildcard_domain;
|
$this->application->fqdn = 'http://' . $this->application->uuid . '.' . $wildcard_domain;
|
||||||
$this->application->save();
|
$this->application->save();
|
||||||
}
|
}
|
||||||
$this->workdir = "/artifacts/{$this->deployment_uuid}";
|
$this->workdir = "/artifacts/{$this->deployment_uuid}";
|
||||||
@ -116,24 +117,28 @@ class DeployApplicationJob implements ShouldQueue
|
|||||||
$this->executeNow([$this->execute_in_builder("cd {$this->workdir} && git rev-parse HEAD")], 'commit_sha', hideFromOutput: true);
|
$this->executeNow([$this->execute_in_builder("cd {$this->workdir} && git rev-parse HEAD")], 'commit_sha', hideFromOutput: true);
|
||||||
$this->git_commit = $this->activity->properties->get('commit_sha');
|
$this->git_commit = $this->activity->properties->get('commit_sha');
|
||||||
|
|
||||||
$this->executeNow([
|
if (!$this->force_rebuild) {
|
||||||
"docker inspect {$this->application->uuid} --format '{{json .Config.Image}}' 2>&1",
|
|
||||||
], 'stopped_container_image', hideFromOutput: true, ignoreErrors: true);
|
|
||||||
$image = $this->activity->properties->get('stopped_container_image');
|
|
||||||
if (isset($image)) {
|
|
||||||
$image = explode(':', str_replace('"', '', $image))[1];
|
|
||||||
if ($image == $this->git_commit) {
|
|
||||||
$this->executeNow([
|
|
||||||
"echo -n 'Application found locally with the same Git Commit SHA. Starting it... '"
|
|
||||||
]);
|
|
||||||
$this->executeNow([
|
|
||||||
"docker start {$this->application->uuid}"
|
|
||||||
], hideFromOutput: true);
|
|
||||||
|
|
||||||
$this->executeNow([
|
|
||||||
"echo 'Done. 🎉'",
|
$this->executeNow([
|
||||||
], isFinished: true);
|
"docker inspect {$this->application->uuid} --format '{{json .Config.Image}}' 2>&1",
|
||||||
return;
|
], 'stopped_container_image', hideFromOutput: true, ignoreErrors: true);
|
||||||
|
$image = $this->activity->properties->get('stopped_container_image');
|
||||||
|
if (isset($image)) {
|
||||||
|
$image = explode(':', str_replace('"', '', $image))[1];
|
||||||
|
if ($image == $this->git_commit) {
|
||||||
|
$this->executeNow([
|
||||||
|
"echo -n 'Application found locally with the same Git Commit SHA. Starting it... '"
|
||||||
|
]);
|
||||||
|
$this->executeNow([
|
||||||
|
"docker start {$this->application->uuid}"
|
||||||
|
], hideFromOutput: true);
|
||||||
|
|
||||||
|
$this->executeNow([
|
||||||
|
"echo 'Done. 🎉'",
|
||||||
|
], isFinished: true);
|
||||||
|
return;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
$this->executeNow([
|
$this->executeNow([
|
||||||
|
@ -1,13 +1,19 @@
|
|||||||
<div>
|
<div>
|
||||||
@if ($application->status === 'running')
|
@if ($application->status === 'running')
|
||||||
|
<button wire:click='start'>Restart</button>
|
||||||
|
<button wire:click='forceRebuild'>Force Rebuild</button>
|
||||||
<button wire:click='stop'>Stop</button>
|
<button wire:click='stop'>Stop</button>
|
||||||
@else
|
@else
|
||||||
<button wire:click='start'>Start</button>
|
<button wire:click='start'>Start</button>
|
||||||
|
<button wire:click='forceRebuild'>Start (no cache)</button>
|
||||||
@endif
|
@endif
|
||||||
<button wire:click='kill'>Kill</button>
|
<button wire:click='kill'>Kill</button>
|
||||||
<span wire:poll='pollingStatus'>
|
<span wire:poll='pollingStatus'>
|
||||||
@if ($application->status === 'running')
|
@if ($application->status === 'running')
|
||||||
<span class="text-green-500">{{ $application->status }}</span>
|
<span class="text-green-500">{{ $application->status }}</span>
|
||||||
|
@if (!data_get($application, 'settings.is_bot') && data_get($application, 'fqdn'))
|
||||||
|
<a target="_blank" href="{{ data_get($application, 'fqdn') }}">Open</a>
|
||||||
|
@endif
|
||||||
@else
|
@else
|
||||||
<span class="text-red-500">{{ $application->status }}</span>
|
<span class="text-red-500">{{ $application->status }}</span>
|
||||||
@endif
|
@endif
|
||||||
|
@ -13,7 +13,7 @@
|
|||||||
<livewire:application.general :applicationId="$application->id" />
|
<livewire:application.general :applicationId="$application->id" />
|
||||||
</div>
|
</div>
|
||||||
<div x-cloak x-show="tab === 'secrets'">
|
<div x-cloak x-show="tab === 'secrets'">
|
||||||
<livewire:application.secrets />
|
<livewire:application.secrets />
|
||||||
</div>
|
</div>
|
||||||
<div x-cloak x-show="tab === 'source'">
|
<div x-cloak x-show="tab === 'source'">
|
||||||
<livewire:application.source :applicationId="$application->id" />
|
<livewire:application.source :applicationId="$application->id" />
|
||||||
|
Loading…
x
Reference in New Issue
Block a user