Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[1.x] Sandbox #193

Merged
merged 12 commits into from
Sep 6, 2022
Merged
60 changes: 50 additions & 10 deletions src/Commands/Output/DeploymentSuccess.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,17 +29,11 @@ public function render(Deployment $deployment, DateTimeInterface $startedAt)
$this->displayDnsRecordsChanges($deployment);
}

if ($deployment->vanityDomain()) {
Helpers::line();

Helpers::table([
'<comment>Deployment ID</comment>',
'<comment>Environment URL</comment>',
], [[
"<options=bold>{$deployment->id}</>",
"<options=bold>https://{$deployment->vanityDomain()}</>",
]]);
if ($deployment->hasVanityDomain()) {
$this->displayVanityUrl($deployment);
}

$this->displayFunctionUrl($deployment);
}

/**
Expand Down Expand Up @@ -78,4 +72,50 @@ protected function displayDnsRecordsChanges(Deployment $deployment)
Helpers::line("The DNS records of the zone <comment>$zone</comment> have changed in the last week. If you self-manage the DNS settings of this zone, please run <comment>vapor record:list $zone</comment> and update the DNS settings of the domain accordingly.");
});
}

/**
* Display the vanity domain associated with this environment.
*
* @param \Laravel\VaporCli\Models\Deployment $deployment
* @return void
*/
protected function displayVanityUrl(Deployment $deployment)
{
Helpers::line();

Helpers::table([
'<comment>Deployment ID</comment>',
'<comment>Environment URL</comment>',
], [[
"<options=bold>{$deployment->id}</>",
"<options=bold>https://{$deployment->vanityDomain()}</>",
]]);
}

/**
* Display the function URL associated with this environment.
*
* @param \Laravel\VaporCli\Models\Deployment $deployment
* @return void
*/
protected function displayFunctionUrl(Deployment $deployment)
{
if ($deployment->hasTargetDomains() || $deployment->hasVanityDomain()) {
return;
}

if (! $deployment->hasFunctionUrl()) {
return;
}

Helpers::line();

Helpers::table([
'<comment>Deployment ID</comment>',
'<comment>Environment URL</comment>',
], [[
"<options=bold>{$deployment->id}</>",
"<options=bold>{$deployment->functionUrl()}</>",
]]);
}
}
12 changes: 11 additions & 1 deletion src/ConsoleVaporClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -1493,7 +1493,17 @@ protected function displayRequestErrors($response)
}

if ($response->getStatusCode() === 402) {
Helpers::abort('An active subscription is required to perform this action.');
Helpers::line('');
Helpers::danger('A valid subscription is required to perform this action.');
Helpers::line('');

if ($content = $response->getBody()->getContents()) {
Helpers::line(" - {$content}");
}

Helpers::line('');

exit(1);
}

if ($response->getStatusCode() === 403) {
Expand Down
59 changes: 31 additions & 28 deletions src/Manifest.php
Original file line number Diff line number Diff line change
Expand Up @@ -212,35 +212,38 @@ public static function fresh($project)
*/
protected static function freshConfiguration($project)
{
static::write(array_filter([
'id' => $project['id'],
'name' => $project['name'],
'environments' => [
'production' => array_filter([
'memory' => 1024,
'cli-memory' => 512,
'runtime' => 'php-8.1:al2',
'build' => [
'COMPOSER_MIRROR_PATH_REPOS=1 composer install --no-dev',
'php artisan event:cache',
file_exists(Path::current().'/webpack.mix.js')
? 'npm ci && npm run prod && rm -rf node_modules'
: 'npm ci && npm run build && rm -rf node_modules',
],
]),
'staging' => array_filter([
'memory' => 1024,
'cli-memory' => 512,
'runtime' => 'php-8.1:al2',
'build' => [
'COMPOSER_MIRROR_PATH_REPOS=1 composer install',
'php artisan event:cache',
file_exists(Path::current().'/webpack.mix.js')
? 'npm ci && npm run dev && rm -rf node_modules'
: 'npm ci && npm run build && rm -rf node_modules',
],
]),
$environments['production'] = array_filter([
'memory' => 1024,
'cli-memory' => 512,
'runtime' => 'php-8.1:al2',
'build' => [
'COMPOSER_MIRROR_PATH_REPOS=1 composer install --no-dev',
'php artisan event:cache',
file_exists(Path::current().'/webpack.mix.js')
? 'npm ci && npm run prod && rm -rf node_modules'
: 'npm ci && npm run build && rm -rf node_modules',
],
]);

if (! (isset($project['is_sandboxed']) && $project['is_sandboxed'])) {
$environments['staging'] = array_filter([
'memory' => 1024,
'cli-memory' => 512,
'runtime' => 'php-8.1:al2',
'build' => [
'COMPOSER_MIRROR_PATH_REPOS=1 composer install',
'php artisan event:cache',
file_exists(Path::current().'/webpack.mix.js')
? 'npm ci && npm run dev && rm -rf node_modules'
: 'npm ci && npm run build && rm -rf node_modules',
],
]);
}

static::write(array_filter([
'id' => $project['id'],
'name' => $project['name'],
'environments' => $environments,
]));
}

Expand Down
30 changes: 30 additions & 0 deletions src/Models/Deployment.php
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,16 @@ public function hasFailedHooks()
})['status'] ?? null) === 'failed';
}

/**
* Determine if the deployment has a vanity domain.
*
* @return bool
*/
public function hasVanityDomain()
{
return $this->vanityDomain() !== '';
}

/**
* Get the vanity domain for the deployment environment.
*
Expand All @@ -104,6 +114,26 @@ public function vanityDomain()
return $this->deployment['environment']['vanity_domain'];
}

/**
* Determine if the deployment has a function URL.
*
* @return bool
*/
public function hasFunctionUrl()
{
return ! is_null($this->functionUrl());
}

/**
* Get the function URL for the deployment environment.
*
* @return string|null
*/
public function functionUrl()
{
return isset($this->deployment['environment']['function_url']) ? $this->deployment['environment']['function_url'] : null;
}

/**
* Returns a list of solutions for the current deployment failure.
*
Expand Down