Documentation
¶
Overview ¶
Package compose locates compose files and inspects how they declare ports.
Index ¶
- Variables
- func Base(dir string) (string, error)
- func Files(dir string) ([]string, error)
- func PortLabel(s ServicePort) string
- func Ports(path string) (raw []string, parametrised int, err error)
- func ServiceImage(dir, service string) (string, bool)
- func Services(dir string) ([]string, error)
- type ServicePort
Constants ¶
This section is empty.
Variables ¶
var OverrideNames = []string{
"compose.override.yaml", "compose.override.yml",
"docker-compose.override.yaml", "docker-compose.override.yml",
}
OverrideNames is exported so provisioning copies exactly the files this package detects; two lists drifting apart is how a detected override once ended up referenced by -f without existing in the worktree.
Functions ¶
func Base ¶
Base is the file wtc reads. It stops at the first match and never looks at override files, so a port parametrised only in an override stays invisible to it.
func Files ¶
Files reproduces docker compose's auto-detection, needed whenever an extra -f is passed since that forces every file to be named explicitly.
func PortLabel ¶
func PortLabel(s ServicePort) string
PortLabel distinguishes the several ports of one service, using the part of the variable name that is not the service name: MAILHOG_WEB_PORT on service mailhog becomes "web".
func Ports ¶
Ports counts how the base compose file declares its host ports. wtc can only isolate a worktree when they read ${VAR:-default}; anything hardcoded would collide with the main stack. Hardcoded declarations come back in raw as "host:container" strings, whichever compose syntax declared them.
func ServiceImage ¶ added in v0.4.0
ServiceImage returns the image a service runs, reading the project's merged compose configuration: an override redefining the service wins.
Types ¶
type ServicePort ¶
type ServicePort struct {
Service string
// Var is the environment variable wtc overrides, empty when the port is
// hardcoded and therefore not isolatable.
Var string
Host string // host port declared as the default
Container string // container side, which is what tells a web port apart
}
ServicePort is one published port of a service, as declared in the base compose file.
func MergedServicePorts ¶
func MergedServicePorts(dir string) ([]ServicePort, error)
MergedServicePorts reads the base file then lets the project's own override win, service by service. A project that already remaps its ports on purpose (to avoid a clash on the machine) must keep that mapping as the reference, otherwise rebasing from the base file would silently undo it.
func ServicePorts ¶
func ServicePorts(path string) ([]ServicePort, error)
ServicePorts lists the published ports per service, from that one file only: merging across files is MergedServicePorts' job. The file is walked as a YAML tree rather than decoded into structs, so compose's own tags (!override, !reset) and anchors pass through instead of failing the parse.
func (ServicePort) IsWeb ¶
func (s ServicePort) IsWeb() bool
IsWeb reports whether this port is worth prefixing with http://.