Skip to content

Commit db57ba9

Browse files
committed
sandbox: only pull images if not present
1 parent ac3e19c commit db57ba9

File tree

1 file changed

+16
-7
lines changed

1 file changed

+16
-7
lines changed

sandbox/sandbox.go

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -42,11 +42,12 @@ import (
4242
)
4343

4444
var (
45-
listenAddr = flag.String("listen", ":80", "HTTP server listen address. Only applicable when --mode=server")
46-
mode = flag.String("mode", "server", "Whether to run in \"server\" mode or \"contained\" mode. The contained mode is used internally by the server mode.")
47-
dev = flag.Bool("dev", false, "run in dev mode (show help messages)")
48-
numWorkers = flag.Int("workers", runtime.NumCPU(), "number of parallel gvisor containers to pre-spin up & let run concurrently")
49-
container = flag.String("untrusted-container", "gcr.io/golang-org/playground-sandbox-gvisor:latest", "container image name that hosts the untrusted binary under gvisor")
45+
listenAddr = flag.String("listen", ":80", "HTTP server listen address. Only applicable when --mode=server")
46+
mode = flag.String("mode", "server", "Whether to run in \"server\" mode or \"contained\" mode. The contained mode is used internally by the server mode.")
47+
dev = flag.Bool("dev", false, "run in dev mode (show help messages)")
48+
numWorkers = flag.Int("workers", runtime.NumCPU(), "number of parallel gvisor containers to pre-spin up & let run concurrently")
49+
container = flag.String("untrusted-container", "gcr.io/golang-org/playground-sandbox-gvisor:latest", "container image name that hosts the untrusted binary under gvisor")
50+
allowImageUpdate = flag.Bool("allow-image-update", true, "Allow docker image update. If not allowed, only pull images if not present.")
5051
)
5152

5253
const (
@@ -143,8 +144,16 @@ func main() {
143144
log.Printf("Running in dev mode; container published to host at: http://localhost:8080/")
144145
log.Printf("Run a binary with: curl -v --data-binary @/home/bradfitz/hello http://localhost:8080/run\n")
145146
} else {
146-
if out, err := exec.Command("docker", "pull", *container).CombinedOutput(); err != nil {
147-
log.Fatalf("error pulling %s: %v, %s", *container, err, out)
147+
if *allowImageUpdate {
148+
if out, err := exec.Command("docker", "pull", *container).CombinedOutput(); err != nil {
149+
log.Fatalf("error pulling %s: %v, %s", *container, err, out)
150+
}
151+
} else {
152+
if _, err := exec.Command("docker", "images", "-q", *container).CombinedOutput(); err != nil {
153+
if out, err := exec.Command("docker", "pull", *container).CombinedOutput(); err != nil {
154+
log.Fatalf("error pulling %s: %v, %s", *container, err, out)
155+
}
156+
}
148157
}
149158
log.Printf("Listening on %s", *listenAddr)
150159
}

0 commit comments

Comments
 (0)