feat: attach vector container to additional docker networks

Adds a new global `vector-networks` property on the logs plugin that takes a comma-separated list of Docker networks. When set, the rendered compose file declares each network plus `bridge` as external and joins them on the vector service, so `docker compose up` reconciles attachments on every `logs:vector-start`. When unset, the existing `network_mode: bridge` template is preserved unchanged. The value is validated against `docker network inspect` at set time, rejects the reserved `bridge` entry, and is surfaced in `dokku logs:report` via `--logs-vector-global-networks`.
This commit is contained in:
Jose Diaz-Gonzalez
2026-05-12 22:05:50 -04:00
parent b096d0f131
commit d00a7d741a
7 changed files with 262 additions and 10 deletions

View File

@@ -24,9 +24,10 @@ type vectorSource struct {
}
type vectorTemplateData struct {
DokkuLibRoot string
DokkuLogsDir string
VectorImage string
DokkuLibRoot string
DokkuLogsDir string
VectorImage string
VectorNetworks []string
}
const vectorContainerName = "vector-vector-1"
@@ -89,9 +90,10 @@ func startVectorContainer(vectorImage string) error {
}
data := vectorTemplateData{
DokkuLibRoot: dokkuLibRoot,
DokkuLogsDir: dokkuLogsDir,
VectorImage: vectorImage,
DokkuLibRoot: dokkuLibRoot,
DokkuLogsDir: dokkuLogsDir,
VectorImage: vectorImage,
VectorNetworks: getVectorNetworks(),
}
if err := tmpl.Execute(tmpFile, data); err != nil {
@@ -104,6 +106,24 @@ func startVectorContainer(vectorImage string) error {
})
}
func getVectorNetworks() []string {
value := common.PropertyGet("logs", "--global", "vector-networks")
if value == "" {
return nil
}
networks := []string{}
for _, name := range strings.Split(value, ",") {
name = strings.TrimSpace(name)
if name == "" {
continue
}
networks = append(networks, name)
}
return networks
}
func getComputedVectorImage() string {
return common.PropertyGetDefault("logs", "--global", "vector-image", getDefaultVectorImage())
}
@@ -151,9 +171,10 @@ func stopVectorContainer() error {
}
data := vectorTemplateData{
DokkuLibRoot: dokkuLibRoot,
DokkuLogsDir: dokkuLogsDir,
VectorImage: getComputedVectorImage(),
DokkuLibRoot: dokkuLibRoot,
DokkuLogsDir: dokkuLogsDir,
VectorImage: getComputedVectorImage(),
VectorNetworks: getVectorNetworks(),
}
if err := tmpl.Execute(tmpFile, data); err != nil {

View File

@@ -35,6 +35,7 @@ var (
"app-label-alias": true,
"max-size": true,
"vector-image": true,
"vector-networks": true,
"vector-sink": true,
}
)

View File

@@ -24,6 +24,7 @@ func ReportSingleApp(appName string, format string, infoFlag string) error {
"--logs-global-max-size": reportGlobalMaxSize,
"--logs-global-vector-sink": reportGlobalVectorSink,
"--logs-vector-global-image": reportVectorGlobalImage,
"--logs-vector-global-networks": reportVectorGlobalNetworks,
}
} else {
flags = map[string]common.ReportFunc{
@@ -35,6 +36,7 @@ func ReportSingleApp(appName string, format string, infoFlag string) error {
"--logs-app-label-alias": reportAppLabelAlias,
"--logs-max-size": reportMaxSize,
"--logs-vector-global-image": reportVectorGlobalImage,
"--logs-vector-global-networks": reportVectorGlobalNetworks,
"--logs-vector-sink": reportVectorSink,
}
}
@@ -84,6 +86,10 @@ func reportVectorGlobalImage(appName string) string {
return getComputedVectorImage()
}
func reportVectorGlobalNetworks(appName string) string {
return common.PropertyGet("logs", "--global", "vector-networks")
}
func reportGlobalVectorSink(appName string) string {
value := common.PropertyGet("logs", "--global", "vector-sink")
if value == "" {

View File

@@ -4,6 +4,9 @@ import (
"errors"
"fmt"
"strconv"
"strings"
"github.com/dokku/dokku/plugins/common"
)
func validateSetValue(appName string, key string, value string) error {
@@ -11,6 +14,10 @@ func validateSetValue(appName string, key string, value string) error {
return validateMaxSize(appName, value)
}
if key == "vector-networks" {
return validateVectorNetworks(appName, value)
}
if key == "vector-sink" {
return validateVectorSink(appName, value)
}
@@ -56,3 +63,30 @@ func validateVectorSink(appName string, value string) error {
return nil
}
func validateVectorNetworks(appName string, value string) error {
if value == "" {
return nil
}
for _, name := range strings.Split(value, ",") {
name = strings.TrimSpace(name)
if name == "" {
return errors.New("Invalid vector-networks value, empty entry in comma-separated list")
}
if name == "bridge" {
return errors.New("Invalid vector-networks value, \"bridge\" is attached by default and must not be listed")
}
result, err := common.CallExecCommand(common.ExecCommandInput{
Command: common.DockerBin(),
Args: []string{"network", "inspect", name},
})
if err != nil || result.ExitCode != 0 {
return fmt.Errorf("Network %q does not exist", name)
}
}
return nil
}

View File

@@ -13,7 +13,15 @@ services:
org.label-schema.schema-version: "1.0"
org.label-schema.vendor: dokku
{{- if $.VectorNetworks }}
networks:
bridge: {}
{{- range $name := $.VectorNetworks }}
{{ $name }}: {}
{{- end }}
{{- else }}
network_mode: bridge
{{- end }}
restart: unless-stopped
@@ -21,3 +29,15 @@ services:
- "{{ $.DokkuLibRoot }}/data/logs:/etc/vector"
- "/var/run/docker.sock:/var/run/docker.sock:ro"
- "{{ $.DokkuLogsDir }}/apps:/var/log/dokku/apps"
{{- if $.VectorNetworks }}
networks:
bridge:
name: bridge
external: true
{{- range $name := $.VectorNetworks }}
{{ $name }}:
name: {{ $name }}
external: true
{{- end }}
{{- end }}