Fix docker compose PR location default value
This commit is contained in:
@@ -60,7 +60,9 @@ class General extends Component
|
|||||||
'application.docker_compose_location' => 'nullable',
|
'application.docker_compose_location' => 'nullable',
|
||||||
'application.docker_compose_pr_location' => 'nullable',
|
'application.docker_compose_pr_location' => 'nullable',
|
||||||
'application.docker_compose' => 'nullable',
|
'application.docker_compose' => 'nullable',
|
||||||
|
'application.docker_compose_pr' => 'nullable',
|
||||||
'application.docker_compose_raw' => 'nullable',
|
'application.docker_compose_raw' => 'nullable',
|
||||||
|
'application.docker_compose_pr_raw' => 'nullable',
|
||||||
'application.custom_labels' => 'nullable',
|
'application.custom_labels' => 'nullable',
|
||||||
'application.dockerfile_target_build' => 'nullable',
|
'application.dockerfile_target_build' => 'nullable',
|
||||||
'application.settings.is_static' => 'boolean|required',
|
'application.settings.is_static' => 'boolean|required',
|
||||||
@@ -88,7 +90,9 @@ class General extends Component
|
|||||||
'application.docker_compose_location' => 'Docker compose location',
|
'application.docker_compose_location' => 'Docker compose location',
|
||||||
'application.docker_compose_pr_location' => 'Docker compose location',
|
'application.docker_compose_pr_location' => 'Docker compose location',
|
||||||
'application.docker_compose' => 'Docker compose',
|
'application.docker_compose' => 'Docker compose',
|
||||||
|
'application.docker_compose_pr' => 'Docker compose',
|
||||||
'application.docker_compose_raw' => 'Docker compose raw',
|
'application.docker_compose_raw' => 'Docker compose raw',
|
||||||
|
'application.docker_compose_pr_raw' => 'Docker compose raw',
|
||||||
'application.custom_labels' => 'Custom labels',
|
'application.custom_labels' => 'Custom labels',
|
||||||
'application.dockerfile_target_build' => 'Dockerfile target build',
|
'application.dockerfile_target_build' => 'Dockerfile target build',
|
||||||
'application.settings.is_static' => 'Is static',
|
'application.settings.is_static' => 'Is static',
|
||||||
@@ -98,7 +102,6 @@ class General extends Component
|
|||||||
{
|
{
|
||||||
try {
|
try {
|
||||||
$this->parsedServices = $this->application->parseCompose();
|
$this->parsedServices = $this->application->parseCompose();
|
||||||
ray($this->parsedServices);
|
|
||||||
} catch (\Throwable $e) {
|
} catch (\Throwable $e) {
|
||||||
$this->emit('error', $e->getMessage());
|
$this->emit('error', $e->getMessage());
|
||||||
}
|
}
|
||||||
@@ -196,7 +199,7 @@ class General extends Component
|
|||||||
public function submit($showToaster = true)
|
public function submit($showToaster = true)
|
||||||
{
|
{
|
||||||
try {
|
try {
|
||||||
if ($this->initialDockerComposeLocation !== $this->application->docker_compose_location) {
|
if ($this->initialDockerComposeLocation !== $this->application->docker_compose_location || $this->initialDockerComposePrLocation !== $this->application->docker_compose_pr_location) {
|
||||||
$this->loadComposeFile();
|
$this->loadComposeFile();
|
||||||
}
|
}
|
||||||
$this->validate();
|
$this->validate();
|
||||||
|
@@ -153,7 +153,7 @@ class Application extends BaseModel
|
|||||||
return Attribute::make(
|
return Attribute::make(
|
||||||
set: function ($value) {
|
set: function ($value) {
|
||||||
if (is_null($value) || $value === '') {
|
if (is_null($value) || $value === '') {
|
||||||
return '/docker-compose-pr.yaml';
|
return '/docker-compose.yaml';
|
||||||
} else {
|
} else {
|
||||||
if ($value !== '/') {
|
if ($value !== '/') {
|
||||||
return Str::start(Str::replaceEnd('/', '', $value), '/');
|
return Str::start(Str::replaceEnd('/', '', $value), '/');
|
||||||
@@ -602,7 +602,11 @@ class Application extends BaseModel
|
|||||||
function parseCompose(int $pull_request_id = 0)
|
function parseCompose(int $pull_request_id = 0)
|
||||||
{
|
{
|
||||||
if ($this->docker_compose_raw) {
|
if ($this->docker_compose_raw) {
|
||||||
return parseDockerComposeFile(resource: $this, isNew: false, pull_request_id: $pull_request_id);
|
$mainCompose = parseDockerComposeFile(resource: $this, isNew: false, pull_request_id: $pull_request_id);
|
||||||
|
if ($this->getMorphClass() === 'App\Models\Application' && $this->docker_compose_pr_raw) {
|
||||||
|
parseDockerComposeFile(resource: $this, isNew: false, pull_request_id: $pull_request_id, is_pr: true);
|
||||||
|
}
|
||||||
|
return $mainCompose;
|
||||||
} else {
|
} else {
|
||||||
return collect([]);
|
return collect([]);
|
||||||
}
|
}
|
||||||
@@ -620,11 +624,15 @@ class Application extends BaseModel
|
|||||||
$workdir = rtrim($this->base_directory, '/');
|
$workdir = rtrim($this->base_directory, '/');
|
||||||
$composeFile = $this->docker_compose_location;
|
$composeFile = $this->docker_compose_location;
|
||||||
$prComposeFile = $this->docker_compose_pr_location;
|
$prComposeFile = $this->docker_compose_pr_location;
|
||||||
|
$fileList = collect([".$composeFile"]);
|
||||||
|
if ($composeFile !== $prComposeFile) {
|
||||||
|
$fileList->push(".$prComposeFile");
|
||||||
|
}
|
||||||
$commands = collect([
|
$commands = collect([
|
||||||
"mkdir -p /tmp/{$uuid} && cd /tmp/{$uuid}",
|
"mkdir -p /tmp/{$uuid} && cd /tmp/{$uuid}",
|
||||||
$cloneCommand,
|
$cloneCommand,
|
||||||
"git sparse-checkout init --cone",
|
"git sparse-checkout init --cone",
|
||||||
"git sparse-checkout set .$workdir$composeFile .$workdir$prComposeFile",
|
"git sparse-checkout set {$fileList->implode(' ')}",
|
||||||
"git read-tree -mu HEAD",
|
"git read-tree -mu HEAD",
|
||||||
"cat .$workdir$composeFile",
|
"cat .$workdir$composeFile",
|
||||||
]);
|
]);
|
||||||
@@ -632,23 +640,30 @@ class Application extends BaseModel
|
|||||||
if (!$composeFileContent) {
|
if (!$composeFileContent) {
|
||||||
$this->docker_compose_location = $initialDockerComposeLocation;
|
$this->docker_compose_location = $initialDockerComposeLocation;
|
||||||
$this->save();
|
$this->save();
|
||||||
throw new \Exception("Could not load compose file from $workdir$composeFile");
|
throw new \Exception("Could not load base compose file from $workdir$composeFile");
|
||||||
} else {
|
} else {
|
||||||
$this->docker_compose_raw = $composeFileContent;
|
$this->docker_compose_raw = $composeFileContent;
|
||||||
$this->save();
|
$this->save();
|
||||||
}
|
}
|
||||||
$commands = collect([
|
if ($composeFile === $prComposeFile) {
|
||||||
"cat .$workdir$prComposeFile",
|
$this->docker_compose_pr_raw = $composeFileContent;
|
||||||
]);
|
|
||||||
$composePrFileContent = instant_remote_process($commands, $this->destination->server, false);
|
|
||||||
if (!$composePrFileContent) {
|
|
||||||
$this->docker_compose_pr_location = $initialDockerComposePrLocation;
|
|
||||||
$this->save();
|
$this->save();
|
||||||
throw new \Exception("Could not load compose file from $workdir$prComposeFile");
|
|
||||||
} else {
|
} else {
|
||||||
$this->docker_compose_pr_raw = $composePrFileContent;
|
$commands = collect([
|
||||||
$this->save();
|
"cd /tmp/{$uuid}",
|
||||||
|
"cat .$workdir$prComposeFile",
|
||||||
|
]);
|
||||||
|
$composePrFileContent = instant_remote_process($commands, $this->destination->server, false);
|
||||||
|
if (!$composePrFileContent) {
|
||||||
|
$this->docker_compose_pr_location = $initialDockerComposePrLocation;
|
||||||
|
$this->save();
|
||||||
|
throw new \Exception("Could not load compose file from $workdir$prComposeFile");
|
||||||
|
} else {
|
||||||
|
$this->docker_compose_pr_raw = $composePrFileContent;
|
||||||
|
$this->save();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
$commands = collect([
|
$commands = collect([
|
||||||
"rm -rf /tmp/{$uuid}",
|
"rm -rf /tmp/{$uuid}",
|
||||||
]);
|
]);
|
||||||
|
@@ -579,7 +579,7 @@ function getTopLevelNetworks(Service|Application $resource)
|
|||||||
return $topLevelNetworks->keys();
|
return $topLevelNetworks->keys();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
function parseDockerComposeFile(Service|Application $resource, bool $isNew = false, int $pull_request_id)
|
function parseDockerComposeFile(Service|Application $resource, bool $isNew = false, int $pull_request_id, bool $is_pr = false)
|
||||||
{
|
{
|
||||||
// ray()->clearAll();
|
// ray()->clearAll();
|
||||||
if ($resource->getMorphClass() === 'App\Models\Service') {
|
if ($resource->getMorphClass() === 'App\Models\Service') {
|
||||||
@@ -1089,8 +1089,17 @@ function parseDockerComposeFile(Service|Application $resource, bool $isNew = fal
|
|||||||
return collect([]);
|
return collect([]);
|
||||||
}
|
}
|
||||||
} else if ($resource->getMorphClass() === 'App\Models\Application') {
|
} else if ($resource->getMorphClass() === 'App\Models\Application') {
|
||||||
if ($pull_request_id !== 0 && $resource->dockerComposePrLocation() !== $resource->dockerComposeLocation()) {
|
$isSameDockerComposeFile = false;
|
||||||
|
if ($resource->dockerComposePrLocation() === $resource->dockerComposeLocation()) {
|
||||||
|
$isSameDockerComposeFile = true;
|
||||||
|
$is_pr = false;
|
||||||
|
}
|
||||||
|
if ($is_pr) {
|
||||||
|
try {
|
||||||
|
$yaml = Yaml::parse($resource->docker_compose_pr_raw);
|
||||||
|
} catch (\Exception $e) {
|
||||||
|
throw new \Exception($e->getMessage());
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
try {
|
try {
|
||||||
$yaml = Yaml::parse($resource->docker_compose_raw);
|
$yaml = Yaml::parse($resource->docker_compose_raw);
|
||||||
@@ -1098,7 +1107,7 @@ function parseDockerComposeFile(Service|Application $resource, bool $isNew = fal
|
|||||||
throw new \Exception($e->getMessage());
|
throw new \Exception($e->getMessage());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
ray($yaml);
|
||||||
$server = $resource->destination->server;
|
$server = $resource->destination->server;
|
||||||
$topLevelVolumes = collect(data_get($yaml, 'volumes', []));
|
$topLevelVolumes = collect(data_get($yaml, 'volumes', []));
|
||||||
if ($pull_request_id !== 0) {
|
if ($pull_request_id !== 0) {
|
||||||
@@ -1172,7 +1181,6 @@ function parseDockerComposeFile(Service|Application $resource, bool $isNew = fal
|
|||||||
data_set($service, 'volumes', $serviceVolumes->toArray());
|
data_set($service, 'volumes', $serviceVolumes->toArray());
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
|
||||||
}
|
}
|
||||||
// Decide if the service is a database
|
// Decide if the service is a database
|
||||||
$isDatabase = isDatabaseImage(data_get_str($service, 'image'));
|
$isDatabase = isDatabaseImage(data_get_str($service, 'image'));
|
||||||
@@ -1469,8 +1477,20 @@ function parseDockerComposeFile(Service|Application $resource, bool $isNew = fal
|
|||||||
'volumes' => $topLevelVolumes->toArray(),
|
'volumes' => $topLevelVolumes->toArray(),
|
||||||
'networks' => $topLevelNetworks->toArray(),
|
'networks' => $topLevelNetworks->toArray(),
|
||||||
];
|
];
|
||||||
$resource->docker_compose_raw = Yaml::dump($yaml, 10, 2);
|
if ($isSameDockerComposeFile) {
|
||||||
$resource->docker_compose = Yaml::dump($finalServices, 10, 2);
|
$resource->docker_compose_pr_raw = Yaml::dump($yaml, 10, 2);
|
||||||
|
$resource->docker_compose_pr = Yaml::dump($finalServices, 10, 2);
|
||||||
|
$resource->docker_compose_raw = Yaml::dump($yaml, 10, 2);
|
||||||
|
$resource->docker_compose = Yaml::dump($finalServices, 10, 2);
|
||||||
|
} else {
|
||||||
|
if ($is_pr) {
|
||||||
|
$resource->docker_compose_pr_raw = Yaml::dump($yaml, 10, 2);
|
||||||
|
$resource->docker_compose_pr = Yaml::dump($finalServices, 10, 2);
|
||||||
|
} else {
|
||||||
|
$resource->docker_compose_raw = Yaml::dump($yaml, 10, 2);
|
||||||
|
$resource->docker_compose = Yaml::dump($finalServices, 10, 2);
|
||||||
|
}
|
||||||
|
}
|
||||||
$resource->save();
|
$resource->save();
|
||||||
return collect($finalServices);
|
return collect($finalServices);
|
||||||
}
|
}
|
||||||
|
@@ -13,7 +13,7 @@ return new class extends Migration
|
|||||||
{
|
{
|
||||||
Schema::table('applications', function (Blueprint $table) {
|
Schema::table('applications', function (Blueprint $table) {
|
||||||
$table->string('docker_compose_location')->nullable()->default('/docker-compose.yaml')->after('dockerfile_location');
|
$table->string('docker_compose_location')->nullable()->default('/docker-compose.yaml')->after('dockerfile_location');
|
||||||
$table->string('docker_compose_pr_location')->nullable()->default('/docker-compose-pr.yaml')->after('docker_compose_location');
|
$table->string('docker_compose_pr_location')->nullable()->default('/docker-compose.yaml')->after('docker_compose_location');
|
||||||
|
|
||||||
$table->longText('docker_compose')->nullable()->after('docker_compose_location');
|
$table->longText('docker_compose')->nullable()->after('docker_compose_location');
|
||||||
$table->longText('docker_compose_pr')->nullable()->after('docker_compose_location');
|
$table->longText('docker_compose_pr')->nullable()->after('docker_compose_location');
|
||||||
|
@@ -119,9 +119,9 @@
|
|||||||
<x-forms.input placeholder="/docker-compose.yaml" id="application.docker_compose_location"
|
<x-forms.input placeholder="/docker-compose.yaml" id="application.docker_compose_location"
|
||||||
label="Docker Compose Location"
|
label="Docker Compose Location"
|
||||||
helper="It is calculated together with the Base Directory:<br><span class='text-warning'>{{ Str::start($application->base_directory . $application->docker_compose_location, '/') }}</span>" />
|
helper="It is calculated together with the Base Directory:<br><span class='text-warning'>{{ Str::start($application->base_directory . $application->docker_compose_location, '/') }}</span>" />
|
||||||
<x-forms.input placeholder="/docker-compose.yaml" id="application.docker_compose_pr_location"
|
{{-- <x-forms.input placeholder="/docker-compose.yaml" id="application.docker_compose_pr_location"
|
||||||
label="Docker Compose Location For Pull Requests"
|
label="Docker Compose Location For Pull Requests"
|
||||||
helper="It is calculated together with the Base Directory:<br><span class='text-warning'>{{ Str::start($application->base_directory . $application->docker_compose_pr_location, '/') }}</span>" />
|
helper="It is calculated together with the Base Directory:<br><span class='text-warning'>{{ Str::start($application->base_directory . $application->docker_compose_pr_location, '/') }}</span>" /> --}}
|
||||||
@endif
|
@endif
|
||||||
@if ($application->build_pack === 'dockerfile')
|
@if ($application->build_pack === 'dockerfile')
|
||||||
<x-forms.input id="application.dockerfile_target_build" label="Docker Build Stage Target"
|
<x-forms.input id="application.dockerfile_target_build" label="Docker Build Stage Target"
|
||||||
@@ -140,9 +140,10 @@
|
|||||||
@endif
|
@endif
|
||||||
@if ($application->build_pack === 'dockercompose')
|
@if ($application->build_pack === 'dockercompose')
|
||||||
<x-forms.button wire:click="loadComposeFile">Reload Compose File</x-forms.button>
|
<x-forms.button wire:click="loadComposeFile">Reload Compose File</x-forms.button>
|
||||||
|
|
||||||
<x-forms.textarea rows="10" readonly id="application.docker_compose" label="Docker Compose Content"
|
<x-forms.textarea rows="10" readonly id="application.docker_compose" label="Docker Compose Content"
|
||||||
helper="You need to modify the docker compose file." />
|
helper="You need to modify the docker compose file." />
|
||||||
|
{{-- <x-forms.textarea rows="10" readonly id="application.docker_compose_pr"
|
||||||
|
label="Docker PR Compose Content" helper="You need to modify the docker compose file." /> --}}
|
||||||
@endif
|
@endif
|
||||||
|
|
||||||
@if ($application->dockerfile)
|
@if ($application->dockerfile)
|
||||||
|
Reference in New Issue
Block a user