feat: control systemd Docker daemon target
This commit is contained in:
+17
-2
@@ -9,6 +9,7 @@ import (
|
||||
tea "github.com/charmbracelet/bubbletea"
|
||||
|
||||
"proxyctl/internal/app"
|
||||
"proxyctl/internal/dockerdaemon"
|
||||
"proxyctl/internal/profile"
|
||||
"proxyctl/internal/shell"
|
||||
"proxyctl/internal/target"
|
||||
@@ -23,11 +24,17 @@ func main() {
|
||||
}
|
||||
|
||||
func run(args []string, input io.Reader, output io.Writer) error {
|
||||
return runWithSystemTargets(args, input, output, nil)
|
||||
}
|
||||
|
||||
// runWithSystemTargets keeps process smoke tests hermetic. A nil slice selects
|
||||
// production system Targets; a non-nil slice supplies fakes (or no Targets).
|
||||
func runWithSystemTargets(args []string, input io.Reader, output io.Writer, systemTargets []target.Target) error {
|
||||
executable, err := os.Executable()
|
||||
if err != nil {
|
||||
return fmt.Errorf("locate proxyctl executable: %w", err)
|
||||
}
|
||||
return runWithEnvironment(args, input, output, processEnvironment{}, nil, executable)
|
||||
return runWithEnvironmentAndTargets(args, input, output, processEnvironment{}, nil, executable, systemTargets)
|
||||
}
|
||||
|
||||
type processEnvironment struct{}
|
||||
@@ -41,6 +48,10 @@ func (processEnvironment) LookupUser(name string) (profile.UserIdentity, error)
|
||||
func (processEnvironment) LookupEnv(name string) (string, bool) { return os.LookupEnv(name) }
|
||||
|
||||
func runWithEnvironment(args []string, input io.Reader, output io.Writer, environment profile.IdentityEnvironment, files shell.FileSystem, executable string) error {
|
||||
return runWithEnvironmentAndTargets(args, input, output, environment, files, executable, nil)
|
||||
}
|
||||
|
||||
func runWithEnvironmentAndTargets(args []string, input io.Reader, output io.Writer, environment profile.IdentityEnvironment, files shell.FileSystem, executable string, systemTargets []target.Target) error {
|
||||
profileConfiguration, err := profile.ResolveConfiguration(environment)
|
||||
if err != nil {
|
||||
return err
|
||||
@@ -74,7 +85,11 @@ func runWithEnvironment(args []string, input io.Reader, output io.Writer, enviro
|
||||
}
|
||||
|
||||
store := profile.NewOwnedFileStoreAt(profileConfiguration.Path, profileConfiguration.Owner, profileConfiguration.TrustedRoot)
|
||||
application, err := app.NewWithTargets(store, []target.Target{shellTarget})
|
||||
if systemTargets == nil {
|
||||
systemTargets = []target.Target{dockerdaemon.New(dockerdaemon.DefaultConfiguration(), nil, nil)}
|
||||
}
|
||||
targets := append([]target.Target{shellTarget}, systemTargets...)
|
||||
application, err := app.NewWithTargets(store, targets)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user