diff --git a/app/Http/Livewire/DemoDeployApplication.php b/app/Http/Livewire/DemoDeployApplication.php index 7b7308dd2..f038a72cb 100644 --- a/app/Http/Livewire/DemoDeployApplication.php +++ b/app/Http/Livewire/DemoDeployApplication.php @@ -19,11 +19,19 @@ class DemoDeployApplication extends Component public Application $application; public $destination; + public string $deployment_id; + public string $workdir; + public CoolifyInstanceSettings $coolify_instance_settings; public $wildcard_domain; + protected $command; + private function dockerPreCommand($command) + { + return $this->command[] = "docker exec {$this->deployment_id} sh -c '{$command}'"; + } public function deploy() { $this->isKeepAliveOn = true; @@ -36,22 +44,24 @@ public function deploy() $this->wildcard_domain = $project_wildcard_domain ?? $global_wildcard_domain ?? null; $source = $this->application->source->getMorphClass()::where('id', $this->application->source->id)->first(); - $deployment_id = new Cuid2(10); + $this->deployment_id = new Cuid2(10); - $workdir = $this->get_workdir('application', $this->application->uuid, $deployment_id); + $this->workdir = "/tmp/{$this->deployment_id}"; - $command[] = "echo 'Starting deployment of {$this->application->name} ({$this->application->uuid})'"; - $command[] = 'mkdirs -p ' . $workdir; - $command[] = "git clone -b {$this->application->git_branch} {$source->html_url}/{$this->application->git_repository}.git {$workdir}"; + $this->command[] = "echo 'Starting deployment of {$this->application->name} ({$this->application->uuid})'"; + $this->command[] = "docker run -d --name {$this->deployment_id} --rm -v /var/run/docker.sock:/var/run/docker.sock coolify-builder >/dev/null"; - if (!file_exists($workdir) && $workdir != "/") { - $command[] = "echo 'Removing {$workdir}'"; - $command[] = "rm -rf {$workdir}"; - } - $this->activity = remoteProcess(implode("\n", $command), $this->destination->server->name); + $this->dockerPreCommand('hostname'); + $this->dockerPreCommand("mkdir -p {$this->workdir}"); + $this->dockerPreCommand("ls -ld {$this->workdir}"); + $this->dockerPreCommand("git clone -b {$this->application->git_branch} {$source->html_url}/{$this->application->git_repository}.git {$this->workdir}"); + $this->dockerPreCommand("ls -l {$this->workdir}"); + $this->command[] = "docker stop -t 0 {$this->deployment_id} >/dev/null"; + + $this->activity = remoteProcess(implode("\n", $this->command), $this->destination->server->name); Deployment::create([ - 'uuid' => $deployment_id, + 'uuid' => $this->deployment_id, 'type_id' => $this->application->id, 'type_type' => Application::class, 'activity_log_id' => $this->activity->id, diff --git a/bootstrap/helpers.php b/bootstrap/helpers.php index cf84362d4..67c650b54 100644 --- a/bootstrap/helpers.php +++ b/bootstrap/helpers.php @@ -22,7 +22,6 @@ function remoteProcess( $temp_file = 'id.rsa_' . 'root' . '@' . $found_server->ip; Storage::disk('local')->put($temp_file, $found_server->privateKey->private_key, 'private'); $private_key_location = '/var/www/html/storage/app/' . $temp_file; - return resolve(DispatchRemoteProcess::class, [ 'remoteProcessArgs' => new RemoteProcessArgs( destination: $found_server->ip, diff --git a/database/seeders/ServerSeeder.php b/database/seeders/ServerSeeder.php index f40912b64..1a6514139 100644 --- a/database/seeders/ServerSeeder.php +++ b/database/seeders/ServerSeeder.php @@ -37,7 +37,7 @@ public function run(): void 'id' => 3, 'name' => "localhost", 'description' => "This is the local machine", - 'user' => 'ab', + 'user' => 'andrasbacsai', 'ip' => "172.17.0.1", 'team_id' => $root_team->id, 'private_key_id' => $private_key_1->id, diff --git a/docker/builder/Dockerfile b/docker/builder/Dockerfile new file mode 100644 index 000000000..16aa2a965 --- /dev/null +++ b/docker/builder/Dockerfile @@ -0,0 +1,25 @@ +FROM alpine:3.17 + +ARG TARGETPLATFORM +# https://download.docker.com/linux/static/stable/ +ARG DOCKER_VERSION=20.10.18 +# https://github.com/docker/compose/releases +# Reverted to 2.6.1 because of this https://github.com/docker/compose/issues/9704. 2.9.0 still has a bug. +ARG DOCKER_COMPOSE_VERSION=2.6.1 +# https://github.com/buildpacks/pack/releases +ARG PACK_VERSION=0.27.0 +# https://github.com/railwayapp/nixpacks/releases +ARG NIXPACKS_VERSION=1.6.0 + +USER root +RUN apk add --no-cache bash curl git git-lfs openssh-client tar tini +RUN mkdir -p ~/.docker/cli-plugins +RUN curl -SL https://cdn.coollabs.io/bin/$TARGETPLATFORM/docker-$DOCKER_VERSION -o /usr/bin/docker +RUN curl -SL https://cdn.coollabs.io/bin/$TARGETPLATFORM/docker-compose-linux-$DOCKER_COMPOSE_VERSION -o ~/.docker/cli-plugins/docker-compose +RUN curl -SL https://cdn.coollabs.io/bin/$TARGETPLATFORM/pack-v$PACK_VERSION -o /usr/local/bin/pack +RUN curl -sSL https://nixpacks.com/install.sh | bash +RUN chmod +x ~/.docker/cli-plugins/docker-compose /usr/bin/docker /usr/local/bin/pack + +ENTRYPOINT ["/sbin/tini", "--"] +CMD ["sh", "-c", "while true; do sleep 1000; done"] + diff --git a/resources/views/livewire/demo-deploy-application.blade.php b/resources/views/livewire/demo-deploy-application.blade.php index 18f781620..628c5de78 100644 --- a/resources/views/livewire/demo-deploy-application.blade.php +++ b/resources/views/livewire/demo-deploy-application.blade.php @@ -4,10 +4,6 @@ Activity: {{ $activity?->id ?? 'waiting' }}
{{ data_get($activity, 'description') }}
- {{--
-
Details:
-
{{ json_encode(data_get($activity, 'properties'), JSON_PRETTY_PRINT) }}
-
--}} @endisset