improvement: add basedir + compose file in new compose based apps

This commit is contained in:
Andras Bacsai 2024-07-15 16:39:22 +02:00
parent 4ee1f1a507
commit 356e7b57d2
6 changed files with 88 additions and 9 deletions

View File

@ -53,6 +53,12 @@ class GithubPrivateRepository extends Component
public ?string $publish_directory = null; public ?string $publish_directory = null;
// In case of docker compose
public ?string $base_directory = null;
public ?string $docker_compose_location = '/docker-compose.yaml';
// End of docker compose
protected int $page = 1; protected int $page = 1;
public $build_pack = 'nixpacks'; public $build_pack = 'nixpacks';
@ -68,6 +74,16 @@ public function mount()
$this->github_apps = GithubApp::private(); $this->github_apps = GithubApp::private();
} }
public function updatedBaseDirectory()
{
if ($this->base_directory) {
$this->base_directory = rtrim($this->base_directory, '/');
if (! str($this->base_directory)->startsWith('/')) {
$this->base_directory = '/'.$this->base_directory;
}
}
}
public function updatedBuildPack() public function updatedBuildPack()
{ {
if ($this->build_pack === 'nixpacks') { if ($this->build_pack === 'nixpacks') {
@ -184,6 +200,10 @@ public function submit()
if ($this->build_pack === 'dockerfile' || $this->build_pack === 'dockerimage') { if ($this->build_pack === 'dockerfile' || $this->build_pack === 'dockerimage') {
$application->health_check_enabled = false; $application->health_check_enabled = false;
} }
if ($this->build_pack === 'dockercompose') {
$application['docker_compose_location'] = $this->docker_compose_location;
$application['base_directory'] = $this->base_directory;
}
$fqdn = generateFqdn($destination->server, $application->uuid); $fqdn = generateFqdn($destination->server, $application->uuid);
$application->fqdn = $fqdn; $application->fqdn = $fqdn;

View File

@ -33,6 +33,12 @@ class GithubPrivateRepositoryDeployKey extends Component
public ?string $publish_directory = null; public ?string $publish_directory = null;
// In case of docker compose
public ?string $base_directory = null;
public ?string $docker_compose_location = '/docker-compose.yaml';
// End of docker compose
public string $repository_url; public string $repository_url;
public string $branch; public string $branch;
@ -163,6 +169,10 @@ public function submit()
if ($this->build_pack === 'dockerfile' || $this->build_pack === 'dockerimage') { if ($this->build_pack === 'dockerfile' || $this->build_pack === 'dockerimage') {
$application_init['health_check_enabled'] = false; $application_init['health_check_enabled'] = false;
} }
if ($this->build_pack === 'dockercompose') {
$application_init['docker_compose_location'] = $this->docker_compose_location;
$application_init['base_directory'] = $this->base_directory;
}
$application = Application::create($application_init); $application = Application::create($application_init);
$application->settings->is_static = $this->is_static; $application->settings->is_static = $this->is_static;
$application->settings->save(); $application->settings->save();

View File

@ -33,6 +33,12 @@ class PublicGitRepository extends Component
public ?string $publish_directory = null; public ?string $publish_directory = null;
// In case of docker compose
public ?string $base_directory = null;
public ?string $docker_compose_location = '/docker-compose.yaml';
// End of docker compose
public string $git_branch = 'main'; public string $git_branch = 'main';
public int $rate_limit_remaining = 0; public int $rate_limit_remaining = 0;
@ -59,6 +65,8 @@ class PublicGitRepository extends Component
'is_static' => 'required|boolean', 'is_static' => 'required|boolean',
'publish_directory' => 'nullable|string', 'publish_directory' => 'nullable|string',
'build_pack' => 'required|string', 'build_pack' => 'required|string',
'base_directory' => 'nullable|string',
'docker_compose_location' => 'nullable|string',
]; ];
protected $validationAttributes = [ protected $validationAttributes = [
@ -67,6 +75,8 @@ class PublicGitRepository extends Component
'is_static' => 'static', 'is_static' => 'static',
'publish_directory' => 'publish directory', 'publish_directory' => 'publish directory',
'build_pack' => 'build pack', 'build_pack' => 'build pack',
'base_directory' => 'base directory',
'docker_compose_location' => 'docker compose location',
]; ];
public function mount() public function mount()
@ -79,6 +89,16 @@ public function mount()
$this->query = request()->query(); $this->query = request()->query();
} }
public function updatedBaseDirectory()
{
if ($this->base_directory) {
$this->base_directory = rtrim($this->base_directory, '/');
if (! str($this->base_directory)->startsWith('/')) {
$this->base_directory = '/'.$this->base_directory;
}
}
}
public function updatedBuildPack() public function updatedBuildPack()
{ {
if ($this->build_pack === 'nixpacks') { if ($this->build_pack === 'nixpacks') {
@ -261,6 +281,10 @@ public function submit()
if ($this->build_pack === 'dockerfile' || $this->build_pack === 'dockerimage') { if ($this->build_pack === 'dockerfile' || $this->build_pack === 'dockerimage') {
$application_init['health_check_enabled'] = false; $application_init['health_check_enabled'] = false;
} }
if ($this->build_pack === 'dockercompose') {
$application_init['docker_compose_location'] = $this->docker_compose_location;
$application_init['base_directory'] = $this->base_directory;
}
$application = Application::create($application_init); $application = Application::create($application_init);
$application->settings->is_static = $this->is_static; $application->settings->is_static = $this->is_static;

View File

@ -62,6 +62,15 @@ class="loading loading-xs dark:text-warning loading-spinner"></span>
<x-forms.input id="publish_directory" required label="Publish Directory" /> <x-forms.input id="publish_directory" required label="Publish Directory" />
@endif @endif
</div> </div>
@if ($build_pack === 'dockercompose')
<x-forms.input placeholder="/" wire:model.blur="base_directory" label="Base Directory"
helper="Directory to use as root. Useful for monorepos." />
<x-forms.input placeholder="/docker-compose.yaml" id="docker_compose_location"
label="Docker Compose Location"
helper="It is calculated together with the Base Directory:<br><span class='dark:text-warning'>{{ Str::start($base_directory . $docker_compose_location, '/') }}</span>" />
Compose file location in your repository:<span
class='dark:text-warning'>{{ Str::start($base_directory . $docker_compose_location, '/') }}</span>
@endif
@if ($show_is_static) @if ($show_is_static)
<x-forms.input type="number" required id="port" label="Port" :readonly="$is_static || $build_pack === 'static'" /> <x-forms.input type="number" required id="port" label="Port" :readonly="$is_static || $build_pack === 'static'" />
<div class="w-52"> <div class="w-52">

View File

@ -14,7 +14,6 @@
@endif @endif
</div> </div>
<div class="pb-4">Deploy any public or private Git repositories through a GitHub App.</div> <div class="pb-4">Deploy any public or private Git repositories through a GitHub App.</div>
@if ($github_apps->count() !== 0) @if ($github_apps->count() !== 0)
<h2 class="pt-4 pb-4">Select a Github App</h2> <h2 class="pt-4 pb-4">Select a Github App</h2>
<div class="flex flex-col gap-2"> <div class="flex flex-col gap-2">
@ -92,6 +91,16 @@
helper="If there is a build process involved (like Svelte, React, Next, etc..), please specify the output directory for the build assets." /> helper="If there is a build process involved (like Svelte, React, Next, etc..), please specify the output directory for the build assets." />
@endif @endif
</div> </div>
@if ($build_pack === 'dockercompose')
<x-forms.input placeholder="/" wire:model.blur="base_directory"
label="Base Directory"
helper="Directory to use as root. Useful for monorepos." />
<x-forms.input placeholder="/docker-compose.yaml" id="docker_compose_location"
label="Docker Compose Location"
helper="It is calculated together with the Base Directory:<br><span class='dark:text-warning'>{{ Str::start($base_directory . $docker_compose_location, '/') }}</span>" />
Compose file location in your repository:<span
class='dark:text-warning'>{{ Str::start($base_directory . $docker_compose_location, '/') }}</span>
@endif
@if ($show_is_static) @if ($show_is_static)
<x-forms.input type="number" id="port" label="Port" :readonly="$is_static || $build_pack === 'static'" <x-forms.input type="number" id="port" label="Port" :readonly="$is_static || $build_pack === 'static'"
helper="The port your application listens on." /> helper="The port your application listens on." />

View File

@ -13,10 +13,6 @@
</div> </div>
@if (!$branch_found) @if (!$branch_found)
<div class="px-2 pt-4"> <div class="px-2 pt-4">
<div class="flex flex-col pb-4">
<div>Preselect branch (eg: main):</div>
<div class='text-helper'>https://github.com/coollabsio/coolify-examples/tree/main</div>
</div>
<div> <div>
For example application deployments, checkout <a class="underline dark:text-white" For example application deployments, checkout <a class="underline dark:text-white"
href="https://github.com/coollabsio/coolify-examples/" target="_blank">Coolify href="https://github.com/coollabsio/coolify-examples/" target="_blank">Coolify
@ -51,6 +47,15 @@
helper="If there is a build process involved (like Svelte, React, Next, etc..), please specify the output directory for the build assets." /> helper="If there is a build process involved (like Svelte, React, Next, etc..), please specify the output directory for the build assets." />
@endif @endif
</div> </div>
@if ($build_pack === 'dockercompose')
<x-forms.input placeholder="/" wire:model.blur="base_directory" label="Base Directory"
helper="Directory to use as root. Useful for monorepos." />
<x-forms.input placeholder="/docker-compose.yaml" id="docker_compose_location"
label="Docker Compose Location"
helper="It is calculated together with the Base Directory:<br><span class='dark:text-warning'>{{ Str::start($base_directory . $docker_compose_location, '/') }}</span>" />
Compose file location in your repository:<span
class='dark:text-warning'>{{ Str::start($base_directory . $docker_compose_location, '/') }}</span>
@endif
@if ($show_is_static) @if ($show_is_static)
<x-forms.input type="number" id="port" label="Port" :readonly="$is_static || $build_pack === 'static'" <x-forms.input type="number" id="port" label="Port" :readonly="$is_static || $build_pack === 'static'"
helper="The port your application listens on." /> helper="The port your application listens on." />
@ -59,10 +64,12 @@
helper="If your application is a static site or the final build assets should be served as a static site, enable this." /> helper="If your application is a static site or the final build assets should be served as a static site, enable this." />
</div> </div>
@endif @endif
@if ($build_pack === 'dockercompose' && isDev()) {{-- @if ($build_pack === 'dockercompose' && isDev())
<div class="dark:text-warning">If you choose Docker Compose based deployments, you cannot change it afterwards.</div> <div class="dark:text-warning">If you choose Docker Compose based deployments, you cannot
<x-forms.checkbox instantSave label="New Compose Services (only in dev mode)" id="new_compose_services"></x-forms.checkbox> change it afterwards.</div>
@endif <x-forms.checkbox instantSave label="New Compose Services (only in dev mode)"
id="new_compose_services"></x-forms.checkbox>
@endif --}}
</div> </div>
<x-forms.button wire:click.prevent='submit'> <x-forms.button wire:click.prevent='submit'>
Continue Continue