mirror of
https://github.com/coollabsio/coolify.git
synced 2026-03-11 08:55:47 +00:00
add tag docker label
This commit is contained in:
parent
31ba241d97
commit
e4d0c53d2b
4 changed files with 36 additions and 3 deletions
|
|
@ -2487,7 +2487,7 @@ class ApplicationDeploymentJob implements ShouldBeEncrypted, ShouldQueue
|
||||||
return escapeDollarSign($value);
|
return escapeDollarSign($value);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
$labels = $labels->merge(defaultLabels($this->application->id, $this->application->uuid, $this->application->project()->name, $this->application->name, $this->application->environment->name, $this->pull_request_id))->toArray();
|
$labels = $labels->merge(defaultLabels($this->application->id, $this->application->uuid, $this->application->project()->name, $this->application->name, $this->application->environment->name, $this->pull_request_id, tags: $this->application->tags))->toArray();
|
||||||
|
|
||||||
// Check for custom HEALTHCHECK
|
// Check for custom HEALTHCHECK
|
||||||
if ($this->application->build_pack === 'dockerfile' || $this->application->dockerfile) {
|
if ($this->application->build_pack === 'dockerfile' || $this->application->dockerfile) {
|
||||||
|
|
|
||||||
|
|
@ -209,6 +209,23 @@ function get_port_from_dockerfile($dockerfile): ?int
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function formatTagsForDockerLabel($tags, int $limit = 50): string
|
||||||
|
{
|
||||||
|
if (! $tags || $tags->isEmpty()) {
|
||||||
|
return '';
|
||||||
|
}
|
||||||
|
|
||||||
|
return $tags->take($limit)
|
||||||
|
->pluck('name')
|
||||||
|
->map(function ($tag) {
|
||||||
|
// Sanitize to only allow characters safe for Docker labels
|
||||||
|
// Allows: alphanumeric, hyphens, underscores, periods, colons, forward slashes
|
||||||
|
return preg_replace('/[^a-zA-Z0-9\-_.:\/]/', '', $tag);
|
||||||
|
})
|
||||||
|
->filter() // Remove empty strings after sanitization
|
||||||
|
->implode(' ');
|
||||||
|
}
|
||||||
|
|
||||||
function defaultDatabaseLabels($database)
|
function defaultDatabaseLabels($database)
|
||||||
{
|
{
|
||||||
$labels = collect([]);
|
$labels = collect([]);
|
||||||
|
|
@ -221,10 +238,15 @@ function defaultDatabaseLabels($database)
|
||||||
$labels->push('coolify.environmentName='.Str::slug($database->environment->name));
|
$labels->push('coolify.environmentName='.Str::slug($database->environment->name));
|
||||||
$labels->push('coolify.database.subType='.$database->type());
|
$labels->push('coolify.database.subType='.$database->type());
|
||||||
|
|
||||||
|
$tagsLabel = formatTagsForDockerLabel($database->tags ?? collect());
|
||||||
|
if ($tagsLabel) {
|
||||||
|
$labels->push('coolify.tags='.$tagsLabel);
|
||||||
|
}
|
||||||
|
|
||||||
return $labels;
|
return $labels;
|
||||||
}
|
}
|
||||||
|
|
||||||
function defaultLabels($id, $name, string $projectName, string $resourceName, string $environment, $pull_request_id = 0, string $type = 'application', $subType = null, $subId = null, $subName = null)
|
function defaultLabels($id, $name, string $projectName, string $resourceName, string $environment, $pull_request_id = 0, string $type = 'application', $subType = null, $subId = null, $subName = null, $tags = null)
|
||||||
{
|
{
|
||||||
$labels = collect([]);
|
$labels = collect([]);
|
||||||
$labels->push('coolify.managed=true');
|
$labels->push('coolify.managed=true');
|
||||||
|
|
@ -244,6 +266,13 @@ function defaultLabels($id, $name, string $projectName, string $resourceName, st
|
||||||
$subName && $labels->push('coolify.service.subName='.Str::slug($subName));
|
$subName && $labels->push('coolify.service.subName='.Str::slug($subName));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if ($tags) {
|
||||||
|
$tagsLabel = formatTagsForDockerLabel($tags);
|
||||||
|
if ($tagsLabel) {
|
||||||
|
$labels->push('coolify.tags='.$tagsLabel);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return $labels;
|
return $labels;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1168,6 +1168,7 @@ function applicationParser(Application $resource, int $pull_request_id = 0, ?int
|
||||||
pull_request_id: $pullRequestId,
|
pull_request_id: $pullRequestId,
|
||||||
type: 'application',
|
type: 'application',
|
||||||
environment: $resource->environment->name,
|
environment: $resource->environment->name,
|
||||||
|
tags: $resource->tags,
|
||||||
);
|
);
|
||||||
|
|
||||||
$isDatabase = isDatabaseImage($image, $service);
|
$isDatabase = isDatabaseImage($image, $service);
|
||||||
|
|
@ -2272,6 +2273,7 @@ function serviceParser(Service $resource): Collection
|
||||||
subId: $savedService->id,
|
subId: $savedService->id,
|
||||||
subName: $savedService->human_name ?? $savedService->name,
|
subName: $savedService->human_name ?? $savedService->name,
|
||||||
environment: $resource->environment->name,
|
environment: $resource->environment->name,
|
||||||
|
tags: $resource->tags,
|
||||||
);
|
);
|
||||||
|
|
||||||
// Add COOLIFY_FQDN & COOLIFY_URL to environment
|
// Add COOLIFY_FQDN & COOLIFY_URL to environment
|
||||||
|
|
|
||||||
|
|
@ -1918,6 +1918,7 @@ function parseDockerComposeFile(Service|Application $resource, bool $isNew = fal
|
||||||
subId: $savedService->id,
|
subId: $savedService->id,
|
||||||
subName: $savedService->name,
|
subName: $savedService->name,
|
||||||
environment: $resource->environment->name,
|
environment: $resource->environment->name,
|
||||||
|
tags: $resource->tags,
|
||||||
);
|
);
|
||||||
$serviceLabels = $serviceLabels->merge($defaultLabels);
|
$serviceLabels = $serviceLabels->merge($defaultLabels);
|
||||||
if (! $isDatabase && $fqdns->count() > 0) {
|
if (! $isDatabase && $fqdns->count() > 0) {
|
||||||
|
|
@ -2765,7 +2766,8 @@ function parseDockerComposeFile(Service|Application $resource, bool $isNew = fal
|
||||||
resourceName: $resource->name,
|
resourceName: $resource->name,
|
||||||
environment: $resource->environment->name,
|
environment: $resource->environment->name,
|
||||||
pull_request_id: $pull_request_id,
|
pull_request_id: $pull_request_id,
|
||||||
type: 'application'
|
type: 'application',
|
||||||
|
tags: $resource->tags,
|
||||||
);
|
);
|
||||||
$serviceLabels = $serviceLabels->merge($defaultLabels);
|
$serviceLabels = $serviceLabels->merge($defaultLabels);
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue