From 4f5e12bd6f20910d20e8089f24ccf6d490080349 Mon Sep 17 00:00:00 2001 From: Joe Dixon Date: Mon, 10 Oct 2022 16:29:45 +0100 Subject: [PATCH] Show asset domain in output --- src/Commands/DeployCommand.php | 14 +++++++++++ src/Commands/Output/DeploymentSuccess.php | 29 +++++++++++++++++++++++ 2 files changed, 43 insertions(+) diff --git a/src/Commands/DeployCommand.php b/src/Commands/DeployCommand.php index e9e2c603..85e8f3a9 100644 --- a/src/Commands/DeployCommand.php +++ b/src/Commands/DeployCommand.php @@ -137,6 +137,10 @@ protected function buildProject(array $project) */ protected function assetDomain(array $project) { + if ($this->usesCloudFront() && $domain = $this->customAssetDomain()) { + return "https://$domain"; + } + if ($this->usesCloudFront() && $project['cloudfront_status'] == 'deployed') { return $project['asset_domains']['cloudfront'] ?? $project['asset_domains']['s3']; @@ -155,6 +159,16 @@ protected function usesCloudFront() return Manifest::current()['environments'][$this->argument('environment')]['cloudfront'] ?? true; } + /** + * Determine if the project uses a custom asset domain. + * + * @return string|null + */ + protected function customAssetDomain() + { + return Manifest::current()['asset-domain'] ?? null; + } + /** * Upload the deployment artifact. * diff --git a/src/Commands/Output/DeploymentSuccess.php b/src/Commands/Output/DeploymentSuccess.php index 51276e39..99dc73e7 100644 --- a/src/Commands/Output/DeploymentSuccess.php +++ b/src/Commands/Output/DeploymentSuccess.php @@ -34,6 +34,8 @@ public function render(Deployment $deployment, DateTimeInterface $startedAt) } $this->displayFunctionUrl($deployment); + + $this->displayAssetDomainDnsRecordChanges($deployment); } /** @@ -118,4 +120,31 @@ protected function displayFunctionUrl(Deployment $deployment) "{$deployment->functionUrl()}", ]]); } + + /** + * Display the DNS Records changes related to the asset domain. + * + * @param \Laravel\VaporCli\Models\Deployment $deployment + * @return void + */ + protected function displayAssetDomainDnsRecordChanges(Deployment $deployment) + { + if (! $assetDomain = $deployment->manifest['asset-domain'] ?? null) { + return; + } + + Helpers::line(); + + if ($deployment->created_asset_domain) { + Helpers::line('Custom asset domain created: Custom domains may take up to an hour to become active after provisioning.'); + + Helpers::line(); + } + + Helpers::table([ + 'Domain', 'Alias / CNAME', + ], [[ + $assetDomain, $deployment->project['cloudfront_domain'], + ]]); + } }