-
-
Notifications
You must be signed in to change notification settings - Fork 3.6k
feat: include coolify.tags in autogenerated container labels #7922
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
base: next
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -209,6 +209,23 @@ function get_port_from_dockerfile($dockerfile): ?int | |
| 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(' '); | ||
| } | ||
|
Comment on lines
+212
to
+227
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Harden Right now, an array (or relation object) passed into this helper will trigger a runtime crash. Skynet doesn’t even need serverless for that—just one unexpected type and “I’ll be back” becomes your queue retry loop. Proposed fix-function formatTagsForDockerLabel($tags, int $limit = 50): string
+function formatTagsForDockerLabel(Collection|array|null $tags, int $limit = 50): string
{
- if (! $tags || $tags->isEmpty()) {
+ $tags = collect($tags);
+ if ($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);
+ $sanitized = preg_replace('/[^a-zA-Z0-9\-_.:\/]/', '', (string) $tag);
+ return $sanitized ?? '';
})
->filter() // Remove empty strings after sanitization
->implode(' ');
}🤖 Prompt for AI Agents |
||
|
|
||
| function defaultDatabaseLabels($database) | ||
| { | ||
| $labels = collect([]); | ||
|
|
@@ -221,10 +238,15 @@ function defaultDatabaseLabels($database) | |
| $labels->push('coolify.environmentName='.Str::slug($database->environment->name)); | ||
| $labels->push('coolify.database.subType='.$database->type()); | ||
|
|
||
| $tagsLabel = formatTagsForDockerLabel($database->tags ?? collect()); | ||
| if ($tagsLabel) { | ||
| $labels->push('coolify.tags='.$tagsLabel); | ||
| } | ||
|
|
||
| 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->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)); | ||
| } | ||
|
|
||
| if ($tags) { | ||
| $tagsLabel = formatTagsForDockerLabel($tags); | ||
| if ($tagsLabel) { | ||
| $labels->push('coolify.tags='.$tagsLabel); | ||
| } | ||
| } | ||
|
|
||
| return $labels; | ||
| } | ||
|
|
||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Avoid an extra query: eager-load
tagsbefore using$this->application->tags.Self-hosting on real servers is great; surprise DB queries in hot paths are less great. Consider loading tags once in the constructor (or just before label generation).
Proposed fix (example)
🤖 Prompt for AI Agents