fix: nixpacks buildpack

This commit is contained in:
Andras Bacsai
2024-01-03 21:03:46 +01:00
parent 65be83e75d
commit 6159783a73
4 changed files with 37 additions and 50 deletions

View File

@@ -81,7 +81,6 @@ class ApplicationDeploymentJob implements ShouldQueue, ShouldBeEncrypted
private ?string $buildTarget = null; private ?string $buildTarget = null;
private Collection $saved_outputs; private Collection $saved_outputs;
private ?string $full_healthcheck_url = null; private ?string $full_healthcheck_url = null;
private ?string $nixpacks_command = null;
private string $serverUser = 'root'; private string $serverUser = 'root';
private string $serverUserHomeDir = '/root'; private string $serverUserHomeDir = '/root';
@@ -165,11 +164,15 @@ class ApplicationDeploymentJob implements ShouldQueue, ShouldBeEncrypted
$ips = collect([]); $ips = collect([]);
if (count($allContainers) > 0) { if (count($allContainers) > 0) {
$allContainers = $allContainers[0]; $allContainers = $allContainers[0];
$allContainers = collect($allContainers)->sort()->values();
foreach ($allContainers as $container) { foreach ($allContainers as $container) {
$containerName = data_get($container, 'Name'); $containerName = data_get($container, 'Name');
if ($containerName === 'coolify-proxy') { if ($containerName === 'coolify-proxy') {
continue; continue;
} }
if (preg_match('/-(\d{12})/',$containerName)) {
continue;
}
$containerIp = data_get($container, 'IPv4Address'); $containerIp = data_get($container, 'IPv4Address');
if ($containerName && $containerIp) { if ($containerName && $containerIp) {
$containerIp = str($containerIp)->before('/'); $containerIp = str($containerIp)->before('/');
@@ -876,15 +879,11 @@ class ApplicationDeploymentJob implements ShouldQueue, ShouldBeEncrypted
private function nixpacks_build_cmd() private function nixpacks_build_cmd()
{ {
$this->generate_env_variables(); $this->generate_env_variables();
$cacheKey = $this->application->uuid; // $cacheKey = $this->application->uuid;
if ($this->pull_request_id !== 0) { // if ($this->pull_request_id !== 0) {
$cacheKey = "{$this->application->uuid}-pr-{$this->pull_request_id}"; // $cacheKey = "{$this->application->uuid}-pr-{$this->pull_request_id}";
} // }
if ($this->force_rebuild) { $nixpacks_command = "nixpacks build --no-cache {$this->env_args} --no-error-without-start";
$nixpacks_command = "nixpacks build --no-cache {$this->env_args} --no-error-without-start";
} else {
$nixpacks_command = "nixpacks build --cache-key '{$cacheKey}' {$this->env_args} --no-error-without-start";
}
if ($this->application->build_command) { if ($this->application->build_command) {
$nixpacks_command .= " --build-cmd \"{$this->application->build_command}\""; $nixpacks_command .= " --build-cmd \"{$this->application->build_command}\"";
} }
@@ -894,7 +893,6 @@ class ApplicationDeploymentJob implements ShouldQueue, ShouldBeEncrypted
if ($this->application->install_command) { if ($this->application->install_command) {
$nixpacks_command .= " --install-cmd \"{$this->application->install_command}\""; $nixpacks_command .= " --install-cmd \"{$this->application->install_command}\"";
} }
$this->nixpacks_command = $nixpacks_command;
$nixpacks_command .= " -o {$this->workdir} {$this->workdir}"; $nixpacks_command .= " -o {$this->workdir} {$this->workdir}";
return $nixpacks_command; return $nixpacks_command;
} }
@@ -1232,26 +1230,21 @@ COPY ./nginx.conf /etc/nginx/conf.d/default.conf");
} }
}"); }");
} else { } else {
if ($this->application->build_pack === 'nixpacks') { $this->execute_remote_command(
$this->execute_remote_command( [
[ executeInDocker($this->deployment_uuid, "cp {$this->workdir}/Dockerfile {$this->workdir}/.nixpacks/Dockerfile")
executeInDocker($this->deployment_uuid, "mv {$this->workdir}/Dockerfile {$this->workdir}/.nixpacks/Dockerfile") ],
], );
[ if ($this->force_rebuild) {
executeInDocker($this->deployment_uuid, $this->nixpacks_command . " --name $this->build_image_name {$this->workdir}"), "hidden" => true $this->execute_remote_command([
] executeInDocker($this->deployment_uuid, "docker build --no-cache $this->buildTarget $this->addHosts --network host -f {$this->workdir}{$this->dockerfile_location} {$this->build_args} --progress plain -t $this->build_image_name {$this->workdir}"), "hidden" => true
); ]);
} else { } else {
if ($this->force_rebuild) { $this->execute_remote_command([
$this->execute_remote_command([ executeInDocker($this->deployment_uuid, "docker build $this->buildTarget $this->addHosts --network host -f {$this->workdir}{$this->dockerfile_location} {$this->build_args} --progress plain -t $this->build_image_name {$this->workdir}"), "hidden" => true
executeInDocker($this->deployment_uuid, "docker build --no-cache $this->buildTarget $this->addHosts --network host -f {$this->workdir}{$this->dockerfile_location} {$this->build_args} --progress plain -t $this->build_image_name {$this->workdir}"), "hidden" => true ]);
]);
} else {
$this->execute_remote_command([
executeInDocker($this->deployment_uuid, "docker build $this->buildTarget $this->addHosts --network host -f {$this->workdir}{$this->dockerfile_location} {$this->build_args} --progress plain -t $this->build_image_name {$this->workdir}"), "hidden" => true
]);
}
} }
// }
$dockerfile = base64_encode("FROM {$this->application->static_image} $dockerfile = base64_encode("FROM {$this->application->static_image}
WORKDIR /usr/share/nginx/html/ WORKDIR /usr/share/nginx/html/
@@ -1295,25 +1288,19 @@ COPY ./nginx.conf /etc/nginx/conf.d/default.conf");
]); ]);
} else { } else {
if ($this->application->build_pack === 'nixpacks') { $this->execute_remote_command(
$this->execute_remote_command( [
[ executeInDocker($this->deployment_uuid, "cp {$this->workdir}/Dockerfile {$this->workdir}/.nixpacks/Dockerfile")
executeInDocker($this->deployment_uuid, "mv {$this->workdir}/Dockerfile {$this->workdir}/.nixpacks/Dockerfile") ],
], );
[ if ($this->force_rebuild) {
executeInDocker($this->deployment_uuid, $this->nixpacks_command . " --name {$this->production_image_name} {$this->workdir}"), "hidden" => true $this->execute_remote_command([
] executeInDocker($this->deployment_uuid, "docker build --no-cache $this->buildTarget $this->addHosts --network host -f {$this->workdir}{$this->dockerfile_location} {$this->build_args} --progress plain -t $this->production_image_name {$this->workdir}"), "hidden" => true
); ]);
} else { } else {
if ($this->force_rebuild) { $this->execute_remote_command([
$this->execute_remote_command([ executeInDocker($this->deployment_uuid, "docker build $this->buildTarget $this->addHosts --network host -f {$this->workdir}{$this->dockerfile_location} {$this->build_args} --progress plain -t $this->production_image_name {$this->workdir}"), "hidden" => true
executeInDocker($this->deployment_uuid, "docker build --no-cache $this->buildTarget $this->addHosts --network host -f {$this->workdir}{$this->dockerfile_location} {$this->build_args} --progress plain -t $this->production_image_name {$this->workdir}"), "hidden" => true ]);
]);
} else {
$this->execute_remote_command([
executeInDocker($this->deployment_uuid, "docker build $this->buildTarget $this->addHosts --network host -f {$this->workdir}{$this->dockerfile_location} {$this->build_args} --progress plain -t $this->production_image_name {$this->workdir}"), "hidden" => true
]);
}
} }
} }
} }

View File

@@ -7,7 +7,7 @@ return [
// The release version of your application // The release version of your application
// Example with dynamic git hash: trim(exec('git --git-dir ' . base_path('.git') . ' log --pretty="%h" -n1 HEAD')) // Example with dynamic git hash: trim(exec('git --git-dir ' . base_path('.git') . ' log --pretty="%h" -n1 HEAD'))
'release' => '4.0.0-beta.180', 'release' => '4.0.0-beta.181',
// When left empty or `null` the Laravel environment will be used // When left empty or `null` the Laravel environment will be used
'environment' => config('app.env'), 'environment' => config('app.env'),

View File

@@ -1,3 +1,3 @@
<?php <?php
return '4.0.0-beta.180'; return '4.0.0-beta.181';

View File

@@ -4,7 +4,7 @@
"version": "3.12.36" "version": "3.12.36"
}, },
"v4": { "v4": {
"version": "4.0.0-beta.180" "version": "4.0.0-beta.181"
} }
} }
} }