add custom git commit deployment

This commit is contained in:
Andras Bacsai 2023-05-10 12:22:27 +02:00
parent 775ee5d27a
commit fe6ecd465e
10 changed files with 37 additions and 15 deletions

View File

@ -21,7 +21,7 @@ public function configuration()
if (!$application) { if (!$application) {
return redirect()->route('dashboard'); return redirect()->route('dashboard');
} }
return view('project.application.configuration', ['application' => $application]); return view('project.application.configuration', ['application' => $application,]);
} }
public function deployments() public function deployments()
{ {

View File

@ -19,4 +19,13 @@ public function mount()
{ {
$this->application = Application::where('id', $this->applicationId)->first(); $this->application = Application::where('id', $this->applicationId)->first();
} }
public function submit()
{
$this->validate();
if (!$this->application->git_commit_sha) {
$this->application->git_commit_sha = 'HEAD';
}
$this->application->save();
$this->emit('saved', 'Application source updated!');
}
} }

View File

@ -430,8 +430,8 @@ private function executeNow(
} }
private function setGitImportSettings($git_clone_command) private function setGitImportSettings($git_clone_command)
{ {
if ($this->application->git_commit_sha) { if ($this->application->git_commit_sha !== 'HEAD') {
$git_clone_command = "{$git_clone_command} && cd {$this->workdir} && git checkout {$this->application->git_commit_sha}"; $git_clone_command = "{$git_clone_command} && cd {$this->workdir} && git -c advice.detachedHead=false checkout {$this->application->git_commit_sha} >/dev/null 2>&1";
} }
if ($this->application->settings->is_git_submodules_allowed) { if ($this->application->settings->is_git_submodules_allowed) {
$git_clone_command = "{$git_clone_command} && cd {$this->workdir} && git submodule update --init --recursive"; $git_clone_command = "{$git_clone_command} && cd {$this->workdir} && git submodule update --init --recursive";

View File

@ -44,17 +44,24 @@ public function publishDirectory(): Attribute
set: fn ($value) => $value ? '/' . ltrim($value, '/') : null, set: fn ($value) => $value ? '/' . ltrim($value, '/') : null,
); );
} }
public function gitLocation(): Attribute public function gitBranchLocation(): Attribute
{ {
return Attribute::make( return Attribute::make(
get: function () { get: function () {
if (!is_null($this->source?->html_url) && !is_null($this->git_repository) && !is_null($this->git_branch)) { if (!is_null($this->source?->html_url) && !is_null($this->git_repository) && !is_null($this->git_branch)) {
if (is_null($this->git_commit_sha)) {
return "{$this->source->html_url}/{$this->git_repository}/tree/{$this->git_branch}"; return "{$this->source->html_url}/{$this->git_repository}/tree/{$this->git_branch}";
} else {
return "{$this->source->html_url}/{$this->git_repository}/tree/{$this->git_commit_sha}";
} }
} }
);
}
public function gitCommits(): Attribute
{
return Attribute::make(
get: function () {
if (!is_null($this->source?->html_url) && !is_null($this->git_repository) && !is_null($this->git_branch)) {
return "{$this->source->html_url}/{$this->git_repository}/commits/{$this->git_branch}";
}
} }
); );

View File

@ -22,7 +22,7 @@ public function up(): void
$table->string('git_repository'); $table->string('git_repository');
$table->string('git_branch'); $table->string('git_branch');
$table->string('git_commit_sha')->nullable(); $table->string('git_commit_sha')->default('HEAD');
$table->string('docker_registry_image_name')->nullable(); $table->string('docker_registry_image_name')->nullable();
$table->string('docker_registry_image_tag')->nullable(); $table->string('docker_registry_image_tag')->nullable();

View File

@ -1,5 +1,5 @@
<nav class="flex gap-4 py-2"> <nav class="flex gap-4 py-2">
<a target="_blank" href="{{ $gitLocation }}"> <a target="_blank" href="{{ $gitBranchLocation }}">
<x-inputs.button>Open on Git ↗️</x-inputs.button> <x-inputs.button>Open on Git ↗️</x-inputs.button>
</a> </a>
<a <a

View File

@ -4,6 +4,12 @@
<div class="flex flex-col w-96"> <div class="flex flex-col w-96">
<x-inputs.input id="application.git_repository" label="Git Repository" readonly /> <x-inputs.input id="application.git_repository" label="Git Repository" readonly />
<x-inputs.input id="application.git_branch" label="Git Branch" readonly /> <x-inputs.input id="application.git_branch" label="Git Branch" readonly />
<x-inputs.input id="application.git_commit_sha" label="Git Commit SHA" readonly /> <form wire:submit.prevent='submit'>
<x-inputs.input id="application.git_commit_sha" placeholder="HEAD" label="Git Commit SHA" />
<x-inputs.button type="submit">Save</x-inputs.button>
</form>
<a target="_blank" href="{{ $application->gitCommits }}">
<x-inputs.button>Commits ↗️</x-inputs.button>
</a>
</div> </div>
</div> </div>

View File

@ -1,6 +1,6 @@
<x-layout> <x-layout>
<h1>Configuration</h1> <h1>Configuration</h1>
<x-applications.navbar :applicationId="$application->id" :gitLocation="$application->gitLocation" /> <x-applications.navbar :applicationId="$application->id" :gitBranchLocation="$application->gitBranchLocation" />
<div x-data="{ activeTab: window.location.hash ? window.location.hash.substring(1) : 'general' }"> <div x-data="{ activeTab: window.location.hash ? window.location.hash.substring(1) : 'general' }">
<div class="flex gap-4"> <div class="flex gap-4">
<a :class="activeTab === 'general' && 'text-purple-500'" <a :class="activeTab === 'general' && 'text-purple-500'"

View File

@ -1,5 +1,5 @@
<x-layout> <x-layout>
<h1>Deployment</h1> <h1>Deployment</h1>
<x-applications.navbar :applicationId="$application->id" :gitLocation="$application->gitLocation" /> <x-applications.navbar :applicationId="$application->id" :gitBranchLocation="$application->gitBranchLocation" />
<livewire:project.application.poll-deployment :activity="$activity" :deployment_uuid="$deployment_uuid" /> <livewire:project.application.poll-deployment :activity="$activity" :deployment_uuid="$deployment_uuid" />
</x-layout> </x-layout>

View File

@ -1,6 +1,6 @@
<x-layout> <x-layout>
<h1>Deployments</h1> <h1>Deployments</h1>
<x-applications.navbar :applicationId="$application->id" :gitLocation="$application->gitLocation" /> <x-applications.navbar :applicationId="$application->id" :gitBranchLocation="$application->gitBranchLocation" />
<div class="pt-2"> <div class="pt-2">
@forelse ($deployments as $deployment) @forelse ($deployments as $deployment)
<livewire:project.application.get-deployments :deployment_uuid="data_get($deployment->properties, 'type_uuid')" :created_at="data_get($deployment, 'created_at')" :status="data_get($deployment->properties, 'status')" /> <livewire:project.application.get-deployments :deployment_uuid="data_get($deployment->properties, 'type_uuid')" :created_at="data_get($deployment, 'created_at')" :status="data_get($deployment->properties, 'status')" />