dockercompose

package
v0.2.2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 12, 2026 License: MIT Imports: 15 Imported by: 0

Documentation

Overview

Package dockercompose provides Docker Compose CLI operations for XenForo.

Index

Constants

This section is empty.

Variables

View Source
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

func CheckDockerComposeAvailable(ctx context.Context) error

CheckDockerComposeAvailable checks if Docker Compose is available.

func CheckDockerRunning

func CheckDockerRunning(ctx context.Context) error

CheckDockerRunning checks if Docker is running.

func IsOrbStack

func IsOrbStack(ctx context.Context) (bool, error)

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

func ProjectExists(ctx context.Context, instance string) (bool, error)

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

type ContainerInfo struct {
	Service string
	Name    string
	State   string
	Status  string
	Ports   string
}

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 NewRunner

func NewRunner(xfDir string) (*Runner, error)

NewRunner creates a new Docker Compose runner for the given XenForo directory.

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

func (r *Runner) Contexts() []string

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

func (r *Runner) DatabaseCredentials() (string, string)

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

func (r *Runner) DatabaseName() string

DatabaseName returns the configured database name.

func (*Runner) Destroy

func (r *Runner) Destroy(ctx context.Context) error

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.

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

func (r *Runner) GetURL(ctx context.Context) (string, error)

GetURL returns the URL for accessing the XenForo site. It detects OrbStack vs standard Docker.

func (*Runner) Instance

func (r *Runner) Instance() string

Instance returns the Docker instance name.

func (*Runner) IsServiceRunning

func (r *Runner) IsServiceRunning(ctx context.Context, service string) (bool, error)

IsServiceRunning reports whether the given compose service has a running container.

func (*Runner) PSInfo

func (r *Runner) PSInfo(ctx context.Context) ([]ContainerInfo, error)

PSInfo returns container status parsed from `docker compose ps --format json`.

func (*Runner) WaitForDatabase

func (r *Runner) WaitForDatabase(ctx context.Context, checkInterval time.Duration) error

WaitForDatabase waits for the database to be ready.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL