exec

package
v0.2.1 Latest Latest
Warning

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

Go to latest
Published: Mar 21, 2022 License: MIT Imports: 17 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Mock added in v0.2.0

func Mock(shouldFail bool, resultContents string) func(Document) Exec

Mock can be used in tests to avoid executing real commands.

service.Executor := exec.Mock(true, pdfFixture)

Imprtant note: Mock will panic if the document's main input file does not contain a dot + file extension, of if the result content can't be written.

Types

type DockerClient

type DockerClient struct {
	// contains filtered or unexported fields
}

DockerClient wraps a Docker client instance and provides methods to pull images and start containers.

func NewDockerClient

func NewDockerClient(log *zap.Logger) (h *DockerClient, err error)

NewDockerClient creates a new DockerClient. To configure the client, use environment variables: DOCKER_HOST, DOCKER_API_VERSION, DOCKER_CERT_PATH and DOCKER_TLS_VERIFY are supported.

func (*DockerClient) Executor

func (dc *DockerClient) Executor(doc Document) Exec

func (*DockerClient) Run

func (dc *DockerClient) Run(ctx context.Context, tag, wd string, cmd []string) (string, error)

Run creates a new Docker container from the given image tag, mounts the working directory into it, and executes the given command in it.

func (*DockerClient) SetImages

func (dc *DockerClient) SetImages(ctx context.Context, alwaysPull bool, tags ...string) ([]string, error)

SetImages ensures that the given image tags are present on the Docker host (missing images are pulled automatically). Existing images are not updated, unless alwaysPull is true.

If stdout is a terminal, download progress is reported.

SetImages also sets the DockerClients allow list from which containers are started.

type Document added in v0.2.0

type Document interface {
	WorkingDirectory() (string, error)
	MainInput() (string, error)
	Engine() tex.Engine
	Image() string
}

Document is a sub-set of the tex.Document interface.

type Exec

type Exec interface {
	Run(context.Context, *zap.Logger) error
}

func LocalExec

func LocalExec(doc Document) Exec

type MockExec added in v0.2.0

type MockExec struct {

	// ShouldFail controls whether Run will return an error or not.
	ShouldFail bool

	// Result holds content written to either the document's result PDF
	// file, or its correspondint error log file, depending on the
	// value of ShouldFail.
	ResultContents string
	// contains filtered or unexported fields
}

func (*MockExec) Run added in v0.2.0

func (x *MockExec) Run(ctx context.Context, log *zap.Logger) error

Jump to

Keyboard shortcuts

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