feat: control systemd Docker daemon target

This commit is contained in:
proxyctl coordinator
2026-07-17 03:24:52 +08:00
parent 3003450dce
commit be3bbbbe04
11 changed files with 919 additions and 25 deletions
+17 -2
View File
@@ -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
}
+4 -2
View File
@@ -6,12 +6,14 @@ import (
"path/filepath"
"strings"
"testing"
"proxyctl/internal/target"
)
func TestDefaultInvocationStartsTUIWithNoProfileState(t *testing.T) {
t.Setenv("XDG_CONFIG_HOME", t.TempDir())
var output bytes.Buffer
if err := run(nil, strings.NewReader("q"), &output); err != nil {
if err := runWithSystemTargets(nil, strings.NewReader("q"), &output, []target.Target{}); err != nil {
t.Fatalf("run proxyctl: %v", err)
}
if !strings.Contains(output.String(), "No Active Profile") {
@@ -27,7 +29,7 @@ func TestDefaultInvocationLoadsPersistedActiveProfile(t *testing.T) {
"activeProfile": "office"
}`)
var output bytes.Buffer
if err := run(nil, strings.NewReader("q"), &output); err != nil {
if err := runWithSystemTargets(nil, strings.NewReader("q"), &output, []target.Target{}); err != nil {
t.Fatalf("run proxyctl: %v", err)
}
if !strings.Contains(output.String(), "Active Profile: office") {