fix
This commit is contained in:
parent
f5da79b690
commit
f93b643e43
@ -9,7 +9,7 @@ class ForceUpgrade extends Component
|
|||||||
{
|
{
|
||||||
public function upgrade()
|
public function upgrade()
|
||||||
{
|
{
|
||||||
dispatch_sync(new InstanceAutoUpdateJob());
|
dispatch_sync(new InstanceAutoUpdateJob(force: true));
|
||||||
$this->emit('updateInitiated');
|
$this->emit('updateInitiated');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -10,77 +10,79 @@ use Illuminate\Contracts\Queue\ShouldQueue;
|
|||||||
use Illuminate\Foundation\Bus\Dispatchable;
|
use Illuminate\Foundation\Bus\Dispatchable;
|
||||||
use Illuminate\Queue\InteractsWithQueue;
|
use Illuminate\Queue\InteractsWithQueue;
|
||||||
use Illuminate\Queue\SerializesModels;
|
use Illuminate\Queue\SerializesModels;
|
||||||
|
use Log;
|
||||||
|
|
||||||
class InstanceAutoUpdateJob implements ShouldQueue
|
class InstanceAutoUpdateJob implements ShouldQueue
|
||||||
{
|
{
|
||||||
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
|
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
|
||||||
|
|
||||||
/**
|
private string $latest_version;
|
||||||
* Create a new job instance.
|
private string $current_version;
|
||||||
*/
|
private Server $server;
|
||||||
public function __construct()
|
private string $server_name = 'host.docker.internal';
|
||||||
{
|
|
||||||
$instance_settings = InstanceSettings::get();
|
|
||||||
if (!$instance_settings->is_auto_update_enabled) {
|
|
||||||
$this->delete();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
public function __construct(private bool $force = false)
|
||||||
* Execute the job.
|
|
||||||
*/
|
|
||||||
public function handle(): void
|
|
||||||
{
|
{
|
||||||
if (config('app.env') === 'local') {
|
if (config('app.env') === 'local') {
|
||||||
$latest_version = get_latest_version_of_coolify();
|
$this->server_name = 'coolify-testing-host';
|
||||||
$current_version = config('version');
|
}
|
||||||
if ($latest_version === $current_version) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if (version_compare($latest_version, $current_version, '<')) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
$server = Server::where('ip', 'coolify-testing-host')->first();
|
$instance_settings = InstanceSettings::get();
|
||||||
if (!$server) {
|
$this->server = Server::where('ip', $this->server_name)->first();
|
||||||
return;
|
|
||||||
}
|
|
||||||
instant_remote_process([
|
|
||||||
"sleep 2"
|
|
||||||
], $server);
|
|
||||||
remote_process([
|
|
||||||
"sleep 10"
|
|
||||||
], $server, ActivityTypes::INLINE->value);
|
|
||||||
} else {
|
|
||||||
$latest_version = get_latest_version_of_coolify();
|
|
||||||
$current_version = config('version');
|
|
||||||
if ($latest_version === $current_version) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if (version_compare($latest_version, $current_version, '<')) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
$cdn = "https://coolify-cdn.b-cdn.net/files";
|
if (!$instance_settings->is_auto_update_enabled || !$this->server) {
|
||||||
$server = Server::where('ip', 'host.docker.internal')->first();
|
return $this->delete();
|
||||||
if (!$server) {
|
}
|
||||||
return;
|
|
||||||
|
$this->latest_version = get_latest_version_of_coolify();
|
||||||
|
$this->current_version = config('version');
|
||||||
|
if (!$this->force) {
|
||||||
|
try {
|
||||||
|
$this->check_if_update_available();
|
||||||
|
} catch (\Exception $e) {
|
||||||
|
Log::error($e->getMessage());
|
||||||
|
return $this->delete();
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
private function check_if_update_available()
|
||||||
|
{
|
||||||
|
if ($this->latest_version === $this->current_version) {
|
||||||
|
throw new \Exception("Already on latest version");
|
||||||
|
}
|
||||||
|
if (version_compare($this->latest_version, $this->current_version, '<')) {
|
||||||
|
throw new \Exception("Already on latest version");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
public function handle(): void
|
||||||
|
{
|
||||||
|
try {
|
||||||
|
if (config('app.env') === 'local') {
|
||||||
|
instant_remote_process([
|
||||||
|
"sleep 2"
|
||||||
|
], $this->server);
|
||||||
|
remote_process([
|
||||||
|
"sleep 10"
|
||||||
|
], $this->server);
|
||||||
|
} else {
|
||||||
|
$cdn = "https://coolify-cdn.b-cdn.net/files";
|
||||||
|
instant_remote_process([
|
||||||
|
"curl -fsSL $cdn/docker-compose.yml -o /data/coolify/source/docker-compose.yml",
|
||||||
|
"curl -fsSL $cdn/docker-compose.prod.yml -o /data/coolify/source/docker-compose.prod.yml",
|
||||||
|
"curl -fsSL $cdn/.env.production -o /data/coolify/source/.env.production",
|
||||||
|
"curl -fsSL $cdn/upgrade.sh -o /data/coolify/source/upgrade.sh",
|
||||||
|
], $this->server);
|
||||||
|
|
||||||
instant_remote_process([
|
instant_remote_process([
|
||||||
"curl -fsSL $cdn/docker-compose.yml -o /data/coolify/source/docker-compose.yml",
|
"docker compose -f /data/coolify/source/docker-compose.yml -f /data/coolify/source/docker-compose.prod.yml pull",
|
||||||
"curl -fsSL $cdn/docker-compose.prod.yml -o /data/coolify/source/docker-compose.prod.yml",
|
], $this->server);
|
||||||
"curl -fsSL $cdn/.env.production -o /data/coolify/source/.env.production",
|
|
||||||
"curl -fsSL $cdn/upgrade.sh -o /data/coolify/source/upgrade.sh",
|
|
||||||
], $server);
|
|
||||||
|
|
||||||
instant_remote_process([
|
remote_process([
|
||||||
"docker compose -f /data/coolify/source/docker-compose.yml -f /data/coolify/source/docker-compose.prod.yml pull",
|
"bash /data/coolify/source/upgrade.sh $this->latest_version"
|
||||||
], $server);
|
], $this->server, ActivityTypes::INLINE->value);
|
||||||
|
}
|
||||||
remote_process([
|
} catch (\Exception $e) {
|
||||||
"bash /data/coolify/source/upgrade.sh $latest_version"
|
Log::error($e->getMessage());
|
||||||
], $server, ActivityTypes::INLINE->value);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -2,6 +2,7 @@
|
|||||||
|
|
||||||
use App\Actions\CoolifyTask\PrepareCoolifyTask;
|
use App\Actions\CoolifyTask\PrepareCoolifyTask;
|
||||||
use App\Data\CoolifyTaskArgs;
|
use App\Data\CoolifyTaskArgs;
|
||||||
|
use App\Enums\ActivityTypes;
|
||||||
use App\Models\Server;
|
use App\Models\Server;
|
||||||
use Illuminate\Database\Eloquent\Model;
|
use Illuminate\Database\Eloquent\Model;
|
||||||
use Illuminate\Support\Facades\Process;
|
use Illuminate\Support\Facades\Process;
|
||||||
@ -16,7 +17,7 @@ use Spatie\Activitylog\Models\Activity;
|
|||||||
function remote_process(
|
function remote_process(
|
||||||
array $command,
|
array $command,
|
||||||
Server $server,
|
Server $server,
|
||||||
string $type,
|
string $type = ActivityTypes::INLINE->value,
|
||||||
?string $type_uuid = null,
|
?string $type_uuid = null,
|
||||||
?Model $model = null,
|
?Model $model = null,
|
||||||
): Activity {
|
): Activity {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user