Merge remote-tracking branch 'origin/v4-next' into patricio-deploy-proxy

This commit is contained in:
Joao Patricio 2023-05-03 09:32:09 +01:00
commit 7c13a92d9a
13 changed files with 64 additions and 42 deletions

View File

@ -37,6 +37,7 @@ public function handle()
$compose_file = "docker-compose.yml";
$compose_file_prod = "docker-compose.prod.yml";
$upgrade_script = "upgrade.sh";
$docker_install_script = "install-docker.sh";
$production_env = ".env.production";
PendingRequest::macro('storage', function ($file) {
@ -53,8 +54,9 @@ public function handle()
Http::pool(fn (Pool $pool) => [
$pool->storage(file: "$parent_dir/$compose_file")->put("/$bunny_cdn_storage_name/$bunny_cdn_path/$compose_file"),
$pool->storage(file: "$parent_dir/$compose_file_prod")->put("/$bunny_cdn_storage_name/$bunny_cdn_path/$compose_file_prod"),
$pool->storage(file: "$parent_dir/scripts/$upgrade_script")->put("/$bunny_cdn_storage_name/$bunny_cdn_path/$upgrade_script"),
$pool->storage(file: "$parent_dir/$production_env")->put("/$bunny_cdn_storage_name/$bunny_cdn_path/$production_env"),
$pool->storage(file: "$parent_dir/scripts/$upgrade_script")->put("/$bunny_cdn_storage_name/$bunny_cdn_path/$upgrade_script"),
$pool->storage(file: "$parent_dir/scripts/$docker_install_script")->put("/$bunny_cdn_storage_name/$bunny_cdn_path/$docker_install_script"),
]);
$res = Http::withHeaders([
@ -64,13 +66,15 @@ public function handle()
"url" => "$bunny_cdn/$bunny_cdn_path/$compose_file",
"url" => "$bunny_cdn/$bunny_cdn_path/$compose_file_prod",
"url" => "$bunny_cdn/$bunny_cdn_path/$upgrade_script",
"url" => "$bunny_cdn/$bunny_cdn_path/$production_env"
"url" => "$bunny_cdn/$bunny_cdn_path/$production_env",
"url" => "$bunny_cdn/$bunny_cdn_path/$docker_install_script"
]);
if ($res->ok()) {
echo "All files uploaded & purged...\n";
return;
}
throw new \Exception("Something went wrong.");
} catch (\Exception $e) {
echo "Something went wrong.\n";
echo $e->getMessage();
}
}

View File

@ -45,7 +45,7 @@ public function submit()
$server = Server::find($this->server_id);
instantRemoteProcess($server, ['docker network create --attachable ' . $this->network], throwError: false);
instantRemoteProcess(['docker network create --attachable ' . $this->network], $server, throwError: false);
return redirect()->route('destination.show', $docker->uuid);
}
}

View File

@ -10,15 +10,14 @@ class ForceUpgrade extends Component
{
public function upgrade()
{
//if (env('APP_ENV') === 'local') {
if (config('app.env') === 'local') {
$server = Server::where('ip', 'coolify-testing-host')->first();
if (!$server) {
return;
}
instantRemoteProcess($server, [
instantRemoteProcess([
"sleep 2"
]);
], $server);
remoteProcess([
"sleep 10"
], $server, ActivityTypes::INLINE->value);
@ -32,15 +31,16 @@ public function upgrade()
return;
}
instantRemoteProcess($server, [
instantRemoteProcess([
"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",
]);
instantRemoteProcess($server, [
], $server);
instantRemoteProcess([
"docker compose -f /data/coolify/source/docker-compose.yml -f /data/coolify/source/docker-compose.prod.yml pull",
]);
], $server);
remoteProcess([
"bash /data/coolify/source/upgrade.sh $latestVersion"

View File

@ -73,7 +73,7 @@ public function delete()
}
public function stop()
{
instantRemoteProcess($this->destination->server, ["docker rm -f {$this->application->uuid}"]);
instantRemoteProcess(["docker rm -f {$this->application->uuid}"], $this->destination->server);
if ($this->application->status != 'exited') {
$this->application->status = 'exited';
$this->application->save();

View File

@ -2,6 +2,7 @@
namespace App\Http\Livewire\Server;
use App\Enums\ActivityTypes;
use App\Models\Server;
use Illuminate\Support\Facades\Validator;
use Livewire\Component;
@ -28,15 +29,30 @@ public function mount()
public function installDocker()
{
$config = base64_encode('{ "live-restore": true }');
instantRemoteProcess($this->server, [
"curl https://releases.rancher.com/install-docker/23.0.sh | sh"
]);
remoteProcess([
"curl https://releases.rancher.com/install-docker/23.0.sh | sh",
"echo '{$config}' | base64 -d > /etc/docker/daemon.json",
"systemctl restart docker"
], $this->server, ActivityTypes::INLINE->value);
}
public function checkServer()
{
$this->uptime = instantRemoteProcess($this->server, ['uptime']);
$this->dockerVersion = instantRemoteProcess($this->server, ['docker version|head -2|grep -i version'], false);
$this->dockerComposeVersion = instantRemoteProcess($this->server, ['docker compose version|head -2|grep -i version'], false);
try {
$this->uptime = instantRemoteProcess(['uptime'], $this->server, false);
if (!$this->uptime) {
$this->uptime = 'Server not reachable.';
throw new \Exception('Server not reachable.');
}
$this->dockerVersion = instantRemoteProcess(['docker version|head -2|grep -i version'], $this->server, false);
if (!$this->dockerVersion) {
$this->dockerVersion = 'Not installed.';
}
$this->dockerComposeVersion = instantRemoteProcess(['docker compose version|head -2|grep -i version'], $this->server, false);
if (!$this->dockerComposeVersion) {
$this->dockerComposeVersion = 'Not installed.';
}
} catch (\Exception $e) {
}
}
public function submit()
{

View File

@ -38,7 +38,7 @@ protected function checkAllServers()
$not_found_applications = $applications;
$containers = collect();
foreach ($servers as $server) {
$output = instantRemoteProcess($server, ['docker ps -a -q --format \'{{json .}}\'']);
$output = instantRemoteProcess(['docker ps -a -q --format \'{{json .}}\''], $server);
$containers = $containers->concat(formatDockerCmdOutputToJson($output));
}
foreach ($containers as $container) {
@ -67,7 +67,7 @@ protected function checkContainerStatus()
return;
}
if ($application->destination->server) {
$container = instantRemoteProcess($application->destination->server, ["docker inspect --format '{{json .State}}' {$this->container_id}"]);
$container = instantRemoteProcess(["docker inspect --format '{{json .State}}' {$this->container_id}"], $application->destination->server);
$container = formatDockerCmdOutputToJson($container);
$application->status = $container[0]['Status'];
$application->save();

View File

@ -31,7 +31,7 @@ public function handle(): void
try {
$servers = Server::all();
foreach ($servers as $server) {
instantRemoteProcess($server, ['docker image prune -f']);
instantRemoteProcess(['docker image prune -f'], $server);
}
} catch (\Exception $e) {
Log::error($e->getMessage());

View File

@ -7,6 +7,7 @@
use Illuminate\Support\Facades\Process;
use Illuminate\Support\Facades\Queue;
use Illuminate\Support\ServiceProvider;
use Illuminate\Support\Str;
class AppServiceProvider extends ServiceProvider
{
@ -15,14 +16,9 @@ class AppServiceProvider extends ServiceProvider
*/
public function register(): void
{
// @TODO: Is this the best place to run the seeder?
// if (env('APP_ENV') === 'production') {
// dump('Seed default data.');
// Process::run('php artisan db:seed --class=ProductionSeeder --force');
// } else {
// dump('Not in production environment.');
// }
//
if (config('app.env') === 'production' && Str::contains(config('coolify.version'), ['nightly'])) {
Process::run('php artisan migrate:fresh --force --seed --seeder=ProductionSeeder');
}
}
/**
@ -31,9 +27,8 @@ public function register(): void
public function boot(): void
{
Queue::after(function (JobProcessed $event) {
// @TODO: Remove `coolify-builder` container after the remoteProcess job is finishged and remoteProcess->type == `deployment`.
// @TODO: Remove `coolify-builder` container after the remoteProcess job is finishged and remoteProcess->type == `deployment`.
if ($event->job->resolveName() === CoolifyTask::class) {
}
});
}

View File

@ -120,7 +120,7 @@ function formatDockerLabelsToJson($rawOutput): Collection
}
}
if (!function_exists('instantRemoteProcess')) {
function instantRemoteProcess(Server $server, array $command, $throwError = true)
function instantRemoteProcess(array $command, Server $server, $throwError = true)
{
$command_string = implode("\n", $command);
$private_key_location = savePrivateKeyForServer($server);

View File

@ -22,14 +22,17 @@
Submit
</button>
<button wire:click.prevent='checkServer'>Check Server</button>
<button wire:click.prevent='installDocker'>Install Docker</button>
{{-- <button wire:click.prevent='installDocker'>Install Docker</button> --}}
</div>
</form>
@isset($uptime)
<p>Connection OK</p>
<p>Uptime: {{ $uptime }}</p>
<p>{{ $dockerVersion }}</p>
<p>{{ $dockerComposeVersion }}</p>
@endisset
@isset($dockerVersion)
<p>Docker Engine: {{ $dockerVersion }}</p>
@endisset
@isset($dockerComposeVersion)
<p>Docker Compose: {{ $dockerComposeVersion }}</p>
@endisset
</div>

View File

@ -0,0 +1,5 @@
#!/bin/bash
curl https://releases.rancher.com/install-docker/23.0.sh | sh
echo "Docker installed successfully"
echo '{ "live-restore": true }' >/etc/docker/daemon.json
systemctl restart docker

View File

@ -2,10 +2,12 @@
## Do not modify this file. You will lost the ability to installation and autoupdate!
###########
## Always run "php artisan app:sync-to-bunny-cdn --env=secrets" if you update this file.
## Always run "php artisan app:sync-to-bunny-cdn --env=secrets" or "scripts/run sync-bunny" if you update this file.
###########
VERSION="1.0.0"
DOCKER_VERSION="23.0"
CDN="https://coolify-cdn.b-cdn.net/files"
OS_TYPE=$(cat /etc/os-release | grep -w "ID" | cut -d "=" -f 2 | tr -d '"')
OS_VERSION=$(cat /etc/os-release | grep -w "VERSION_ID" | cut -d "=" -f 2 | tr -d '"')
@ -18,9 +20,7 @@ fi
if ! [ -x "$(command -v docker)" ]; then
echo "Docker is not installed. Installing Docker..."
curl -fsSL https://get.docker.com -o get-docker.sh
sh get-docker.sh
rm get-docker.sh
curl https://releases.rancher.com/install-docker/${DOCKER_VERSION}.sh | sh
echo "Docker installed successfully"
fi

View File

@ -21,8 +21,7 @@ function help {
compgen -A function | cat -n
}
function sync-bunny {
bash vendor/bin/spin exec -u webuser coolify php artisan sync:bunny --env=secret ||
php artisan sync:bunny --env=secrets
php artisan sync:bunny --env=secrets
}
function queue {
bash vendor/bin/spin exec -u webuser coolify php artisan queue:listen