Add customizable container labels (#146)
This commit is contained in:
@@ -8,6 +8,7 @@ type Settings struct {
|
||||
Mounts []Mount
|
||||
Allocations Allocations
|
||||
Limits Limits
|
||||
Labels map[string]string
|
||||
}
|
||||
|
||||
// Defines the actual configuration struct for the environment with all of the settings
|
||||
@@ -68,6 +69,14 @@ func (c *Configuration) Mounts() []Mount {
|
||||
return c.settings.Mounts
|
||||
}
|
||||
|
||||
// Labels returns the container labels associated with this instance.
|
||||
func (c *Configuration) Labels() map[string]string {
|
||||
c.mu.RLock()
|
||||
defer c.mu.RUnlock()
|
||||
|
||||
return c.settings.Labels
|
||||
}
|
||||
|
||||
// Returns the environment variables associated with this instance.
|
||||
func (c *Configuration) EnvironmentVariables() []string {
|
||||
c.mu.RLock()
|
||||
|
||||
@@ -174,6 +174,16 @@ func (e *Environment) Create() error {
|
||||
}
|
||||
}
|
||||
|
||||
// Merge user-provided labels with system labels
|
||||
confLabels := e.Configuration.Labels()
|
||||
labels := make(map[string]string, 2+len(confLabels))
|
||||
|
||||
for key := range confLabels {
|
||||
labels[key] = confLabels[key]
|
||||
}
|
||||
labels["Service"] = "Pterodactyl"
|
||||
labels["ContainerType"] = "server_process"
|
||||
|
||||
conf := &container.Config{
|
||||
Hostname: e.Id,
|
||||
Domainname: config.Get().Docker.Domainname,
|
||||
@@ -186,10 +196,7 @@ func (e *Environment) Create() error {
|
||||
ExposedPorts: a.Exposed(),
|
||||
Image: strings.TrimPrefix(e.meta.Image, "~"),
|
||||
Env: e.Configuration.EnvironmentVariables(),
|
||||
Labels: map[string]string{
|
||||
"Service": "Pterodactyl",
|
||||
"ContainerType": "server_process",
|
||||
},
|
||||
Labels: labels,
|
||||
}
|
||||
|
||||
networkMode := container.NetworkMode(config.Get().Docker.Network.Mode)
|
||||
|
||||
Reference in New Issue
Block a user