Sketch inception wiring: make it easier to run unsafe sketch inside Sketch
By renaming the api key env variable, you can run "sketch -unsafe"
both with and without skaband without removing /.dockerenv and
re-writing env variables. Previously this was painful. We're using
"--outside-hostname" to indicate the fact that we're an "inside sketch".
diff --git a/cmd/sketch/main.go b/cmd/sketch/main.go
index 183aef0..3090d5a 100644
--- a/cmd/sketch/main.go
+++ b/cmd/sketch/main.go
@@ -103,14 +103,8 @@
flagArgs.gitEmail = defaultGitEmail()
}
- // Detect if we're running inside Docker
- inDocker := false
- if _, err := os.Stat("/.dockerenv"); err == nil {
- inDocker = true
- }
-
- // Detect if we're inside the sketch container with access to outside environment
- inInsideSketch := inDocker && flagArgs.outsideHostname != ""
+ // Detect if we're inside the sketch container
+ inInsideSketch := flagArgs.outsideHostname != ""
// Validate initial commit and unsafe flag combination
if flagArgs.unsafe && flagArgs.initialCommit != "HEAD" {
@@ -118,9 +112,9 @@
}
// Dispatch to the appropriate execution path
- if inDocker {
+ if inInsideSketch {
// We're running inside the Docker container
- return runInContainerMode(ctx, flagArgs, inInsideSketch, logFile)
+ return runInContainerMode(ctx, flagArgs, logFile)
} else if flagArgs.unsafe {
// We're running directly on the host in unsafe mode
return runInUnsafeMode(ctx, flagArgs, logFile)
@@ -280,16 +274,16 @@
// runInContainerMode handles execution inside the Docker container.
// The inInsideSketch parameter indicates whether we're inside the sketch container
// with access to outside environment variables.
-func runInContainerMode(ctx context.Context, flags CLIFlags, inInsideSketch bool, logFile *os.File) error {
+func runInContainerMode(ctx context.Context, flags CLIFlags, logFile *os.File) error {
// Get credentials from environment
- apiKey := os.Getenv("ANTHROPIC_API_KEY")
+ apiKey := os.Getenv("SKETCH_ANTHROPIC_API_KEY")
pubKey := os.Getenv("SKETCH_PUB_KEY")
- antURL, err := skabandclient.LocalhostToDockerInternal(os.Getenv("ANT_URL"))
- if err != nil && os.Getenv("ANT_URL") != "" {
+ antURL, err := skabandclient.LocalhostToDockerInternal(os.Getenv("SKETCH_ANT_URL"))
+ if err != nil && os.Getenv("SKETCH_ANT_URL") != "" {
return err
}
- return setupAndRunAgent(ctx, flags, antURL, apiKey, pubKey, inInsideSketch, logFile)
+ return setupAndRunAgent(ctx, flags, antURL, apiKey, pubKey, true, logFile)
}
// runInUnsafeMode handles execution on the host machine without Docker.
diff --git a/dockerimg/dockerimg.go b/dockerimg/dockerimg.go
index 1486435..722e3e6 100644
--- a/dockerimg/dockerimg.go
+++ b/dockerimg/dockerimg.go
@@ -421,14 +421,14 @@
"-it",
"--name", cntrName,
"-p", hostPort + ":80", // forward container port 80 to a host port
- "-e", "ANTHROPIC_API_KEY=" + config.AntAPIKey,
+ "-e", "SKETCH_ANTHROPIC_API_KEY=" + config.AntAPIKey,
}
for _, envVar := range getEnvForwardingFromGitConfig(ctx) {
cmdArgs = append(cmdArgs, "-e", envVar)
}
if config.AntURL != "" {
- cmdArgs = append(cmdArgs, "-e", "ANT_URL="+config.AntURL)
+ cmdArgs = append(cmdArgs, "-e", "SKETCH_ANT_URL="+config.AntURL)
}
if config.SketchPubKey != "" {
cmdArgs = append(cmdArgs, "-e", "SKETCH_PUB_KEY="+config.SketchPubKey)