Documentation
¶
Overview ¶
Package dockercompose provides Docker Compose CLI operations for XenForo.
Index ¶
- Variables
- func CheckDockerComposeAvailable(ctx context.Context) error
- func CheckDockerRunning(ctx context.Context) error
- func IsOrbStack(ctx context.Context) (bool, error)
- func ProjectExists(ctx context.Context, instance string) (bool, error)
- type ContainerInfo
- type Runner
- func (r *Runner) Compose(ctx context.Context, stdin io.Reader, stdout, stderr io.Writer, args ...string) error
- func (r *Runner) Contexts() []string
- func (r *Runner) DatabaseCredentials() (string, string)
- func (r *Runner) DatabaseName() string
- func (r *Runner) Destroy(ctx context.Context) error
- func (r *Runner) ExecInput(ctx context.Context, service string, env map[string]string, stdin io.Reader, ...) error
- func (r *Runner) ExecOrRun(ctx context.Context, service string, env map[string]string, stdin io.Reader, ...) error
- func (r *Runner) ExecOutput(ctx context.Context, service string, env map[string]string, stdout io.Writer, ...) error
- func (r *Runner) GetURL(ctx context.Context) (string, error)
- func (r *Runner) Instance() string
- func (r *Runner) IsServiceRunning(ctx context.Context, service string) (bool, error)
- func (r *Runner) PSInfo(ctx context.Context) ([]ContainerInfo, error)
- func (r *Runner) WaitForDatabase(ctx context.Context, checkInterval time.Duration) error
Constants ¶
This section is empty.
Variables ¶
var ( // ErrUnexpectedOutput indicates that an operation produced unexpected output. ErrUnexpectedOutput = errors.New("unexpected output") // ErrTimeout indicates an operation timed out. ErrTimeout = errors.New("operation timed out") // ErrEnvNotInitialized indicates the Docker environment is not initialized. ErrEnvNotInitialized = errors.New("environment not initialized") )
Functions ¶
func CheckDockerComposeAvailable ¶
CheckDockerComposeAvailable checks if Docker Compose is available.
func CheckDockerRunning ¶
CheckDockerRunning checks if Docker is running.
func IsOrbStack ¶
IsOrbStack reports whether the Docker engine is OrbStack, which exposes container services to the host at <service>.<project>.orb.local without publishing ports.
func ProjectExists ¶
ProjectExists reports whether a Compose project already owns containers or volumes under the given instance name.
Compose derives container and volume names from the project name, so a second environment reusing one would adopt the first's resources. Volumes are checked as well as containers because `docker compose down` leaves volumes behind: an environment can be stopped with no containers at all and still collide.
A failed Docker command is returned as an error rather than reported as an absent project. Treating an unreachable Docker as "free" would let creation proceed onto a name that may already be in use.
Types ¶
type ContainerInfo ¶
ContainerInfo describes a single container as rendered by `xf ps`.
Status and Ports are display strings derived from the Compose record rather than wire fields: `docker compose ps --format json` reports State, Health, ExitCode and Publishers, not the combined Status/Ports strings.
type Runner ¶
type Runner struct {
// contains filtered or unexported fields
}
Runner handles Docker Compose operations for a XenForo installation.
func (*Runner) Compose ¶
func (r *Runner) Compose(ctx context.Context, stdin io.Reader, stdout, stderr io.Writer, args ...string) error
Compose runs a docker compose command directly with explicit stdio.
func (*Runner) Contexts ¶
Contexts returns the compose contexts declared by XF_CONTEXTS, which select the environment's feature compose files (for example "mysql", "postgres" or "redis").
func (*Runner) DatabaseCredentials ¶
DatabaseCredentials returns the configured database user and password.
The names must match what the compose files read, since those are the keys that end up in .env: XF_DB_USER and XF_DB_PASSWORD (compose.mysql.yaml, compose.postgres.yaml). The defaults mirror the fallbacks declared there.
Resolution order matches docker compose: process environment, then .env, then the built-in default.
func (*Runner) DatabaseName ¶
DatabaseName returns the configured database name.
func (*Runner) Destroy ¶
Destroy stops the environment and removes its volumes.
This is permanent: the database and any other volume data are deleted. It is what removing a worktree needs, since otherwise each discarded feature branch leaves a full volume set behind.
func (*Runner) ExecInput ¶
func (r *Runner) ExecInput(ctx context.Context, service string, env map[string]string, stdin io.Reader, cmd ...string) error
ExecInput runs a command in a service, feeding it from stdin.
func (*Runner) ExecOrRun ¶
func (r *Runner) ExecOrRun(ctx context.Context, service string, env map[string]string, stdin io.Reader, stdout, stderr io.Writer, cmd ...string) error
ExecOrRun uses exec for running services and falls back to run for stopped services.
env is passed as container environment variables so secrets stay out of the process list. The streams are explicit so interactive commands and progress writers behave the same whether the service is running or stopped. A TTY is requested only when stdin is a terminal.
func (*Runner) ExecOutput ¶
func (r *Runner) ExecOutput(ctx context.Context, service string, env map[string]string, stdout io.Writer, cmd ...string) error
ExecOutput runs a command in a service, streaming its output to stdout.
Output is streamed rather than buffered so that large results, such as a database dump, do not have to fit in memory. Secrets belong in env rather than cmd: a value passed as a command argument is visible in the container's process list.
func (*Runner) GetURL ¶
GetURL returns the URL for accessing the XenForo site. It detects OrbStack vs standard Docker.
func (*Runner) IsServiceRunning ¶
IsServiceRunning reports whether the given compose service has a running container.