An open-source, faster Devin alternative
TypeScript
make sure hash functions agree
Brian Reardon64e8b56d7606
diff --git a/cmd/worker/main.go b/cmd/worker/main.goindex ddcd8ff2..c4b14854 100644--- a/cmd/worker/main.go+++ b/cmd/worker/main.go@@ -36,6 +36,26 @@ var AgentVersion = "dev"var WorkerVersion = "dev"func main() {+ // Subcommands that don't need config/secrets. Must short-circuit before+ // LoadSecretsFromKeyVault, which is slow and would fail outside Azure.+ //+ // "golden-version <path>" prints the full-file hash used for golden-image+ // archive keys. Packer invokes this so the archive key matches what+ // ensureCheckpointRebased looks up at runtime.+ if len(os.Args) >= 2 && os.Args[1] == "golden-version" {+ if len(os.Args) != 3 {+ fmt.Fprintln(os.Stderr, "usage: opensandbox-worker golden-version <path-to-base-image>")+ os.Exit(2)+ }+ ver, err := qm.ComputeGoldenVersion(os.Args[2])+ if err != nil {+ fmt.Fprintln(os.Stderr, err)+ os.Exit(1)+ }+ fmt.Println(ver)+ return+ }+// Load secrets from Azure Key Vault if configured (before config.Load reads env vars).if err := config.LoadSecretsFromKeyVault(); err != nil {log.Fatalf("failed to load secrets from Key Vault: %v", err)diff --git a/deploy/packer/worker-ami.pkr.hcl b/deploy/packer/worker-ami.pkr.hclindex 47a26317..8ac15b1a 100644--- a/deploy/packer/worker-ami.pkr.hcl+++ b/deploy/packer/worker-ami.pkr.hcl@@ -242,7 +242,9 @@ build {" echo 'default.ext4 not found — skipping archival'"," exit 0","fi",- "GOLDEN_VER=$(head -c 1048576 /opt/opensandbox/images/default.ext4 | sha256sum | cut -c1-16)",+ "# Use the worker binary's hash function so the archive key matches what",+ "# ensureCheckpointRebased looks up at runtime.",+ "GOLDEN_VER=$(/usr/local/bin/opensandbox-worker golden-version /opt/opensandbox/images/default.ext4)","echo \"Base image golden version: $GOLDEN_VER\"","python3 - <<PYEOF","import http.client, hashlib, hmac, base64, datetime, os, sys",diff --git a/internal/qemu/golden_version.go b/internal/qemu/golden_version.goindex d0e63d2c..2fca2247 100644--- a/internal/qemu/golden_version.go+++ b/internal/qemu/golden_version.go@@ -30,3 +30,10 @@ func computeGoldenVersion(baseImagePath string) (string, error) {}return fmt.Sprintf("%x", h.Sum(nil))[:16], nil}++// ComputeGoldenVersion is the exported entry point used by cmd/worker's+// "golden-version" subcommand so Packer invokes the same hash function+// the runtime uses for archive-key lookups.+func ComputeGoldenVersion(baseImagePath string) (string, error) {+ return computeGoldenVersion(baseImagePath)+}