fix: services should have destination as well

This commit is contained in:
Andras Bacsai
2023-10-01 13:59:22 +02:00
parent 23968e7886
commit 9ab5a1f7bd
5 changed files with 78 additions and 9 deletions

View File

@@ -6,7 +6,7 @@ use App\Models\EnvironmentVariable;
use App\Models\Project;
use App\Models\Server;
use App\Models\Service;
use Illuminate\Support\Facades\Cache;
use App\Models\StandaloneDocker;
use Illuminate\Support\Str;
class ProjectController extends Controller
@@ -66,20 +66,22 @@ class ProjectController extends Controller
'database_uuid' => $standalone_postgresql->uuid,
]);
}
if ($type->startsWith('one-click-service-') && !is_null( (int)$server_id)) {
if ($type->startsWith('one-click-service-') && !is_null((int)$server_id)) {
$oneClickServiceName = $type->after('one-click-service-')->value();
$oneClickService = data_get($services, "$oneClickServiceName.compose");
ray($oneClickServiceName);
$oneClickDotEnvs = data_get($services, "$oneClickServiceName.envs", null);
if ($oneClickDotEnvs) {
$oneClickDotEnvs = Str::of(base64_decode($oneClickDotEnvs))->split('/\r\n|\r|\n/');
}
if ($oneClickService) {
$destination = StandaloneDocker::where('uuid', $destination_uuid)->first();
$service = Service::create([
'name' => "$oneClickServiceName-" . Str::random(10),
'docker_compose_raw' => base64_decode($oneClickService),
'environment_id' => $environment->id,
'server_id' => (int) $server_id,
'destination_id' => (int) $destination->id,
'destination_type' => $destination->getMorphClass(),
]);
$service->name = "$oneClickServiceName-" . $service->uuid;
$service->save();