2023-08-29 14:31:46 +00:00
< ? php
2023-12-07 18:06:32 +00:00
namespace App\Livewire\Boarding ;
2023-08-29 18:34:01 +00:00
2024-02-12 10:46:36 +00:00
use App\Enums\ProxyTypes ;
2023-08-29 14:31:46 +00:00
use App\Models\PrivateKey ;
use App\Models\Project ;
use App\Models\Server ;
2023-09-08 16:33:26 +00:00
use App\Models\Team ;
2025-03-24 20:01:27 +00:00
use App\Services\ConfigurationRepository ;
2023-08-30 09:06:44 +00:00
use Illuminate\Support\Collection ;
2023-08-29 14:31:46 +00:00
use Livewire\Component ;
2024-11-22 14:51:25 +00:00
use Visus\Cuid2\Cuid2 ;
2023-08-29 14:31:46 +00:00
class Index extends Component
2023-08-29 18:34:01 +00:00
{
2025-11-24 07:44:04 +00:00
protected $listeners = [
'refreshBoardingIndex' => 'validateServer' ,
'prerequisitesInstalled' => 'handlePrerequisitesInstalled' ,
];
2023-08-29 14:31:46 +00:00
2025-10-12 15:59:37 +00:00
#[\Livewire\Attributes\Url(as: 'step', history: true)]
2024-03-25 13:44:31 +00:00
public string $currentState = 'welcome' ;
2024-03-20 14:46:59 +00:00
2025-10-12 15:59:37 +00:00
#[\Livewire\Attributes\Url(keep: true)]
2023-09-18 08:41:06 +00:00
public ? string $selectedServerType = null ;
2024-06-10 20:43:34 +00:00
2023-08-29 18:34:01 +00:00
public ? Collection $privateKeys = null ;
2024-03-20 14:46:59 +00:00
2025-10-12 15:59:37 +00:00
#[\Livewire\Attributes\Url(keep: true)]
2023-08-29 18:34:01 +00:00
public ? int $selectedExistingPrivateKey = null ;
2024-06-10 20:43:34 +00:00
2025-10-12 15:59:37 +00:00
#[\Livewire\Attributes\Url(keep: true)]
2023-08-29 14:31:46 +00:00
public ? string $privateKeyType = null ;
2024-06-10 20:43:34 +00:00
2023-08-29 14:31:46 +00:00
public ? string $privateKey = null ;
2024-06-10 20:43:34 +00:00
2023-08-29 14:31:46 +00:00
public ? string $publicKey = null ;
2024-06-10 20:43:34 +00:00
2023-08-29 14:31:46 +00:00
public ? string $privateKeyName = null ;
2024-06-10 20:43:34 +00:00
2023-08-29 14:31:46 +00:00
public ? string $privateKeyDescription = null ;
2024-06-10 20:43:34 +00:00
2023-08-29 14:31:46 +00:00
public ? PrivateKey $createdPrivateKey = null ;
2023-08-30 09:06:44 +00:00
public ? Collection $servers = null ;
2024-03-20 14:46:59 +00:00
2025-10-12 15:59:37 +00:00
#[\Livewire\Attributes\Url(keep: true)]
2023-08-30 09:06:44 +00:00
public ? int $selectedExistingServer = null ;
2024-06-10 20:43:34 +00:00
2023-08-29 14:31:46 +00:00
public ? string $remoteServerName = null ;
2024-06-10 20:43:34 +00:00
2023-08-29 14:31:46 +00:00
public ? string $remoteServerDescription = null ;
2024-06-10 20:43:34 +00:00
2023-08-29 14:31:46 +00:00
public ? string $remoteServerHost = null ;
2024-06-10 20:43:34 +00:00
public ? int $remoteServerPort = 22 ;
2023-08-29 14:31:46 +00:00
public ? string $remoteServerUser = 'root' ;
2024-06-10 20:43:34 +00:00
2023-11-29 09:06:52 +00:00
public bool $isSwarmManager = false ;
2024-06-10 20:43:34 +00:00
2023-12-04 08:29:55 +00:00
public bool $isCloudflareTunnel = false ;
2024-06-10 20:43:34 +00:00
2023-08-29 14:31:46 +00:00
public ? Server $createdServer = null ;
2023-11-15 08:34:27 +00:00
public Collection $projects ;
2024-03-20 14:46:59 +00:00
2025-10-12 15:59:37 +00:00
#[\Livewire\Attributes\Url(keep: true)]
2024-03-20 14:46:59 +00:00
public ? int $selectedProject = null ;
2024-06-10 20:43:34 +00:00
2023-08-29 14:31:46 +00:00
public ? Project $createdProject = null ;
2023-09-18 09:21:10 +00:00
public bool $dockerInstallationStarted = false ;
2023-09-18 11:01:01 +00:00
2023-09-18 12:41:31 +00:00
public string $serverPublicKey ;
2024-06-10 20:43:34 +00:00
2023-09-18 12:41:31 +00:00
public bool $serverReachable = true ;
2023-09-18 11:01:01 +00:00
2024-11-10 21:28:12 +00:00
public ? string $minDockerVersion = null ;
2025-11-24 07:44:04 +00:00
public int $prerequisiteInstallAttempts = 0 ;
public int $maxPrerequisiteInstallAttempts = 3 ;
2023-08-29 14:31:46 +00:00
public function mount ()
{
2024-05-21 12:29:06 +00:00
if ( auth () -> user () ? -> isMember () && auth () -> user () -> currentTeam () -> show_boarding === true ) {
return redirect () -> route ( 'dashboard' );
}
2024-11-10 21:28:12 +00:00
2024-11-12 12:27:26 +00:00
$this -> minDockerVersion = str ( config ( 'constants.docker.minimum_required_version' )) -> before ( '.' );
2023-08-29 14:31:46 +00:00
$this -> privateKeyName = generate_random_name ();
$this -> remoteServerName = generate_random_name ();
2025-10-12 15:59:37 +00:00
// Initialize collections to avoid null errors
if ( $this -> privateKeys === null ) {
$this -> privateKeys = collect ();
}
if ( $this -> servers === null ) {
$this -> servers = collect ();
}
if ( ! isset ( $this -> projects )) {
$this -> projects = collect ();
}
// Restore state when coming from URL with query params
if ( $this -> selectedServerType === 'localhost' && $this -> selectedExistingServer === 0 ) {
$this -> createdServer = Server :: find ( 0 );
if ( $this -> createdServer ) {
$this -> serverPublicKey = $this -> createdServer -> privateKey -> getPublicKey ();
}
}
if ( $this -> selectedServerType === 'remote' ) {
if ( $this -> privateKeys -> isEmpty ()) {
2025-10-23 14:18:20 +00:00
$this -> privateKeys = PrivateKey :: ownedAndOnlySShKeys ([ 'name' ]) -> where ( 'id' , '!=' , 0 ) -> get ();
2025-10-12 15:59:37 +00:00
}
if ( $this -> servers -> isEmpty ()) {
$this -> servers = Server :: ownedByCurrentTeam ([ 'name' ]) -> where ( 'id' , '!=' , 0 ) -> get ();
}
if ( $this -> selectedExistingServer ) {
$this -> createdServer = Server :: find ( $this -> selectedExistingServer );
if ( $this -> createdServer ) {
$this -> serverPublicKey = $this -> createdServer -> privateKey -> getPublicKey ();
$this -> updateServerDetails ();
}
}
if ( $this -> selectedExistingPrivateKey ) {
$this -> createdPrivateKey = PrivateKey :: where ( 'team_id' , currentTeam () -> id )
-> where ( 'id' , $this -> selectedExistingPrivateKey )
-> first ();
if ( $this -> createdPrivateKey ) {
$this -> privateKey = $this -> createdPrivateKey -> private_key ;
$this -> publicKey = $this -> createdPrivateKey -> getPublicKey ();
}
}
// Auto-regenerate key pair for "Generate with Coolify" mode on page refresh
if ( $this -> privateKeyType === 'create' && empty ( $this -> privateKey )) {
$this -> createNewPrivateKey ();
}
}
if ( $this -> selectedProject ) {
$this -> createdProject = Project :: find ( $this -> selectedProject );
if ( ! $this -> createdProject ) {
$this -> projects = Project :: ownedByCurrentTeam ([ 'name' ]) -> get ();
}
2023-08-29 14:31:46 +00:00
}
2025-10-12 16:52:45 +00:00
// Load projects when on create-project state (for page refresh)
if ( $this -> currentState === 'create-project' && $this -> projects -> isEmpty ()) {
$this -> projects = Project :: ownedByCurrentTeam ([ 'name' ]) -> get ();
}
2023-08-29 14:31:46 +00:00
}
2024-06-10 20:43:34 +00:00
2023-09-15 13:34:25 +00:00
public function explanation ()
{
2023-08-31 07:56:37 +00:00
if ( isCloud ()) {
2023-08-30 16:35:20 +00:00
return $this -> setServerType ( 'remote' );
}
2024-03-25 13:44:31 +00:00
$this -> currentState = 'select-server-type' ;
2023-08-30 16:35:20 +00:00
}
2023-09-14 08:39:05 +00:00
2023-08-29 14:31:46 +00:00
public function restartBoarding ()
{
2024-03-13 11:11:37 +00:00
return redirect () -> route ( 'onboarding' );
2023-08-29 14:31:46 +00:00
}
2024-06-10 20:43:34 +00:00
2023-08-29 14:31:46 +00:00
public function skipBoarding ()
{
2025-01-07 14:31:43 +00:00
Team :: find ( currentTeam () -> id ) -> update ([
2024-06-10 20:43:34 +00:00
'show_boarding' => false ,
2023-08-29 14:31:46 +00:00
]);
refreshSession ();
2024-06-10 20:43:34 +00:00
2023-08-29 14:31:46 +00:00
return redirect () -> route ( 'dashboard' );
}
2023-08-30 09:06:44 +00:00
public function setServerType ( string $type )
2023-08-29 14:31:46 +00:00
{
2023-09-18 08:41:06 +00:00
$this -> selectedServerType = $type ;
if ( $this -> selectedServerType === 'localhost' ) {
2025-01-07 14:31:43 +00:00
$this -> createdServer = Server :: find ( 0 );
2024-03-20 14:46:59 +00:00
$this -> selectedExistingServer = 0 ;
2024-06-10 20:43:34 +00:00
if ( ! $this -> createdServer ) {
2023-12-07 18:06:32 +00:00
return $this -> dispatch ( 'error' , 'Localhost server is not found. Something went wrong during installation. Please try to reinstall or contact support.' );
2023-08-29 14:31:46 +00:00
}
2024-09-16 17:52:55 +00:00
$this -> serverPublicKey = $this -> createdServer -> privateKey -> getPublicKey ();
2024-06-10 20:43:34 +00:00
2025-01-07 14:31:43 +00:00
return $this -> validateServer ( 'localhost' );
} elseif ( $this -> selectedServerType === 'remote' ) {
2025-10-23 14:18:20 +00:00
$this -> privateKeys = PrivateKey :: ownedAndOnlySShKeys ([ 'name' ]) -> where ( 'id' , '!=' , 0 ) -> get ();
2025-10-12 16:54:12 +00:00
// Auto-select first key if available for better UX
if ( $this -> privateKeys -> count () > 0 ) {
$this -> selectedExistingPrivateKey = $this -> privateKeys -> first () -> id ;
}
2025-10-12 16:52:45 +00:00
// Onboarding always creates new servers, skip existing server selection
2024-03-25 13:44:31 +00:00
$this -> currentState = 'private-key' ;
2023-08-30 09:06:44 +00:00
}
}
2024-06-10 20:43:34 +00:00
2024-09-10 15:18:00 +00:00
private function updateServerDetails ()
{
2025-01-07 14:31:43 +00:00
if ( $this -> createdServer ) {
2024-09-10 15:18:00 +00:00
$this -> remoteServerPort = $this -> createdServer -> port ;
$this -> remoteServerUser = $this -> createdServer -> user ;
}
}
2023-09-15 13:34:25 +00:00
public function getProxyType ()
{
2024-08-07 15:52:51 +00:00
$this -> selectProxy ( ProxyTypes :: TRAEFIK -> value );
2023-08-30 09:06:44 +00:00
$this -> getProjects ();
}
2024-06-10 20:43:34 +00:00
2023-08-29 18:34:01 +00:00
public function selectExistingPrivateKey ()
{
2024-03-25 09:41:44 +00:00
if ( is_null ( $this -> selectedExistingPrivateKey )) {
2025-10-12 16:52:45 +00:00
$this -> dispatch ( 'error' , 'Please select a private key.' );
2024-06-10 20:43:34 +00:00
2024-03-25 09:41:44 +00:00
return ;
}
2025-01-07 14:31:43 +00:00
$this -> createdPrivateKey = PrivateKey :: where ( 'team_id' , currentTeam () -> id ) -> where ( 'id' , $this -> selectedExistingPrivateKey ) -> first ();
2023-09-28 11:46:53 +00:00
$this -> privateKey = $this -> createdPrivateKey -> private_key ;
2024-03-25 13:44:31 +00:00
$this -> currentState = 'create-server' ;
2023-08-30 09:06:44 +00:00
}
2024-06-10 20:43:34 +00:00
2023-08-30 09:06:44 +00:00
public function createNewServer ()
{
$this -> selectedExistingServer = null ;
2024-03-25 13:44:31 +00:00
$this -> currentState = 'private-key' ;
2023-08-29 18:34:01 +00:00
}
2024-06-10 20:43:34 +00:00
2023-08-29 14:31:46 +00:00
public function setPrivateKey ( string $type )
{
2023-08-30 09:06:44 +00:00
$this -> selectedExistingPrivateKey = null ;
2023-08-29 14:31:46 +00:00
$this -> privateKeyType = $type ;
2023-09-11 08:15:45 +00:00
if ( $type === 'create' ) {
2023-08-29 14:31:46 +00:00
$this -> createNewPrivateKey ();
2025-10-12 15:59:37 +00:00
} else {
$this -> privateKey = null ;
$this -> publicKey = null ;
2023-08-29 14:31:46 +00:00
}
2024-03-25 13:44:31 +00:00
$this -> currentState = 'create-private-key' ;
2023-08-29 14:31:46 +00:00
}
2024-06-10 20:43:34 +00:00
2023-08-29 14:31:46 +00:00
public function savePrivateKey ()
{
$this -> validate ([
2024-09-16 19:34:27 +00:00
'privateKeyName' => 'required|string|max:255' ,
'privateKeyDescription' => 'nullable|string|max:255' ,
'privateKey' => 'required|string' ,
2023-08-29 14:31:46 +00:00
]);
2024-09-16 19:34:27 +00:00
try {
$privateKey = PrivateKey :: createAndStore ([
'name' => $this -> privateKeyName ,
'description' => $this -> privateKeyDescription ,
'private_key' => $this -> privateKey ,
'team_id' => currentTeam () -> id ,
]);
$this -> createdPrivateKey = $privateKey ;
$this -> currentState = 'create-server' ;
2025-01-07 14:31:43 +00:00
} catch ( \Exception $e ) {
2024-09-23 17:51:31 +00:00
$this -> addError ( 'privateKey' , 'Failed to save private key: ' . $e -> getMessage ());
2024-09-16 19:34:27 +00:00
}
2023-08-29 14:31:46 +00:00
}
2024-06-10 20:43:34 +00:00
2023-08-29 14:31:46 +00:00
public function saveServer ()
{
$this -> validate ([
2024-09-10 15:29:53 +00:00
'remoteServerName' => 'required|string' ,
'remoteServerHost' => 'required|string' ,
2023-09-15 13:34:25 +00:00
'remoteServerPort' => 'required|integer' ,
2024-09-10 15:29:53 +00:00
'remoteServerUser' => 'required|string' ,
2023-08-29 14:31:46 +00:00
]);
2024-09-10 15:29:53 +00:00
2023-08-29 14:31:46 +00:00
$this -> privateKey = formatPrivateKey ( $this -> privateKey );
2023-09-15 13:34:25 +00:00
$foundServer = Server :: whereIp ( $this -> remoteServerHost ) -> first ();
if ( $foundServer ) {
2026-02-12 07:10:59 +00:00
if ( $foundServer -> team_id === currentTeam () -> id ) {
return $this -> dispatch ( 'error' , 'A server with this IP/Domain already exists in your team.' );
}
return $this -> dispatch ( 'error' , 'A server with this IP/Domain is already in use by another team.' );
2023-09-15 13:34:25 +00:00
}
2025-01-07 14:31:43 +00:00
$this -> createdServer = Server :: create ([
2023-09-18 09:21:10 +00:00
'name' => $this -> remoteServerName ,
'ip' => $this -> remoteServerHost ,
'port' => $this -> remoteServerPort ,
'user' => $this -> remoteServerUser ,
'description' => $this -> remoteServerDescription ,
'private_key_id' => $this -> createdPrivateKey -> id ,
'team_id' => currentTeam () -> id ,
]);
2023-11-29 09:06:52 +00:00
$this -> createdServer -> settings -> is_swarm_manager = $this -> isSwarmManager ;
2023-12-04 08:29:55 +00:00
$this -> createdServer -> settings -> is_cloudflare_tunnel = $this -> isCloudflareTunnel ;
2023-11-28 14:49:24 +00:00
$this -> createdServer -> settings -> save ();
2024-03-20 14:46:59 +00:00
$this -> selectedExistingServer = $this -> createdServer -> id ;
2024-03-25 13:44:31 +00:00
$this -> currentState = 'validate-server' ;
2023-08-30 09:06:44 +00:00
}
2024-06-10 20:43:34 +00:00
2024-02-05 13:40:54 +00:00
public function installServer ()
{
2024-03-05 15:23:46 +00:00
$this -> dispatch ( 'init' , true );
2024-02-05 13:40:54 +00:00
}
2024-06-10 20:43:34 +00:00
2023-09-18 11:01:01 +00:00
public function validateServer ()
2023-09-15 13:34:25 +00:00
{
2023-08-29 14:31:46 +00:00
try {
2025-03-24 20:01:27 +00:00
$this -> disableSshMux ();
2023-09-18 09:21:10 +00:00
2024-02-15 12:44:40 +00:00
// EC2 does not have `uptime` command, lol
2024-02-15 12:52:42 +00:00
instant_remote_process ([ 'ls /' ], $this -> createdServer , true );
2023-09-18 09:21:10 +00:00
2023-09-18 12:41:31 +00:00
$this -> createdServer -> settings () -> update ([
2023-09-18 09:21:10 +00:00
'is_reachable' => true ,
]);
2024-09-10 14:55:34 +00:00
$this -> serverReachable = true ;
2025-01-07 14:31:43 +00:00
} catch ( \Throwable $e ) {
2023-09-18 12:41:31 +00:00
$this -> serverReachable = false ;
2024-09-10 14:55:34 +00:00
$this -> createdServer -> settings () -> update ([
'is_reachable' => false ,
]);
2024-06-10 20:43:34 +00:00
2023-11-21 11:07:06 +00:00
return handleError ( error : $e , livewire : $this );
2023-09-18 11:01:01 +00:00
}
2023-09-18 09:21:10 +00:00
2025-11-21 08:49:33 +00:00
try {
// Check prerequisites
2025-11-21 12:14:48 +00:00
$validationResult = $this -> createdServer -> validatePrerequisites ();
if ( ! $validationResult [ 'success' ]) {
2025-11-24 07:44:04 +00:00
// Check if we've exceeded max attempts
if ( $this -> prerequisiteInstallAttempts >= $this -> maxPrerequisiteInstallAttempts ) {
2025-11-21 12:14:48 +00:00
$missingCommands = implode ( ', ' , $validationResult [ 'missing' ]);
2025-11-24 07:44:04 +00:00
throw new \Exception ( " Prerequisites ( { $missingCommands } ) could not be installed after { $this -> maxPrerequisiteInstallAttempts } attempts. Please install them manually. " );
}
// Start async installation and wait for completion via ActivityMonitor
$activity = $this -> createdServer -> installPrerequisites ();
$this -> prerequisiteInstallAttempts ++ ;
$this -> dispatch ( 'activityMonitor' , $activity -> id , 'prerequisitesInstalled' );
// Return early - handlePrerequisitesInstalled() will be called when installation completes
return ;
}
// Prerequisites are already installed, continue with validation
$this -> continueValidation ();
} catch ( \Throwable $e ) {
return handleError ( error : $e , livewire : $this );
}
}
public function handlePrerequisitesInstalled ()
{
try {
// Revalidate prerequisites after installation completes
$validationResult = $this -> createdServer -> validatePrerequisites ();
if ( ! $validationResult [ 'success' ]) {
// Installation completed but prerequisites still missing - retry
$missingCommands = implode ( ', ' , $validationResult [ 'missing' ]);
if ( $this -> prerequisiteInstallAttempts >= $this -> maxPrerequisiteInstallAttempts ) {
throw new \Exception ( " Prerequisites ( { $missingCommands } ) could not be installed after { $this -> maxPrerequisiteInstallAttempts } attempts. Please install them manually. " );
2025-11-21 08:49:33 +00:00
}
2025-11-24 07:44:04 +00:00
// Try again
$activity = $this -> createdServer -> installPrerequisites ();
$this -> prerequisiteInstallAttempts ++ ;
$this -> dispatch ( 'activityMonitor' , $activity -> id , 'prerequisitesInstalled' );
return ;
2025-11-21 08:49:33 +00:00
}
2025-11-24 07:44:04 +00:00
// Prerequisites validated successfully - continue with Docker validation
$this -> continueValidation ();
2025-11-21 08:49:33 +00:00
} catch ( \Throwable $e ) {
return handleError ( error : $e , livewire : $this );
}
2025-11-24 07:44:04 +00:00
}
2025-11-21 08:49:33 +00:00
2025-11-24 07:44:04 +00:00
private function continueValidation ()
{
2023-09-18 11:01:01 +00:00
try {
2023-09-15 13:34:25 +00:00
$dockerVersion = instant_remote_process ([ " docker version|head -2|grep -i version| awk ' { print $ 2}' " ], $this -> createdServer , true );
$dockerVersion = checkMinimumDockerEngineVersion ( $dockerVersion );
if ( is_null ( $dockerVersion )) {
2024-03-25 13:44:31 +00:00
$this -> currentState = 'validate-server' ;
2025-01-07 14:31:43 +00:00
throw new \Exception ( 'Docker not found or old version is installed.' );
2023-09-16 14:49:33 +00:00
}
2023-09-18 12:41:31 +00:00
$this -> createdServer -> settings () -> update ([
'is_usable' => true ,
]);
$this -> getProxyType ();
2025-01-07 14:31:43 +00:00
} catch ( \Throwable $e ) {
2024-09-10 14:55:34 +00:00
$this -> createdServer -> settings () -> update ([
'is_usable' => false ,
]);
2024-09-11 08:21:18 +00:00
2023-11-21 11:07:06 +00:00
return handleError ( error : $e , livewire : $this );
}
2023-09-18 09:21:10 +00:00
}
2024-06-10 20:43:34 +00:00
2024-02-12 10:46:36 +00:00
public function selectProxy ( ? string $proxyType = null )
2023-08-29 14:31:46 +00:00
{
2024-06-10 20:43:34 +00:00
if ( ! $proxyType ) {
2023-08-30 09:06:44 +00:00
return $this -> getProjects ();
2023-08-29 14:31:46 +00:00
}
$this -> createdServer -> proxy -> type = $proxyType ;
$this -> createdServer -> proxy -> status = 'exited' ;
2025-11-13 12:38:57 +00:00
$this -> createdServer -> proxy -> last_saved_settings = null ;
$this -> createdServer -> proxy -> last_applied_settings = null ;
2023-08-29 14:31:46 +00:00
$this -> createdServer -> save ();
2023-08-30 09:06:44 +00:00
$this -> getProjects ();
}
2023-09-15 13:34:25 +00:00
public function getProjects ()
{
2025-01-07 14:31:43 +00:00
$this -> projects = Project :: ownedByCurrentTeam ([ 'name' ]) -> get ();
2023-08-30 09:06:44 +00:00
if ( $this -> projects -> count () > 0 ) {
2024-03-20 14:46:59 +00:00
$this -> selectedProject = $this -> projects -> first () -> id ;
2023-08-30 09:06:44 +00:00
}
2024-03-25 13:44:31 +00:00
$this -> currentState = 'create-project' ;
2023-08-29 14:31:46 +00:00
}
2024-06-10 20:43:34 +00:00
2023-09-15 13:34:25 +00:00
public function selectExistingProject ()
{
2025-01-07 14:31:43 +00:00
$this -> createdProject = Project :: find ( $this -> selectedProject );
2024-03-25 13:44:31 +00:00
$this -> currentState = 'create-resource' ;
2023-08-30 09:06:44 +00:00
}
2024-06-10 20:43:34 +00:00
2023-08-29 14:31:46 +00:00
public function createNewProject ()
{
2025-01-07 14:31:43 +00:00
$this -> createdProject = Project :: create ([
2024-06-10 20:43:34 +00:00
'name' => 'My first project' ,
'team_id' => currentTeam () -> id ,
2024-11-22 14:51:25 +00:00
'uuid' => ( string ) new Cuid2 ,
2023-08-29 14:31:46 +00:00
]);
2024-03-25 13:44:31 +00:00
$this -> currentState = 'create-resource' ;
2023-08-29 14:31:46 +00:00
}
2024-06-10 20:43:34 +00:00
2023-08-29 14:31:46 +00:00
public function showNewResource ()
{
$this -> skipBoarding ();
2024-06-10 20:43:34 +00:00
2023-08-29 14:31:46 +00:00
return redirect () -> route (
2024-01-07 15:23:41 +00:00
'project.resource.create' ,
2023-08-29 14:31:46 +00:00
[
'project_uuid' => $this -> createdProject -> uuid ,
2024-11-22 14:51:25 +00:00
'environment_uuid' => $this -> createdProject -> environments -> first () -> uuid ,
2023-09-15 13:34:25 +00:00
'server' => $this -> createdServer -> id ,
2023-08-29 14:31:46 +00:00
]
);
}
2024-06-10 20:43:34 +00:00
2024-09-10 14:55:34 +00:00
public function saveAndValidateServer ()
{
$this -> validate ([
'remoteServerPort' => 'required|integer|min:1|max:65535' ,
'remoteServerUser' => 'required|string' ,
]);
2024-09-10 15:18:00 +00:00
$this -> createdServer -> update ([
'port' => $this -> remoteServerPort ,
'user' => $this -> remoteServerUser ,
2024-09-10 15:29:53 +00:00
'timezone' => 'UTC' ,
]);
2024-09-10 14:55:34 +00:00
$this -> validateServer ();
}
2023-08-29 14:31:46 +00:00
private function createNewPrivateKey ()
{
$this -> privateKeyName = generate_random_name ();
$this -> privateKeyDescription = 'Created by Coolify' ;
2023-08-29 18:34:01 +00:00
[ 'private' => $this -> privateKey , 'public' => $this -> publicKey ] = generateSSHKey ();
2023-08-29 14:31:46 +00:00
}
2024-06-10 20:43:34 +00:00
2025-03-24 20:01:27 +00:00
private function disableSshMux () : void
{
$configRepository = app ( ConfigurationRepository :: class );
$configRepository -> disableSshMux ();
}
2023-08-29 14:31:46 +00:00
public function render ()
{
return view ( 'livewire.boarding.index' ) -> layout ( 'layouts.boarding' );
}
}