wowowowowo
This commit is contained in:
@@ -2,15 +2,17 @@
|
||||
|
||||
namespace App\Http\Controllers;
|
||||
|
||||
use App\Http\Requests\StoreEnvironmentDeploymentRequest;
|
||||
use App\Jobs\Environments\DeployEnvironment;
|
||||
use App\Models\Application;
|
||||
use App\Models\Environment;
|
||||
use App\Models\Organisation;
|
||||
use Illuminate\Http\RedirectResponse;
|
||||
use Illuminate\Support\Collection;
|
||||
|
||||
class EnvironmentDeploymentController extends Controller
|
||||
{
|
||||
public function store(Organisation $organisation, Application $application, Environment $environment): RedirectResponse
|
||||
public function store(StoreEnvironmentDeploymentRequest $request, Organisation $organisation, Application $application, Environment $environment): RedirectResponse
|
||||
{
|
||||
abort_unless(
|
||||
(int) $application->organisation_id === (int) $organisation->id
|
||||
@@ -18,7 +20,16 @@ class EnvironmentDeploymentController extends Controller
|
||||
404,
|
||||
);
|
||||
|
||||
dispatch(new DeployEnvironment($environment));
|
||||
$environment->loadMissing('services.replicas');
|
||||
|
||||
if ($organisation->registries()->doesntExist() && $this->serverIdsFor($environment)->count() > 1) {
|
||||
return back()->with('error', 'Configure a registry before deploying this environment to multiple servers.');
|
||||
}
|
||||
|
||||
dispatch(new DeployEnvironment(
|
||||
environment: $environment,
|
||||
targetCommit: $request->validated('target_commit') ?: null,
|
||||
));
|
||||
|
||||
return redirect()->route('environments.show', [
|
||||
'organisation' => $organisation->id,
|
||||
@@ -26,4 +37,19 @@ class EnvironmentDeploymentController extends Controller
|
||||
'environment' => $environment->id,
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return \Illuminate\Support\Collection<int, int>
|
||||
*/
|
||||
private function serverIdsFor(Environment $environment): Collection
|
||||
{
|
||||
return $environment->services
|
||||
->flatMap(fn ($service) => [
|
||||
$service->server_id,
|
||||
...$service->replicas->pluck('server_id')->all(),
|
||||
])
|
||||
->filter()
|
||||
->unique()
|
||||
->values();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user