Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feat: Add Docker Registry and Images functionality #4187

Draft
wants to merge 54 commits into
base: next
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
54 commits
Select commit Hold shift + click to select a range
b57a439
chore: add registry auth to docker image apps
Nov 8, 2024
15653e6
chore: added registry url with default plus fixed functionality
Nov 8, 2024
5a1431c
chore: remove encrypting token since it should be editable and visibl…
Nov 8, 2024
5187324
fix: revert change
Nov 8, 2024
3130b44
fix: revert some more for less confusion
Nov 8, 2024
60d6189
Merge remote-tracking branch 'upstream/next' into docker-image-login
Nov 8, 2024
02d29d9
chore: info tooltip
Nov 8, 2024
ebf2072
chore: encrypt with casts + masking and interpolation + fixes
Nov 9, 2024
9d08eed
chore: small improvement
Nov 10, 2024
3cd185a
chore: changed migrations, created registries, initial progress
Nov 11, 2024
42de7ec
chore: database, navigation images
Nov 11, 2024
1fd8737
fix: navbar link color
Nov 11, 2024
653d0f3
Merge remote-tracking branch 'upstream/next' into docker-image-login
Nov 11, 2024
65eb856
chore: looks and validation
Nov 11, 2024
8787a9b
Merge branch 'next' into docker-image-login
peaklabs-dev Nov 14, 2024
063d420
chore: svg + new validations
Nov 18, 2024
80b5f92
Merge branch 'docker-image-login' of github.com:OSINTRoach/coolify in…
Nov 18, 2024
b7e00ce
Merge remote-tracking branch 'upstream/next' into docker-image-login
Nov 18, 2024
0e2820f
chore: dockerRegistry
Nov 28, 2024
9e1a78e
Merge branch 'next' into docker-image-login
OSINTRoach Nov 28, 2024
4f7631c
chore: Images
Nov 29, 2024
5167bbd
Merge branch 'docker-image-login' of github.com:OSINTRoach/coolify in…
Nov 29, 2024
557cd55
chore: add list docker images
Dec 3, 2024
03bfcfb
Merge branch 'docker-image-login-davidh' into docker-image-login
Dec 3, 2024
e75f704
Merge branch 'next' into docker-image-login
OSINTRoach Dec 3, 2024
0ff0cad
chore: progress select multiple registries
Dec 3, 2024
f1873ef
Merge branch 'docker-image-login' into budaydev
Dec 3, 2024
08d46bc
chore: multi select on dockerimage build
Dec 3, 2024
0308d36
chore: unique
Dec 3, 2024
37f9266
chore: small fix
Dec 3, 2024
8c32dda
Merge pull request #1 from OSINTRoach/budaydev
OSINTRoach Dec 3, 2024
885d852
chore: fillable bug solved
Dec 4, 2024
9e8cbca
Merge branch 'budaydev' into docker-image-login
Dec 4, 2024
40bf9e2
refactor: list docker images
Dec 5, 2024
8cab528
chore: add get_server_dcoker_image_details
Dec 5, 2024
6a16e71
chore: add container count to image details
Dec 5, 2024
20fcd43
chore: add delete_all_dangling_server_docker_images
Dec 5, 2024
80cedee
Merge remote-tracking branch 'origin/docker-image-login-davidh' into …
Dec 5, 2024
d529f8f
Merge branch 'next' into docker-image-login
peaklabs-dev Dec 6, 2024
dab2290
chore: add delete_server_docker_image
Dec 6, 2024
07c545a
chore: images page in progress
Dec 9, 2024
e7ac684
chore: revert
Dec 9, 2024
fad2b04
refactor: delete_server_docker_image
Dec 10, 2024
f8cff8c
refactor: ListServerDockerImages
Dec 11, 2024
0483f98
refactor: GetServerDockerImageDetails
Dec 11, 2024
58357b1
refactor: ListServerDockerImages
Dec 11, 2024
98e1b54
refactor: ListServerDockerImages
Dec 17, 2024
5e2f4de
refactor: ListServerDockerImages
Dec 19, 2024
c3ae14d
chore: red
Dec 19, 2024
710db04
Merge remote-tracking branch 'upstream/next' into docker-image-login
Dec 19, 2024
e67280d
Merge branch 'docker-image-login-davidh' into docker-image-login
Dec 19, 2024
3879c5a
Merge branch 'docker-image-login' into budaydev
Dec 19, 2024
5c2cf9f
chore: list and details progress
Dec 23, 2024
5f45d68
Merge branch 'next' into docker-image-login
peaklabs-dev Dec 23, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions app/Actions/Docker/DeleteServerDockerImages.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<?php

namespace App\Actions\Docker;

use Lorisleiva\Actions\Concerns\AsAction;

class DeleteServerDockerImages
{
use AsAction;

public static function run($server, $ids)
{
$idsForCommand = implode(' ', $ids);
return instant_remote_process(["docker rmi $idsForCommand -f"], $server);
}
}
27 changes: 27 additions & 0 deletions app/Actions/Docker/GetServerDockerImageDetails.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<?php

namespace App\Actions\Docker;

use Lorisleiva\Actions\Concerns\AsAction;

class GetServerDockerImageDetails
{
use AsAction;

public static function run($server, $imageId)
{
$imageDetailsRaw = instant_remote_process(["docker inspect --type=image {$imageId} --format '{{json .}}'"], $server);
$imageDetails = json_decode($imageDetailsRaw, true);

if (json_last_error() !== JSON_ERROR_NONE) {
return ['error' => 'Invalid JSON returned from Docker inspect', 'raw_output' => $imageDetailsRaw];
}

$containerCountRaw = instant_remote_process(["docker ps -q --filter ancestor={$imageId} | wc -l"], $server);
$containerCount = intval(trim($containerCountRaw));

$imageDetails['ContainerCount'] = $containerCount;

return $imageDetails;
}
}
62 changes: 62 additions & 0 deletions app/Actions/Docker/ListServerDockerImages.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
<?php

namespace App\Actions\Docker;

use Illuminate\Database\Eloquent\Collection;
use Lorisleiva\Actions\Concerns\AsAction;

class ListServerDockerImages
{
use AsAction;

public Collection $server;

public static function run($server)
{
$commandForContainers = "curl --unix-socket /var/run/docker.sock http://localhost/containers/json?all=true";
$containers = json_decode(instant_remote_process([$commandForContainers], $server), true);

$runningImages = array();
foreach ($containers as $container) {
$runningImages[$container['ImageID']][] = true;
}

$command = "curl --unix-socket /var/run/docker.sock http://localhost/images/json";
$imagesJson = json_decode(instant_remote_process([$command], $server), true);

$images = [];

foreach ($imagesJson as $image) {
$isRunning = key_exists($image['Id'], $runningImages);

if ($image['RepoTags'] == []){
$imageCopy = $image;

$imageCopy["Status"] = 'unused';
$imageCopy["Dangling"] = true;

array_push($images, $imageCopy);

}else{

foreach ($image['RepoTags'] as $tag) {
$imageCopy = $image;

$imageCopy["RepoTags"] = $tag;

if ($isRunning){
$imageCopy["Status"] = 'in use';
}else{
$imageCopy["Status"] = 'unused';
}

$imageCopy["Dangling"] = false;

array_push($images, $imageCopy);
}
}
}

return $images;
}
}
17 changes: 17 additions & 0 deletions app/Actions/Docker/UpdateServerDockerImageTag.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<?php

namespace App\Actions\Docker;

use Lorisleiva\Actions\Concerns\AsAction;

class UpdateServerDockerImageTag
{
use AsAction;

public static function run($server, $imageId, $tagName)
{
$imageDetails = GetServerDockerImageDetails::run($server, $imageId);

return instant_remote_process(["docker tag {$imageId} {$imageDetails['Repository']}:{$tagName}"], $server);
}
}
98 changes: 98 additions & 0 deletions app/Http/Controllers/Api/DockerController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
<?php

namespace App\Http\Controllers\Api;

use App\Actions\Docker\DeleteServerDockerImages;
use App\Actions\Docker\GetServerDockerImageDetails;
use App\Actions\Docker\ListServerDockerImages;
use App\Actions\Docker\UpdateServerDockerImageTag;
use App\Http\Controllers\Controller;
use App\Models\Server;
use Illuminate\Http\Request;

class DockerController extends Controller
{
public function list_server_docker_images($server_uuid)
{

$query = Server::query();

$server = $query->where('uuid', $server_uuid)->first();
if (!$server) {
return response()->json(['error' => 'server not found'], 404);
}

$isReachable = (bool) $server->settings->is_reachable;
// If the server is reachable, send the reachable notification if it was sent before
if ($isReachable !== true) {
return response()->json(['error' => 'server is not reachable.'], 403);
}

return ListServerDockerImages::run($server);
}

public function get_server_docker_image_details($server_uuid, $id)
{
$query = Server::query();

$server = $query->where('uuid', $server_uuid)->first();
if (!$server) {
return response()->json(['error' => 'server not found'], 404);
}

$isReachable = (bool) $server->settings->is_reachable;
// If the server is reachable, send the reachable notification if it was sent before
if ($isReachable !== true) {
return response()->json(['error' => 'server is not reachable.'], 403);
}

return response()->json(GetServerDockerImageDetails::run($server, $id));
}

public function update_server_docker_image_tag($server_uuid, $id, Request $request)
{
$query = Server::query();

$server = $query->where('uuid', $server_uuid)->first();
if (!$server) {
return response()->json(['error' => 'server not found'], 404);
}

$isReachable = (bool) $server->settings->is_reachable;
// If the server is reachable, send the reachable notification if it was sent before
if ($isReachable !== true) {
return response()->json(['error' => 'server is not reachable.'], 403);
}

$validatedData = $request->validate([
'tag' => 'required|string|min:1'
]);

return response()->json(UpdateServerDockerImageTag::run($server, $id, $validatedData['tag']));
}

public function delete_server_docker_images($server_uuid, Request $request)
{
$query = Server::query();

$server = $query->where('uuid', $server_uuid)->first();
if (!$server) {
return response()->json(['error' => 'server not found'], 404);
}

$isReachable = (bool) $server->settings->is_reachable;
// If the server is reachable, send the reachable notification if it was sent before
if ($isReachable !== true) {
return response()->json(['error' => 'server is not reachable.'], 403);
}

$validatedData = $request->validate([
'ids' => ['nullable', 'array'],
'ids.*' => ['string', 'distinct'],
]);

$message = DeleteServerDockerImages::run($server, $validatedData['ids']);

return response()->json(['message' => $message]);
}
}
Loading