Skip to content

Commit 2978042

Browse files
authored
Merge pull request coollabsio#2835 from coollabsio/next
v4.0.0-beta.314
2 parents 6ada6d1 + 4225ec7 commit 2978042

30 files changed

+552
-100
lines changed

app/Actions/Service/StartService.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ public function handle(Service $service)
2020
$commands[] = "docker network inspect $service->uuid >/dev/null 2>&1 || docker network create --attachable $service->uuid";
2121
$commands[] = 'echo Starting service.';
2222
$commands[] = "echo 'Pulling images.'";
23-
$commands[] = 'docker compose pull';
23+
$commands[] = 'docker compose pull --policy always';
2424
$commands[] = "echo 'Starting containers.'";
2525
$commands[] = 'docker compose up -d --remove-orphans --force-recreate --build';
2626
$commands[] = "docker network connect $service->uuid coolify-proxy >/dev/null 2>&1 || true";

app/Actions/Shared/PullImage.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ public function handle(Service $resource)
1515

1616
$commands[] = 'cd '.$resource->workdir();
1717
$commands[] = "echo 'Saved configuration files to {$resource->workdir()}.'";
18-
$commands[] = 'docker compose pull';
18+
$commands[] = 'docker compose pull --policy always';
1919

2020
$server = data_get($resource, 'server');
2121

app/Jobs/ApplicationDeploymentJob.php

Lines changed: 9 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -462,7 +462,7 @@ private function deploy_docker_compose_buildpack()
462462
if ($this->env_filename) {
463463
$command .= " --env-file {$this->workdir}/{$this->env_filename}";
464464
}
465-
$command .= " --project-name {$this->application->uuid} --project-directory {$this->workdir} -f {$this->workdir}{$this->docker_compose_location} build";
465+
$command .= " --project-name {$this->application->uuid} --project-directory {$this->workdir} -f {$this->workdir}{$this->docker_compose_location} build --pull";
466466
$this->execute_remote_command(
467467
[executeInDocker($this->deployment_uuid, $command), 'hidden' => true],
468468
);
@@ -1624,12 +1624,15 @@ private function generate_compose_file()
16241624
],
16251625
],
16261626
];
1627+
if (data_get($this->application, 'swarm_placement_constraints')) {
1628+
$swarm_placement_constraints = Yaml::parse(base64_decode(data_get($this->application, 'swarm_placement_constraints')));
1629+
$docker_compose['services'][$this->container_name]['deploy'] = array_merge(
1630+
$docker_compose['services'][$this->container_name]['deploy'],
1631+
$swarm_placement_constraints
1632+
);
1633+
}
16271634
if (data_get($this->application, 'settings.is_swarm_only_worker_nodes')) {
1628-
$docker_compose['services'][$this->container_name]['deploy']['placement'] = [
1629-
'constraints' => [
1630-
'node.role == worker',
1631-
],
1632-
];
1635+
$docker_compose['services'][$this->container_name]['deploy']['placement']['constraints'][] = 'node.role == worker';
16331636
}
16341637
if ($this->pull_request_id !== 0) {
16351638
$docker_compose['services'][$this->container_name]['deploy']['replicas'] = 1;
@@ -2028,23 +2031,6 @@ private function stop_running_container(bool $force = false)
20282031
}
20292032
}
20302033

2031-
private function build_by_compose_file()
2032-
{
2033-
$this->application_deployment_queue->addLogEntry('Pulling & building required images.');
2034-
if ($this->application->build_pack === 'dockerimage') {
2035-
$this->application_deployment_queue->addLogEntry('Pulling latest images from the registry.');
2036-
$this->execute_remote_command(
2037-
[executeInDocker($this->deployment_uuid, "docker compose --project-name {$this->application->uuid} --project-directory {$this->workdir} pull"), 'hidden' => true],
2038-
[executeInDocker($this->deployment_uuid, "{$this->coolify_variables} docker compose --project-name {$this->application->uuid} --project-directory {$this->workdir} build"), 'hidden' => true],
2039-
);
2040-
} else {
2041-
$this->execute_remote_command(
2042-
[executeInDocker($this->deployment_uuid, "{$this->coolify_variables} docker compose --project-name {$this->application->uuid} --project-directory {$this->workdir} -f {$this->workdir}{$this->docker_compose_location} build"), 'hidden' => true],
2043-
);
2044-
}
2045-
$this->application_deployment_queue->addLogEntry('New images built.');
2046-
}
2047-
20482034
private function start_by_compose_file()
20492035
{
20502036
if ($this->application->build_pack === 'dockerimage') {

app/Livewire/Project/New/GithubPrivateRepository.php

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,12 @@ class GithubPrivateRepository extends Component
5353

5454
public ?string $publish_directory = null;
5555

56+
// In case of docker compose
57+
public ?string $base_directory = null;
58+
59+
public ?string $docker_compose_location = '/docker-compose.yaml';
60+
// End of docker compose
61+
5662
protected int $page = 1;
5763

5864
public $build_pack = 'nixpacks';
@@ -68,6 +74,16 @@ public function mount()
6874
$this->github_apps = GithubApp::private();
6975
}
7076

77+
public function updatedBaseDirectory()
78+
{
79+
if ($this->base_directory) {
80+
$this->base_directory = rtrim($this->base_directory, '/');
81+
if (! str($this->base_directory)->startsWith('/')) {
82+
$this->base_directory = '/'.$this->base_directory;
83+
}
84+
}
85+
}
86+
7187
public function updatedBuildPack()
7288
{
7389
if ($this->build_pack === 'nixpacks') {
@@ -184,6 +200,10 @@ public function submit()
184200
if ($this->build_pack === 'dockerfile' || $this->build_pack === 'dockerimage') {
185201
$application->health_check_enabled = false;
186202
}
203+
if ($this->build_pack === 'dockercompose') {
204+
$application['docker_compose_location'] = $this->docker_compose_location;
205+
$application['base_directory'] = $this->base_directory;
206+
}
187207
$fqdn = generateFqdn($destination->server, $application->uuid);
188208
$application->fqdn = $fqdn;
189209

app/Livewire/Project/New/GithubPrivateRepositoryDeployKey.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,12 @@ class GithubPrivateRepositoryDeployKey extends Component
3333

3434
public ?string $publish_directory = null;
3535

36+
// In case of docker compose
37+
public ?string $base_directory = null;
38+
39+
public ?string $docker_compose_location = '/docker-compose.yaml';
40+
// End of docker compose
41+
3642
public string $repository_url;
3743

3844
public string $branch;
@@ -163,6 +169,10 @@ public function submit()
163169
if ($this->build_pack === 'dockerfile' || $this->build_pack === 'dockerimage') {
164170
$application_init['health_check_enabled'] = false;
165171
}
172+
if ($this->build_pack === 'dockercompose') {
173+
$application_init['docker_compose_location'] = $this->docker_compose_location;
174+
$application_init['base_directory'] = $this->base_directory;
175+
}
166176
$application = Application::create($application_init);
167177
$application->settings->is_static = $this->is_static;
168178
$application->settings->save();

app/Livewire/Project/New/PublicGitRepository.php

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,12 @@ class PublicGitRepository extends Component
3333

3434
public ?string $publish_directory = null;
3535

36+
// In case of docker compose
37+
public ?string $base_directory = null;
38+
39+
public ?string $docker_compose_location = '/docker-compose.yaml';
40+
// End of docker compose
41+
3642
public string $git_branch = 'main';
3743

3844
public int $rate_limit_remaining = 0;
@@ -59,6 +65,8 @@ class PublicGitRepository extends Component
5965
'is_static' => 'required|boolean',
6066
'publish_directory' => 'nullable|string',
6167
'build_pack' => 'required|string',
68+
'base_directory' => 'nullable|string',
69+
'docker_compose_location' => 'nullable|string',
6270
];
6371

6472
protected $validationAttributes = [
@@ -67,6 +75,8 @@ class PublicGitRepository extends Component
6775
'is_static' => 'static',
6876
'publish_directory' => 'publish directory',
6977
'build_pack' => 'build pack',
78+
'base_directory' => 'base directory',
79+
'docker_compose_location' => 'docker compose location',
7080
];
7181

7282
public function mount()
@@ -79,6 +89,16 @@ public function mount()
7989
$this->query = request()->query();
8090
}
8191

92+
public function updatedBaseDirectory()
93+
{
94+
if ($this->base_directory) {
95+
$this->base_directory = rtrim($this->base_directory, '/');
96+
if (! str($this->base_directory)->startsWith('/')) {
97+
$this->base_directory = '/'.$this->base_directory;
98+
}
99+
}
100+
}
101+
82102
public function updatedBuildPack()
83103
{
84104
if ($this->build_pack === 'nixpacks') {
@@ -261,6 +281,10 @@ public function submit()
261281
if ($this->build_pack === 'dockerfile' || $this->build_pack === 'dockerimage') {
262282
$application_init['health_check_enabled'] = false;
263283
}
284+
if ($this->build_pack === 'dockercompose') {
285+
$application_init['docker_compose_location'] = $this->docker_compose_location;
286+
$application_init['base_directory'] = $this->base_directory;
287+
}
264288
$application = Application::create($application_init);
265289

266290
$application->settings->is_static = $this->is_static;

app/Livewire/Project/Shared/Storages/Show.php

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,16 +4,13 @@
44

55
use App\Models\LocalPersistentVolume;
66
use Livewire\Component;
7-
use Visus\Cuid2\Cuid2;
87

98
class Show extends Component
109
{
1110
public LocalPersistentVolume $storage;
1211

1312
public bool $isReadOnly = false;
1413

15-
public ?string $modalId = null;
16-
1714
public bool $isFirst = true;
1815

1916
public bool $isService = false;
@@ -32,11 +29,6 @@ class Show extends Component
3229
'host_path' => 'host',
3330
];
3431

35-
public function mount()
36-
{
37-
$this->modalId = new Cuid2(7);
38-
}
39-
4032
public function submit()
4133
{
4234
$this->validate();

app/Models/Application.php

Lines changed: 38 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1081,45 +1081,55 @@ public function loadComposeFile($isInit = false)
10811081
'git read-tree -mu HEAD',
10821082
"cat .$workdir$composeFile",
10831083
]);
1084-
$composeFileContent = instant_remote_process($commands, $this->destination->server, false);
1085-
if (! $composeFileContent) {
1084+
try {
1085+
$composeFileContent = instant_remote_process($commands, $this->destination->server);
1086+
} catch (\Exception $e) {
1087+
if (str($e->getMessage())->contains('No such file')) {
1088+
throw new \RuntimeException("Docker Compose file not found at: $workdir$composeFile<br><br>Check if you used the right extension (.yaml or .yml) in the compose file name.");
1089+
}
1090+
if (str($e->getMessage())->contains('fatal: repository') && str($e->getMessage())->contains('does not exist')) {
1091+
if ($this->deploymentType() === 'deploy_key') {
1092+
throw new \RuntimeException('Your deploy key does not have access to the repository. Please check your deploy key and try again.');
1093+
}
1094+
throw new \RuntimeException('Repository does not exist. Please check your repository URL and try again.');
1095+
}
1096+
throw new \RuntimeException($e->getMessage());
1097+
} finally {
10861098
$this->docker_compose_location = $initialDockerComposeLocation;
10871099
$this->save();
10881100
$commands = collect([
10891101
"rm -rf /tmp/{$uuid}",
10901102
]);
10911103
instant_remote_process($commands, $this->destination->server, false);
1092-
throw new \RuntimeException("Docker Compose file not found at: $workdir$composeFile<br><br>Check if you used the right extension (.yaml or .yml) in the compose file name.");
1093-
} else {
1104+
}
1105+
if ($composeFileContent) {
10941106
$this->docker_compose_raw = $composeFileContent;
10951107
$this->save();
1096-
}
1097-
1098-
$commands = collect([
1099-
"rm -rf /tmp/{$uuid}",
1100-
]);
1101-
instant_remote_process($commands, $this->destination->server, false);
1102-
$parsedServices = $this->parseCompose();
1103-
if ($this->docker_compose_domains) {
1104-
$json = collect(json_decode($this->docker_compose_domains));
1105-
$names = collect(data_get($parsedServices, 'services'))->keys()->toArray();
1106-
$jsonNames = $json->keys()->toArray();
1107-
$diff = array_diff($jsonNames, $names);
1108-
$json = $json->filter(function ($value, $key) use ($diff) {
1109-
return ! in_array($key, $diff);
1110-
});
1111-
if ($json) {
1112-
$this->docker_compose_domains = json_encode($json);
1113-
} else {
1114-
$this->docker_compose_domains = null;
1108+
$parsedServices = $this->parseCompose();
1109+
if ($this->docker_compose_domains) {
1110+
$json = collect(json_decode($this->docker_compose_domains));
1111+
$names = collect(data_get($parsedServices, 'services'))->keys()->toArray();
1112+
$jsonNames = $json->keys()->toArray();
1113+
$diff = array_diff($jsonNames, $names);
1114+
$json = $json->filter(function ($value, $key) use ($diff) {
1115+
return ! in_array($key, $diff);
1116+
});
1117+
if ($json) {
1118+
$this->docker_compose_domains = json_encode($json);
1119+
} else {
1120+
$this->docker_compose_domains = null;
1121+
}
1122+
$this->save();
11151123
}
1116-
$this->save();
1124+
1125+
return [
1126+
'parsedServices' => $parsedServices,
1127+
'initialDockerComposeLocation' => $this->docker_compose_location,
1128+
];
1129+
} else {
1130+
throw new \RuntimeException("Docker Compose file not found at: $workdir$composeFile<br><br>Check if you used the right extension (.yaml or .yml) in the compose file name.");
11171131
}
11181132

1119-
return [
1120-
'parsedServices' => $parsedServices,
1121-
'initialDockerComposeLocation' => $this->docker_compose_location,
1122-
];
11231133
}
11241134

11251135
public function parseContainerLabels(?ApplicationPreview $preview = null)

bootstrap/helpers/services.php

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,9 @@ function updateCompose(ServiceApplication|ServiceDatabase $resource)
8888
try {
8989
$name = data_get($resource, 'name');
9090
$dockerComposeRaw = data_get($resource, 'service.docker_compose_raw');
91+
if (! $dockerComposeRaw) {
92+
throw new \Exception('No compose file found or not a valid YAML file.');
93+
}
9194
$dockerCompose = Yaml::parse($dockerComposeRaw);
9295

9396
// Switch Image
@@ -106,7 +109,7 @@ function updateCompose(ServiceApplication|ServiceDatabase $resource)
106109
if ($resourceFqdns->count() === 1) {
107110
$resourceFqdns = $resourceFqdns->first();
108111
$variableName = 'SERVICE_FQDN_'.str($resource->name)->upper()->replace('-', '');
109-
$generatedEnv = EnvironmentVariable::where('service_id', $resource->service_id)->where('key', $variableName)->first();
112+
$generatedEnv = EnvironmentVariable::where('service_id', $resource->service_id)->where('key', 'LIKE', "{$variableName}_%")->first();
110113
$fqdn = Url::fromString($resourceFqdns);
111114
$port = $fqdn->getPort();
112115
$path = $fqdn->getPath();
@@ -125,7 +128,7 @@ function updateCompose(ServiceApplication|ServiceDatabase $resource)
125128
}
126129
}
127130
$variableName = 'SERVICE_URL_'.str($resource->name)->upper()->replace('-', '');
128-
$generatedEnv = EnvironmentVariable::where('service_id', $resource->service_id)->where('key', $variableName)->first();
131+
$generatedEnv = EnvironmentVariable::where('service_id', $resource->service_id)->where('key', 'LIKE', "{$variableName}_%")->first();
129132
$url = Url::fromString($fqdn);
130133
$port = $url->getPort();
131134
$path = $url->getPath();

config/sentry.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77

88
// The release version of your application
99
// Example with dynamic git hash: trim(exec('git --git-dir ' . base_path('.git') . ' log --pretty="%h" -n1 HEAD'))
10-
'release' => '4.0.0-beta.313',
10+
'release' => '4.0.0-beta.314',
1111
// When left empty or `null` the Laravel environment will be used
1212
'environment' => config('app.env'),
1313

0 commit comments

Comments
 (0)