feat: add static ipv4 ipv6 support

This commit is contained in:
Andras Bacsai 2024-02-25 23:13:27 +01:00
parent 5e980c5fe0
commit c7da43f50d
5 changed files with 55 additions and 19 deletions

View File

@ -78,25 +78,25 @@ private function check_resources($schedule)
dispatch($job);
})->name('container-status-' . $server->id)->everyMinute()->onOneServer();
if ($server->isLogDrainEnabled()) {
$schedule
->call(function () use ($server) {
$randomSeconds = rand(1, 40);
$job = new CheckLogDrainContainerJob($server);
$job->delay($randomSeconds);
dispatch($job);
})->name('log-drain-container-check-' . $server->id)->everyMinute()->onOneServer();
// $schedule->job(new CheckLogDrainContainerJob($server))->everyMinute()->onOneServer();
$schedule
->call(function () use ($server) {
$randomSeconds = rand(1, 40);
$job = new CheckLogDrainContainerJob($server);
$job->delay($randomSeconds);
dispatch($job);
})->name('log-drain-container-check-' . $server->id)->everyMinute()->onOneServer();
}
}
foreach ($servers as $server) {
$schedule
->call(function () use ($server) {
$randomSeconds = rand(1, 40);
$job = new ServerStatusJob($server);
$job->delay($randomSeconds);
dispatch($job);
})->name('server-status-job-' . $server->id)->everyMinute()->onOneServer();
// $schedule->job(new ServerStatusJob($server))->everyMinute()->onOneServer();
$schedule
->call(function () use ($server) {
$randomSeconds = rand(1, 40);
$job = new ServerStatusJob($server);
$job->delay($randomSeconds);
dispatch($job);
})->name('server-status-job-' . $server->id)->everyMinute()->onOneServer();
}
}
private function instance_auto_update($schedule)

View File

@ -1223,6 +1223,19 @@ private function generate_compose_file()
if ((bool)$this->application->settings->is_consistent_container_name_enabled) {
$custom_compose = convert_docker_run_to_compose($this->application->custom_docker_run_options);
if (count($custom_compose) > 0) {
$ipv4 = data_get($custom_compose, 'ip.0');
$ipv6 = data_get($custom_compose, 'ip6.0');
data_forget($custom_compose, 'ip');
data_forget($custom_compose, 'ip6');
if ($ipv4 || $ipv6) {
data_forget($docker_compose['services'][$this->application->uuid], 'networks');
}
if ($ipv4) {
$docker_compose['services'][$this->application->uuid]['networks'][$this->destination->network]['ipv4_address'] = $ipv4;
}
if ($ipv6) {
$docker_compose['services'][$this->application->uuid]['networks'][$this->destination->network]['ipv6_address'] = $ipv6;
}
$docker_compose['services'][$this->container_name] = array_merge_recursive($docker_compose['services'][$this->container_name], $custom_compose);
}
} else {
@ -1230,6 +1243,19 @@ private function generate_compose_file()
data_forget($docker_compose, 'services.' . $this->container_name);
$custom_compose = convert_docker_run_to_compose($this->application->custom_docker_run_options);
if (count($custom_compose) > 0) {
$ipv4 = data_get($custom_compose, 'ip.0');
$ipv6 = data_get($custom_compose, 'ip6.0');
data_forget($custom_compose, 'ip');
data_forget($custom_compose, 'ip6');
if ($ipv4 || $ipv6) {
data_forget($docker_compose['services'][$this->application->uuid], 'networks');
}
if ($ipv4) {
$docker_compose['services'][$this->application->uuid]['networks'][$this->destination->network]['ipv4_address'] = $ipv4;
}
if ($ipv6) {
$docker_compose['services'][$this->application->uuid]['networks'][$this->destination->network]['ipv6_address'] = $ipv6;
}
$docker_compose['services'][$this->application->uuid] = array_merge_recursive($docker_compose['services'][$this->application->uuid], $custom_compose);
}
}

View File

@ -43,6 +43,10 @@ public function uniqueId(): int
public function handle()
{
if (!$this->server->isFunctional()) {
return 'Server is not ready.';
};
$applications = $this->server->applications();
$skip_these_applications = collect([]);
foreach ($applications as $application) {
@ -57,10 +61,6 @@ public function handle()
$applications = $applications->filter(function ($value, $key) use ($skip_these_applications) {
return !$skip_these_applications->pluck('id')->contains($value->id);
});
if (!$this->server->isFunctional()) {
return 'Server is not ready.';
};
try {
if ($this->server->isSwarm()) {
$containers = instant_remote_process(["docker service inspect $(docker service ls -q) --format '{{json .}}'"], $this->server, false);

View File

@ -423,7 +423,7 @@ function convert_docker_run_to_compose(?string $custom_docker_run_options = null
'--security-opt',
'--sysctl',
'--ulimit',
'--device'
'--device',
]);
$mapping = collect([
'--cap-add' => 'cap_add',
@ -435,6 +435,7 @@ function convert_docker_run_to_compose(?string $custom_docker_run_options = null
'--init' => 'init',
'--ulimit' => 'ulimits',
'--privileged' => 'privileged',
'--ip' => 'ip',
]);
foreach ($matches as $match) {
$option = $match[1];

View File

@ -8,6 +8,15 @@
])->ray();
});
test('ConvertIp', function () {
$input = '--cap-add=NET_ADMIN --cap-add=NET_RAW --cap-add SYS_ADMIN --ip 127.0.0.1 --ip 127.0.0.2';
$output = convert_docker_run_to_compose($input);
expect($output)->toBe([
'cap_add' => ['NET_ADMIN', 'NET_RAW', 'SYS_ADMIN'],
'ip' => ['127.0.0.1', '127.0.0.2']
])->ray();
});
test('ConvertPrivilegedAndInit', function () {
$input = '---privileged --init';
$output = convert_docker_run_to_compose($input);