compose

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Nov 3, 2026 License: Apache-2.0 Imports: 10 Imported by: 0

Documentation

Overview

Package compose runs the docker compose CLI on a workspace.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func SystemExec

func SystemExec(ctx context.Context, c Command) error

SystemExec runs the real docker CLI.

Types

type Command

type Command struct {
	Args   []string
	Env    []string // added to the environment of the CLI
	Stdin  io.Reader
	Stdout io.Writer
	Stderr io.Writer
}

Command is one docker compose call.

type Container

type Container struct {
	Name       string      `json:"Name"`
	Service    string      `json:"Service"`
	State      string      `json:"State"`
	Health     string      `json:"Health"`
	ExitCode   int         `json:"ExitCode"`
	Publishers []Publisher `json:"Publishers"`
	Labels     string      `json:"Labels"`
}

Container is one line of 'docker compose ps --format json'.

func ParsePs

func ParsePs(data []byte) ([]Container, error)

ParsePs reads 'docker compose ps --format json'. Compose writes one JSON object per line; versions before 2.21 wrote one JSON array.

func (Container) OneOff

func (c Container) OneOff() bool

OneOff reports whether the container was started by 'docker compose run'.

type Exec

type Exec func(ctx context.Context, cmd Command) error

Exec runs a command. Tests replace it with a fake.

type Publisher

type Publisher struct {
	URL           string `json:"URL"`
	TargetPort    int    `json:"TargetPort"`
	PublishedPort int    `json:"PublishedPort"`
	Protocol      string `json:"Protocol"`
}

Publisher is a published port of a container.

type Runner

type Runner struct {
	Dir  string
	Exec Exec
	// Env is added to every call, for example the config hashes used in labels.
	Env []string
}

Runner runs docker compose with the files of one workspace.

func (Runner) Output

func (r Runner) Output(ctx context.Context, args ...string) ([]byte, error)

Output runs 'docker compose <args>' and returns its stdout. stderr is in the error.

func (Runner) Ps

func (r Runner) Ps(ctx context.Context) ([]Container, error)

Ps returns every container of the project, also the stopped ones.

func (Runner) Run

func (r Runner) Run(ctx context.Context, stdout, stderr io.Writer, args ...string) error

Run runs 'docker compose <args>' and writes its output to stdout and stderr.

func (Runner) RunIO

func (r Runner) RunIO(ctx context.Context, stdin io.Reader, stdout, stderr io.Writer, args ...string) error

RunIO runs 'docker compose <args>' with stdin.

Jump to

Keyboard shortcuts

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