-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added the ship command with the find server feature
- Utilized the Laravel Pipeline - Set up the configuration file with proper validation
- Loading branch information
1 parent
101a05d
commit bda0e39
Showing
15 changed files
with
2,511 additions
and
272 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,3 +3,4 @@ | |
/.vscode | ||
/.vagrant | ||
.phpunit.result.cache | ||
.env |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
/** | ||
* This file is part of Harbor CLI. | ||
* | ||
* (c) Mehran Rasulian <[email protected]> | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
namespace App\Commands; | ||
|
||
use App\Services\Forge\ForgeService; | ||
use App\Services\Forge\Pipeline\FindServer; | ||
use App\Traits\Outputifier; | ||
use Illuminate\Support\Facades\Pipeline; | ||
use LaravelZero\Framework\Commands\Command; | ||
|
||
class ShipCommand extends Command | ||
{ | ||
use Outputifier; | ||
|
||
protected $signature = 'ship'; | ||
|
||
protected $description = 'Prepares the preview environment for your project.'; | ||
|
||
public function handle(ForgeService $service): void | ||
{ | ||
Pipeline::send($service) | ||
->through([ | ||
FindServer::class, | ||
]) | ||
->then(fn () => $this->success('It is done.')); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,104 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
/** | ||
* This file is part of Harbor CLI. | ||
* | ||
* (c) Mehran Rasulian <[email protected]> | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
namespace App\Services\Forge; | ||
|
||
use App\Actions\GenerateDomainName; | ||
use Laravel\Forge\Forge; | ||
use Laravel\Forge\Resources\Server; | ||
use Laravel\Forge\Resources\Site; | ||
|
||
class ForgeService | ||
{ | ||
/** | ||
* The Forge SDK instance. | ||
*/ | ||
public Forge $forge; | ||
|
||
/** | ||
* The Forge wrapper setting instance. | ||
*/ | ||
public ForgeSetting $setting; | ||
|
||
/** | ||
* The Forge server instance. | ||
*/ | ||
public ?Server $server = null; | ||
|
||
/** | ||
* The Forge site instance. | ||
*/ | ||
public ?Site $site = null; | ||
|
||
/** | ||
* New database credentials for updating the site's DB environment keys. | ||
*/ | ||
public ?array $database = []; | ||
|
||
/** | ||
* To check weather the site is created now. | ||
*/ | ||
public bool $siteNewlyMade = false; | ||
|
||
/** | ||
* Get the formatted domain based on subdomain pattern. | ||
*/ | ||
private ?string $formattedDomain = null; | ||
|
||
public function __construct() | ||
{ | ||
$this->setting = new ForgeSetting(); | ||
|
||
$this->forge = new Forge($this->setting->token); | ||
} | ||
|
||
public function setServer(Server $server): void | ||
{ | ||
$this->server = $server; | ||
} | ||
|
||
public function setSite(Site $site): void | ||
{ | ||
$this->site = $site; | ||
} | ||
|
||
public function setDatabase(array $database): void | ||
{ | ||
$this->database = $database; | ||
} | ||
|
||
public function getFormattedDomainName(): ?string | ||
{ | ||
if (is_null($this->formattedDomain)) { | ||
$this->formattedDomain = GenerateDomainName::run(); | ||
} | ||
|
||
return $this->formattedDomain; | ||
} | ||
|
||
public function findSite(string $serverId): ?Site | ||
{ | ||
foreach ($this->forge->sites($serverId) as $site) { | ||
if ($site->name === $this->getFormattedDomainName()) { | ||
return $site; | ||
} | ||
} | ||
|
||
return null; | ||
} | ||
|
||
public function markSiteAsNewlyMade(): void | ||
{ | ||
$this->siteNewlyMade = true; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,174 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
/** | ||
* This file is part of Harbor CLI. | ||
* | ||
* (c) Mehran Rasulian <[email protected]> | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
namespace App\Services\Forge; | ||
|
||
use Illuminate\Support\Facades\Validator; | ||
use Illuminate\Support\Str; | ||
use InvalidArgumentException; | ||
|
||
class ForgeSetting | ||
{ | ||
/** | ||
* The API token. | ||
*/ | ||
public string $token; | ||
|
||
/** | ||
* The server ID. | ||
*/ | ||
public string $server; | ||
|
||
/** | ||
* The site domain. | ||
*/ | ||
public string $domain; | ||
|
||
/** | ||
* The git provider. | ||
*/ | ||
public string $gitProvider; | ||
|
||
/** | ||
* The git repository. | ||
*/ | ||
public string $repository; | ||
|
||
/** | ||
* The git branch.. | ||
*/ | ||
public string $branch; | ||
|
||
/** | ||
* The subdomain pattern. | ||
*/ | ||
public ?string $subdomainPattern = null; | ||
|
||
/** | ||
* The project type | ||
*/ | ||
public string $projectType; | ||
|
||
/** | ||
* The PHP version | ||
*/ | ||
public string $phpVersion; | ||
|
||
/** | ||
* The Nginx template | ||
*/ | ||
public string $nginxTemplate; | ||
|
||
/** | ||
* Weather enable Quick Deploy. | ||
*/ | ||
public bool $quickDeploy; | ||
|
||
/** | ||
* Weather required to run site isolation. | ||
*/ | ||
public bool $siteIsolationRequired; | ||
|
||
/** | ||
* Weather required to run jobs scheduler. | ||
*/ | ||
public bool $jobSchedulerRequired; | ||
|
||
/** | ||
* Weather required to create database. | ||
*/ | ||
public bool $dbCreationRequired; | ||
|
||
/** | ||
* Whether to automatically source environment variables into the deployment script. | ||
*/ | ||
public bool $autoSourceRequired; | ||
|
||
/** | ||
* Whether to create the SSL certification. | ||
*/ | ||
public bool $sslRequired; | ||
|
||
/** | ||
* Wait on the site deployment during the provision. | ||
*/ | ||
public bool $waitOnDeploy; | ||
|
||
/** | ||
* Wait on the site deployment during the provision. | ||
*/ | ||
public bool $waitOnSsl; | ||
|
||
/** | ||
* A comma-separated string of key/values to update custom keys in the Nginx site template. | ||
*/ | ||
public ?string $nginxSubstitute = null; | ||
|
||
/** | ||
* The contents of the deployment script. | ||
*/ | ||
public ?string $deployScript = null; | ||
|
||
/** | ||
* The contents of the custom key/values to get added in the environment file on runtime. | ||
*/ | ||
public ?string $envVars = null; | ||
|
||
/** | ||
* The validation rules. | ||
*/ | ||
private array $validationRules = [ | ||
'token' => ['required'], | ||
'server' => ['required'], | ||
'domain' => ['required'], | ||
'git_provider' => ['required'], | ||
'repository' => ['required'], | ||
'branch' => ['required'], | ||
'subdomain_pattern' => ['nullable', 'string'], | ||
'project_type' => ['string'], | ||
'php_version' => ['string'], | ||
'nginx_template' => ['nullable', 'int'], | ||
'quick_deploy' => ['boolean'], | ||
'site_isolation_required' => ['boolean'], | ||
'job_scheduler_required' => ['boolean'], | ||
'db_creation_required' => ['boolean'], | ||
'auto_source_required' => ['boolean'], | ||
'ssl_required' => ['boolean'], | ||
'wait_on_ssl' => ['boolean'], | ||
'wait_on_deploy' => ['boolean'], | ||
]; | ||
|
||
public function __construct() | ||
{ | ||
$this->init(config('forge')); | ||
} | ||
|
||
private function init(array $configurations): void | ||
{ | ||
$validator = Validator::make($configurations, $this->validationRules); | ||
|
||
if ($validator->fails()) { | ||
// Handle validation failures. | ||
throw new InvalidArgumentException( | ||
'Invalid configuration values: '.implode(', ', $validator->errors()->all()) | ||
); | ||
} | ||
|
||
// If validation passes, set properties | ||
foreach ($configurations as $key => $value) { | ||
if (property_exists($this, $key = Str::camel($key))) { | ||
$this->$key = $value; | ||
} | ||
} | ||
} | ||
} |
Oops, something went wrong.