2023-08-11 20:41:47 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace App\Http\Livewire\Project\New;
|
|
|
|
|
|
|
|
use App\Models\Application;
|
|
|
|
use App\Models\GithubApp;
|
|
|
|
use App\Models\Project;
|
|
|
|
use App\Models\StandaloneDocker;
|
|
|
|
use App\Models\SwarmDocker;
|
|
|
|
use Livewire\Component;
|
|
|
|
use Visus\Cuid2\Cuid2;
|
|
|
|
|
|
|
|
class SimpleDockerfile extends Component
|
|
|
|
{
|
|
|
|
public string $dockerfile = '';
|
|
|
|
public array $parameters;
|
|
|
|
public array $query;
|
|
|
|
public function mount()
|
|
|
|
{
|
|
|
|
$this->parameters = get_route_parameters();
|
|
|
|
$this->query = request()->query();
|
2023-08-27 13:23:47 +00:00
|
|
|
if (isDev()) {
|
2023-08-11 20:41:47 +00:00
|
|
|
$this->dockerfile = 'FROM nginx
|
|
|
|
EXPOSE 80
|
|
|
|
CMD ["nginx", "-g", "daemon off;"]
|
|
|
|
';
|
|
|
|
}
|
|
|
|
}
|
|
|
|
public function submit()
|
|
|
|
{
|
|
|
|
$this->validate([
|
|
|
|
'dockerfile' => 'required'
|
|
|
|
]);
|
|
|
|
$destination_uuid = $this->query['destination'];
|
|
|
|
$destination = StandaloneDocker::where('uuid', $destination_uuid)->first();
|
|
|
|
if (!$destination) {
|
|
|
|
$destination = SwarmDocker::where('uuid', $destination_uuid)->first();
|
|
|
|
}
|
|
|
|
if (!$destination) {
|
|
|
|
throw new \Exception('Destination not found. What?!');
|
|
|
|
}
|
|
|
|
$destination_class = $destination->getMorphClass();
|
|
|
|
|
|
|
|
$project = Project::where('uuid', $this->parameters['project_uuid'])->first();
|
|
|
|
$environment = $project->load(['environments'])->environments->where('name', $this->parameters['environment_name'])->first();
|
|
|
|
|
|
|
|
$port = get_port_from_dockerfile($this->dockerfile);
|
|
|
|
$application = Application::create([
|
|
|
|
'name' => 'dockerfile-' . new Cuid2(7),
|
|
|
|
'repository_project_id' => 0,
|
|
|
|
'git_repository' => "coollabsio/coolify",
|
|
|
|
'git_branch' => 'main',
|
|
|
|
'build_pack' => 'dockerfile',
|
|
|
|
'dockerfile' => $this->dockerfile,
|
|
|
|
'ports_exposes' => $port,
|
|
|
|
'environment_id' => $environment->id,
|
|
|
|
'destination_id' => $destination->id,
|
|
|
|
'destination_type' => $destination_class,
|
|
|
|
'source_id' => 0,
|
|
|
|
'source_type' => GithubApp::class
|
|
|
|
]);
|
2023-09-19 13:51:13 +00:00
|
|
|
|
|
|
|
$fqdn = "http://{$application->uuid}.{$destination->server->ip}.sslip.io";
|
|
|
|
if (isDev()) {
|
|
|
|
$fqdn = "http://{$application->uuid}.127.0.0.1.sslip.io";
|
|
|
|
}
|
2023-08-21 16:00:12 +00:00
|
|
|
$application->update([
|
2023-09-19 13:51:13 +00:00
|
|
|
'name' => 'dockerfile-' . $application->uuid,
|
|
|
|
'fqdn' => $fqdn
|
2023-08-21 16:00:12 +00:00
|
|
|
]);
|
|
|
|
|
2023-08-11 20:41:47 +00:00
|
|
|
redirect()->route('project.application.configuration', [
|
|
|
|
'application_uuid' => $application->uuid,
|
|
|
|
'environment_name' => $environment->name,
|
|
|
|
'project_uuid' => $project->uuid,
|
|
|
|
]);
|
|
|
|
}
|
|
|
|
}
|