wip: non-root
This commit is contained in:
		
							parent
							
								
									a04c7831b1
								
							
						
					
					
						commit
						41f4b36593
					
				| @ -16,18 +16,10 @@ class CheckConfiguration | |||||||
|             return 'OK'; |             return 'OK'; | ||||||
|         } |         } | ||||||
|         $proxy_path = $server->proxyPath(); |         $proxy_path = $server->proxyPath(); | ||||||
|         if ($server->isNonRoot()) { |         $payload = [ | ||||||
|             $payload = [ |             "mkdir -p $proxy_path", | ||||||
|                 "mkdir -p $proxy_path", |             "cat $proxy_path/docker-compose.yml", | ||||||
|                 "chown -R $server->user:$server->user $proxy_path", |         ]; | ||||||
|                 "cat $proxy_path/docker-compose.yml", |  | ||||||
|             ]; |  | ||||||
|         } else { |  | ||||||
|             $payload = [ |  | ||||||
|                 "mkdir -p $proxy_path", |  | ||||||
|                 "cat $proxy_path/docker-compose.yml", |  | ||||||
|             ]; |  | ||||||
|         } |  | ||||||
|         $proxy_configuration = instant_remote_process($payload, $server, false); |         $proxy_configuration = instant_remote_process($payload, $server, false); | ||||||
| 
 | 
 | ||||||
|         if ($reset || !$proxy_configuration || is_null($proxy_configuration)) { |         if ($reset || !$proxy_configuration || is_null($proxy_configuration)) { | ||||||
|  | |||||||
| @ -30,16 +30,18 @@ class StartProxy | |||||||
|             $server->save(); |             $server->save(); | ||||||
|             if ($server->isSwarm()) { |             if ($server->isSwarm()) { | ||||||
|                 $commands = $commands->merge([ |                 $commands = $commands->merge([ | ||||||
|                     "mkdir -p $proxy_path/dynamic && cd $proxy_path", |                     "mkdir -p $proxy_path/dynamic", | ||||||
|  |                     "cd $proxy_path", | ||||||
|                     "echo 'Creating required Docker Compose file.'", |                     "echo 'Creating required Docker Compose file.'", | ||||||
|                     "echo 'Starting coolify-proxy.'", |                     "echo 'Starting coolify-proxy.'", | ||||||
|                     "cd $proxy_path && docker stack deploy -c docker-compose.yml coolify-proxy", |                     "docker stack deploy -c docker-compose.yml coolify-proxy", | ||||||
|                     "echo 'Proxy started successfully.'" |                     "echo 'Proxy started successfully.'" | ||||||
|                 ]); |                 ]); | ||||||
|             } else { |             } else { | ||||||
|                 $caddfile = "import /dynamic/*.caddy"; |                 $caddfile = "import /dynamic/*.caddy"; | ||||||
|                 $commands = $commands->merge([ |                 $commands = $commands->merge([ | ||||||
|                     "mkdir -p $proxy_path/dynamic && cd $proxy_path", |                     "mkdir -p $proxy_path/dynamic", | ||||||
|  |                     "cd $proxy_path", | ||||||
|                     "echo '$caddfile' > $proxy_path/dynamic/Caddyfile", |                     "echo '$caddfile' > $proxy_path/dynamic/Caddyfile", | ||||||
|                     "echo 'Creating required Docker Compose file.'", |                     "echo 'Creating required Docker Compose file.'", | ||||||
|                     "echo 'Pulling docker image.'", |                     "echo 'Pulling docker image.'", | ||||||
|  | |||||||
| @ -29,7 +29,8 @@ class ConfigureCloudflared | |||||||
|             $config = Yaml::dump($config, 12, 2); |             $config = Yaml::dump($config, 12, 2); | ||||||
|             $docker_compose_yml_base64 = base64_encode($config); |             $docker_compose_yml_base64 = base64_encode($config); | ||||||
|             $commands = collect([ |             $commands = collect([ | ||||||
|                 "mkdir -p /tmp/cloudflared && cd /tmp/cloudflared", |                 "mkdir -p /tmp/cloudflared", | ||||||
|  |                 "cd /tmp/cloudflared", | ||||||
|                 "echo '$docker_compose_yml_base64' | base64 -d > docker-compose.yml", |                 "echo '$docker_compose_yml_base64' | base64 -d > docker-compose.yml", | ||||||
|                 "docker compose pull", |                 "docker compose pull", | ||||||
|                 "docker compose down -v --remove-orphans > /dev/null 2>&1", |                 "docker compose down -v --remove-orphans > /dev/null 2>&1", | ||||||
|  | |||||||
| @ -23,7 +23,8 @@ class Deploy extends Component | |||||||
|             'proxyStatusUpdated', |             'proxyStatusUpdated', | ||||||
|             'traefikDashboardAvailable', |             'traefikDashboardAvailable', | ||||||
|             'serverRefresh' => 'proxyStatusUpdated', |             'serverRefresh' => 'proxyStatusUpdated', | ||||||
|             "checkProxy", "startProxy" |             "checkProxy", | ||||||
|  |             "startProxy" | ||||||
|         ]; |         ]; | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|  | |||||||
| @ -33,32 +33,8 @@ function remote_process( | |||||||
|         $command = $command->toArray(); |         $command = $command->toArray(); | ||||||
|     } |     } | ||||||
|     if ($server->isNonRoot()) { |     if ($server->isNonRoot()) { | ||||||
|         $command = collect($command)->map(function ($line) { |         $command = parseCommandsByLineForSudo(collect($command), $server); | ||||||
|             if (!str($line)->startSwith('cd')) { |  | ||||||
|                 return "sudo $line"; |  | ||||||
|             } |  | ||||||
|             return $line; |  | ||||||
|         })->toArray(); |  | ||||||
|         $command = collect($command)->map(function ($line) use ($server) { |  | ||||||
|             if (Str::startsWith($line, 'sudo mkdir -p')) { |  | ||||||
|                 return "$line && sudo chown -R $server->user:$server->user " . Str::after($line, 'sudo mkdir -p') . ' && sudo chmod -R o-rwx ' . Str::after($line, 'sudo mkdir -p'); |  | ||||||
|             } |  | ||||||
|             return $line; |  | ||||||
|         })->toArray(); |  | ||||||
|         $command = collect($command)->map(function ($line) { |  | ||||||
|             if (str($line)->contains('$(') || str($line)->contains('`')) { |  | ||||||
|                 return str($line)->replace('$(', '$(sudo ')->replace('`', '`sudo ')->value(); |  | ||||||
|             } |  | ||||||
|             if (str($line)->contains('||')) { |  | ||||||
|                 return str($line)->replace('||', '|| sudo ')->value(); |  | ||||||
|             } |  | ||||||
|             if (str($line)->contains('&&')) { |  | ||||||
|                 return str($line)->replace('&&', '&& sudo ')->value(); |  | ||||||
|             } |  | ||||||
|             return $line; |  | ||||||
|         })->toArray(); |  | ||||||
|     } |     } | ||||||
|     ray($command); |  | ||||||
|     $command_string = implode("\n", $command); |     $command_string = implode("\n", $command); | ||||||
|     if (auth()->user()) { |     if (auth()->user()) { | ||||||
|         $teams = auth()->user()->teams->pluck('id'); |         $teams = auth()->user()->teams->pluck('id'); | ||||||
| @ -195,30 +171,7 @@ function instant_remote_process(Collection|array $command, Server $server, bool | |||||||
|         $command = $command->toArray(); |         $command = $command->toArray(); | ||||||
|     } |     } | ||||||
|     if ($server->isNonRoot() && !$no_sudo) { |     if ($server->isNonRoot() && !$no_sudo) { | ||||||
|         $command = collect($command)->map(function ($line) { |         $command = parseCommandsByLineForSudo(collect($command), $server); | ||||||
|             if (!str($line)->startSwith('cd')) { |  | ||||||
|                 return "sudo $line"; |  | ||||||
|             } |  | ||||||
|             return $line; |  | ||||||
|         })->toArray(); |  | ||||||
|         $command = collect($command)->map(function ($line) use ($server) { |  | ||||||
|             if (Str::startsWith($line, 'sudo mkdir -p')) { |  | ||||||
|                 return "$line && sudo chown -R $server->user:$server->user " . Str::after($line, 'sudo mkdir -p') . ' && sudo chmod -R o-rwx ' . Str::after($line, 'sudo mkdir -p'); |  | ||||||
|             } |  | ||||||
|             return $line; |  | ||||||
|         })->toArray(); |  | ||||||
|         $command = collect($command)->map(function ($line) { |  | ||||||
|             if (str($line)->contains('$(') || str($line)->contains('`')) { |  | ||||||
|                 return str($line)->replace('$(', '$(sudo ')->replace('`', '`sudo ')->value(); |  | ||||||
|             } |  | ||||||
|             if (str($line)->contains('||')) { |  | ||||||
|                 return str($line)->replace('||', '|| sudo ')->value(); |  | ||||||
|             } |  | ||||||
|             if (str($line)->contains('&&')) { |  | ||||||
|                 return str($line)->replace('&&', '&& sudo ')->value(); |  | ||||||
|             } |  | ||||||
|             return $line; |  | ||||||
|         })->toArray(); |  | ||||||
|     } |     } | ||||||
|     $command_string = implode("\n", $command); |     $command_string = implode("\n", $command); | ||||||
|     $ssh_command = generateSshCommand($server, $command_string, $no_sudo); |     $ssh_command = generateSshCommand($server, $command_string, $no_sudo); | ||||||
|  | |||||||
| @ -34,7 +34,7 @@ function getFilesystemVolumesFromServer(ServiceApplication|ServiceDatabase|Appli | |||||||
|         $fileVolumes = $oneService->fileStorages()->get(); |         $fileVolumes = $oneService->fileStorages()->get(); | ||||||
|         $commands = collect([ |         $commands = collect([ | ||||||
|             "mkdir -p $workdir > /dev/null 2>&1 || true", |             "mkdir -p $workdir > /dev/null 2>&1 || true", | ||||||
|             "cd " |             "cd $workdir" | ||||||
|         ]); |         ]); | ||||||
|         instant_remote_process($commands, $server); |         instant_remote_process($commands, $server); | ||||||
|         foreach ($fileVolumes as $fileVolume) { |         foreach ($fileVolumes as $fileVolume) { | ||||||
|  | |||||||
| @ -29,6 +29,7 @@ use DanHarrin\LivewireRateLimiting\Exceptions\TooManyRequestsException; | |||||||
| use Illuminate\Database\UniqueConstraintViolationException; | use Illuminate\Database\UniqueConstraintViolationException; | ||||||
| use Illuminate\Mail\Message; | use Illuminate\Mail\Message; | ||||||
| use Illuminate\Notifications\Messages\MailMessage; | use Illuminate\Notifications\Messages\MailMessage; | ||||||
|  | use Illuminate\Support\Collection; | ||||||
| use Illuminate\Support\Facades\Cache; | use Illuminate\Support\Facades\Cache; | ||||||
| use Illuminate\Support\Facades\File; | use Illuminate\Support\Facades\File; | ||||||
| use Illuminate\Support\Facades\Http; | use Illuminate\Support\Facades\Http; | ||||||
| @ -1949,3 +1950,32 @@ function check_domain_usage(ServiceApplication|Application|null $resource = null | |||||||
|         } |         } | ||||||
|     } |     } | ||||||
| } | } | ||||||
|  | 
 | ||||||
|  | function parseCommandsByLineForSudo(Collection $commands, Server $server): array { | ||||||
|  |     $commands = $commands->map(function ($line) { | ||||||
|  |         if (!str($line)->startSwith('cd') && !str($line)->startSwith('command')) { | ||||||
|  |             return "sudo $line"; | ||||||
|  |         } | ||||||
|  |         return $line; | ||||||
|  |     }); | ||||||
|  |     $commands = $commands->map(function ($line) use ($server) { | ||||||
|  |         if (Str::startsWith($line, 'sudo mkdir -p')) { | ||||||
|  |             return "$line && sudo chown -R $server->user:$server->user " . Str::after($line, 'sudo mkdir -p') . ' && sudo chmod -R o-rwx ' . Str::after($line, 'sudo mkdir -p'); | ||||||
|  |         } | ||||||
|  |         return $line; | ||||||
|  |     }); | ||||||
|  |     $commands = $commands->map(function ($line) { | ||||||
|  |         if (str($line)->contains('$(') || str($line)->contains('`')) { | ||||||
|  |             return str($line)->replace('$(', '$(sudo ')->replace('`', '`sudo ')->value(); | ||||||
|  |         } | ||||||
|  |         if (str($line)->contains('||')) { | ||||||
|  |             return str($line)->replace('||', '|| sudo ')->value(); | ||||||
|  |         } | ||||||
|  |         if (str($line)->contains('&&')) { | ||||||
|  |             return str($line)->replace('&&', '&& sudo ')->value(); | ||||||
|  |         } | ||||||
|  |         return $line; | ||||||
|  |     }); | ||||||
|  | 
 | ||||||
|  |     return $commands->toArray(); | ||||||
|  | } | ||||||
|  | |||||||
| @ -10,7 +10,9 @@ | |||||||
|             <div class="flex gap-2"> |             <div class="flex gap-2"> | ||||||
|                 <x-forms.input id="ip" label="IP Address/Domain" required |                 <x-forms.input id="ip" label="IP Address/Domain" required | ||||||
|                     helper="An IP Address (127.0.0.1) or domain (example.com)." /> |                     helper="An IP Address (127.0.0.1) or domain (example.com)." /> | ||||||
|                 {{-- <x-forms.input id="user" label="User" required /> --}} |                 @if (isDev()) | ||||||
|  |                     <x-forms.input id="user" label="User" required /> | ||||||
|  |                 @endif | ||||||
|                 <x-forms.input type="number" id="port" label="Port" required /> |                 <x-forms.input type="number" id="port" label="Port" required /> | ||||||
|             </div> |             </div> | ||||||
|             <x-forms.select label="Private Key" id="private_key_id"> |             <x-forms.select label="Private Key" id="private_key_id"> | ||||||
| @ -29,8 +31,7 @@ | |||||||
|             <div class=""> |             <div class=""> | ||||||
|                 <h3 class="pt-6">Swarm <span class="text-xs text-neutral-500">(experimental)</span></h3> |                 <h3 class="pt-6">Swarm <span class="text-xs text-neutral-500">(experimental)</span></h3> | ||||||
|                 <div class="pb-4">Read the docs <a class='dark:text-white' |                 <div class="pb-4">Read the docs <a class='dark:text-white' | ||||||
|                         href='https://coolify.io/docs/knowledge-base/docker/swarm' |                         href='https://coolify.io/docs/knowledge-base/docker/swarm' target='_blank'>here</a>.</div> | ||||||
|                         target='_blank'>here</a>.</div> |  | ||||||
|                 @if ($is_swarm_worker || $is_build_server) |                 @if ($is_swarm_worker || $is_build_server) | ||||||
|                     <x-forms.checkbox disabled instantSave type="checkbox" id="is_swarm_manager" |                     <x-forms.checkbox disabled instantSave type="checkbox" id="is_swarm_manager" | ||||||
|                         helper="For more information, please read the documentation <a class='dark:text-white' href='https://coolify.io/docs/knowledge-base/docker/swarm' target='_blank'>here</a>." |                         helper="For more information, please read the documentation <a class='dark:text-white' href='https://coolify.io/docs/knowledge-base/docker/swarm' target='_blank'>here</a>." | ||||||
| @ -40,7 +41,7 @@ | |||||||
|                         helper="For more information, please read the documentation <a class='dark:text-white' href='https://coolify.io/docs/knowledge-base/docker/swarm' target='_blank'>here</a>." |                         helper="For more information, please read the documentation <a class='dark:text-white' href='https://coolify.io/docs/knowledge-base/docker/swarm' target='_blank'>here</a>." | ||||||
|                         label="Is it a Swarm Manager?" /> |                         label="Is it a Swarm Manager?" /> | ||||||
|                 @endif |                 @endif | ||||||
|                 @if ($is_swarm_manager|| $is_build_server) |                 @if ($is_swarm_manager || $is_build_server) | ||||||
|                     <x-forms.checkbox disabled instantSave type="checkbox" id="is_swarm_worker" |                     <x-forms.checkbox disabled instantSave type="checkbox" id="is_swarm_worker" | ||||||
|                         helper="For more information, please read the documentation <a class='dark:text-white' href='https://coolify.io/docs/knowledge-base/docker/swarm' target='_blank'>here</a>." |                         helper="For more information, please read the documentation <a class='dark:text-white' href='https://coolify.io/docs/knowledge-base/docker/swarm' target='_blank'>here</a>." | ||||||
|                         label="Is it a Swarm Worker?" /> |                         label="Is it a Swarm Worker?" /> | ||||||
|  | |||||||
| @ -48,7 +48,7 @@ | |||||||
|                 </x-modal-confirmation> |                 </x-modal-confirmation> | ||||||
|             </div> |             </div> | ||||||
|         @else |         @else | ||||||
|             <button @click="$wire.dispatch('checkProxy')" class="gap-2 button"> |             <button @click="$wire.dispatch('checkProxyEvent')" class="gap-2 button"> | ||||||
|                 <svg xmlns="http://www.w3.org/2000/svg" class="w-5 h-5 dark:text-warning" viewBox="0 0 24 24" |                 <svg xmlns="http://www.w3.org/2000/svg" class="w-5 h-5 dark:text-warning" viewBox="0 0 24 24" | ||||||
|                     stroke-width="1.5" stroke="currentColor" fill="none" stroke-linecap="round" |                     stroke-width="1.5" stroke="currentColor" fill="none" stroke-linecap="round" | ||||||
|                     stroke-linejoin="round"> |                     stroke-linejoin="round"> | ||||||
| @ -61,6 +61,10 @@ | |||||||
|     @endif |     @endif | ||||||
|     @script |     @script | ||||||
|         <script> |         <script> | ||||||
|  |             $wire.$on('checkProxyEvent', () => { | ||||||
|  |                 $wire.$dispatch('info', 'Starting proxy.'); | ||||||
|  |                 $wire.$call('checkProxy'); | ||||||
|  |             }); | ||||||
|             $wire.$on('restartEvent', () => { |             $wire.$on('restartEvent', () => { | ||||||
|                 $wire.$dispatch('info', 'Restarting proxy.'); |                 $wire.$dispatch('info', 'Restarting proxy.'); | ||||||
|                 $wire.$call('restart'); |                 $wire.$call('restart'); | ||||||
|  | |||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user