mirror of
https://github.com/coollabsio/coolify.git
synced 2026-10-28 17:44:36 +08:00
The runner group was limited to private repositories, so jobs from public repositories never got a runner: Coolify still started a runner for each matching job, which then waited idle until its timeout. The runner group now allows every repository of the organization, public ones too; existing private groups are updated. GitHub gives a runner any queued job with matching labels, so pull request jobs are refused inside the runner: a job-started hook fails jobs from pull_request, pull_request_target and review events before any step runs, and fails closed when the event is unknown. A new runner setting, off by default, allows pull request jobs; the settings page then warns to require approval for fork pull request workflows on GitHub.
102 lines
2.8 KiB
PHP
102 lines
2.8 KiB
PHP
<?php
|
|
|
|
namespace App\Models;
|
|
|
|
use App\Enums\GithubRunnerDockerMode;
|
|
use App\Enums\GithubRunnerStatus;
|
|
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
|
use Illuminate\Database\Eloquent\Relations\HasMany;
|
|
|
|
class GithubRunnerConfig extends BaseModel
|
|
{
|
|
/**
|
|
* Labels that every Coolify runner registers in addition to the custom labels.
|
|
*/
|
|
public const DEFAULT_LABELS = ['self-hosted', 'linux'];
|
|
|
|
protected $fillable = [
|
|
'server_id',
|
|
'github_app_id',
|
|
'labels',
|
|
'is_enabled',
|
|
'is_dedicated',
|
|
'allow_pull_requests',
|
|
'max_runners',
|
|
'docker_mode',
|
|
'runner_image',
|
|
'cpu_limit',
|
|
'memory_limit',
|
|
'capacity_wait_timeout',
|
|
'idle_timeout',
|
|
'job_timeout',
|
|
];
|
|
|
|
protected function casts(): array
|
|
{
|
|
return [
|
|
'labels' => 'array',
|
|
'is_enabled' => 'boolean',
|
|
'is_dedicated' => 'boolean',
|
|
'allow_pull_requests' => 'boolean',
|
|
'max_runners' => 'integer',
|
|
'docker_mode' => GithubRunnerDockerMode::class,
|
|
'capacity_wait_timeout' => 'integer',
|
|
'idle_timeout' => 'integer',
|
|
'job_timeout' => 'integer',
|
|
];
|
|
}
|
|
|
|
public function server(): BelongsTo
|
|
{
|
|
return $this->belongsTo(Server::class);
|
|
}
|
|
|
|
public function githubApp(): BelongsTo
|
|
{
|
|
return $this->belongsTo(GithubApp::class);
|
|
}
|
|
|
|
public function executions(): HasMany
|
|
{
|
|
return $this->hasMany(GithubRunnerExecution::class);
|
|
}
|
|
|
|
/**
|
|
* Labels sent to GitHub when a runner is registered.
|
|
*
|
|
* @return array<int, string>
|
|
*/
|
|
public function registeredLabels(): array
|
|
{
|
|
return array_values(array_unique([...self::DEFAULT_LABELS, ...array_map('strtolower', $this->labels ?? [])]));
|
|
}
|
|
|
|
/**
|
|
* A job matches when it asks for at least one custom label and every label it asks for is registered.
|
|
* Jobs that only ask for generic labels such as "self-hosted" are left for other runners.
|
|
*
|
|
* @param array<int, string> $requestedLabels
|
|
*/
|
|
public function matchesLabels(array $requestedLabels): bool
|
|
{
|
|
$requested = array_map(fn ($label) => strtolower((string) $label), $requestedLabels);
|
|
$custom = array_map('strtolower', $this->labels ?? []);
|
|
|
|
if (array_intersect($requested, $custom) === []) {
|
|
return false;
|
|
}
|
|
|
|
return array_diff($requested, $this->registeredLabels()) === [];
|
|
}
|
|
|
|
public function occupiedRunnerCount(): int
|
|
{
|
|
return $this->executions()->whereIn('status', GithubRunnerStatus::occupying())->count();
|
|
}
|
|
|
|
public function runnerImage(): string
|
|
{
|
|
return filled($this->runner_image) ? $this->runner_image : config('constants.github_runner.image');
|
|
}
|
|
}
|