feat(setup): build start and verify ThothII
This commit is contained in:
@@ -9,6 +9,8 @@ import (
|
||||
"io"
|
||||
"os"
|
||||
"os/exec"
|
||||
|
||||
"github.com/aritmolab/thothii/tools/tht/internal/config"
|
||||
)
|
||||
|
||||
// Result is the captured output and process exit code for one Docker invocation.
|
||||
@@ -18,8 +20,13 @@ type Result struct {
|
||||
ExitCode int
|
||||
}
|
||||
|
||||
// Runner executes the Docker CLI. It never invokes a shell.
|
||||
type Runner struct {
|
||||
// Runner is the shell-free Docker command boundary used by the host CLI.
|
||||
type Runner interface {
|
||||
Run(context.Context, []string, io.Reader) (Result, error)
|
||||
}
|
||||
|
||||
// execRunner executes the Docker CLI. It never invokes a shell.
|
||||
type execRunner struct {
|
||||
binary string
|
||||
}
|
||||
|
||||
@@ -28,11 +35,11 @@ func NewRunner(binary string) Runner {
|
||||
if binary == "" {
|
||||
binary = "docker"
|
||||
}
|
||||
return Runner{binary: binary}
|
||||
return execRunner{binary: binary}
|
||||
}
|
||||
|
||||
// Run invokes Docker with the supplied argument array and optional standard input.
|
||||
func (r Runner) Run(ctx context.Context, args []string, stdin io.Reader) (Result, error) {
|
||||
func (r execRunner) Run(ctx context.Context, args []string, stdin io.Reader) (Result, error) {
|
||||
command := exec.CommandContext(ctx, r.binary, args...)
|
||||
command.Stdin = stdin
|
||||
var stdout, stderr bytes.Buffer
|
||||
@@ -54,3 +61,26 @@ func (r Runner) Run(ctx context.Context, args []string, stdin io.Reader) (Result
|
||||
}
|
||||
return result, err
|
||||
}
|
||||
|
||||
// InstallationRunner applies an installation's validated Compose arguments to commands that
|
||||
// explicitly start with compose. Direct Docker image commands remain host-side.
|
||||
type InstallationRunner struct {
|
||||
Installation config.Installation
|
||||
Runner Runner
|
||||
}
|
||||
|
||||
// SessionInventoryScope supplies the installation's intended visibility to lifecycle callers.
|
||||
func (r InstallationRunner) SessionInventoryScope() string {
|
||||
if r.Installation.Profile == "local" {
|
||||
return "mine"
|
||||
}
|
||||
return "all"
|
||||
}
|
||||
|
||||
// Run transforms only Compose invocations. It never performs shell interpolation.
|
||||
func (r InstallationRunner) Run(ctx context.Context, args []string, stdin io.Reader) (Result, error) {
|
||||
if len(args) > 0 && args[0] == "compose" {
|
||||
return r.Runner.Run(ctx, r.Installation.ComposeArgs(args[1:]...), stdin)
|
||||
}
|
||||
return r.Runner.Run(ctx, args, stdin)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user