run: trigger a job through the engine like a service

`docker compose run <job>` triggers a run of the job on the engine,
starts its dependencies first, streams its logs and returns its exit
code like a one-off service; a job accepts manual triggering unless it
declares manual: false. A scheduled job runs as up registered it: an
override, or a job up never registered, is refused. A manual job is
removed from the engine after its run, so the next run can differ. When
the engine cannot run jobs, run falls back to a one-off service with a
warning. --detach is refused, an interrupted run is cancelled, a dry run
only reports it. A job named by create, start, build, pull or push gets
an error naming run instead.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Signed-off-by: Guillaume Lours <glours@users.noreply.github.com>
This commit is contained in:
Guillaume Lours 2026-11-10 16:47:28 +01:00 • committed by Nicolas De loof
parent 723ce2bf4e
commit 0aff61809c
19 changed files with 1232 additions and 74 deletions

View file

@ -176,6 +176,23 @@ type ImageManager interface {
type Runner interface {
// RunOneOffContainer creates a service oneoff container and starts its dependencies
RunOneOffContainer(ctx context.Context, project *types.Project, opts RunOptions) (int, error)
// RunJob triggers a Run of the job on the engine's jobs API, starts its
// dependencies first, streams the logs and returns the Run's exit code
// (124 on timeout, 130 when cancelled). A manual job goes through
// CreateAndRun; a scheduled job is run as `up` or `create` registered it: an
// override in options, or a job the engine does not know, is an error. The job must already be in
// project.Services, the way the CLI materializes it, and options.Service
// must be name. options carries the same CLI overrides RunOneOffContainer
// accepts (User, Command, Entrypoint, WorkingDir, CapAdd/CapDrop,
// Environment, Labels, NoDeps). Name has no effect: the jobs API assigns the
// run container's identity itself. A manual job is registered under the
// project and job name and removed when its run ends, so concurrent runs of
// the same manual job are not supported: the first to end cancels the others.
// Detach is refused, a run is waited for;
// a dry run starts the dependencies and stops there. When the engine cannot
// run jobs, the error wraps ErrJobsNotSupported and nothing was done, so the
// caller can fall back to RunOneOffContainer.
RunJob(ctx context.Context, project *types.Project, name string, options RunOptions) (int, error)
// Exec executes a command in a running service container
Exec(ctx context.Context, projectName string, options RunOptions) (int, error)
// Attach STDIN,STDOUT,STDERR to a running service container

View file

@ -65,6 +65,9 @@ var (
// ErrInvalidOption is returned when an option is set to a value it does
// not accept. See InvalidOptionError.
ErrInvalidOption = errors.New("invalid option")
// ErrJobsNotSupported is returned when a job operation requires an engine with usable jobs support (the jobs API and its extension enabled)
ErrJobsNotSupported = errors.New("jobs are not supported by the engine")
)
// IsNotFoundError returns true if the unwrapped error is ErrNotFound