17344: Load alpine docker image for diagnostics.
authorTom Clegg <tom@curii.com>
Tue, 12 Jul 2022 19:31:41 +0000 (15:31 -0400)
committerTom Clegg <tom@curii.com>
Thu, 14 Jul 2022 13:21:41 +0000 (09:21 -0400)
Arvados-DCO-1.1-Signed-off-by: Tom Clegg <tom@curii.com>

lib/diagnostics/cmd.go
lib/install/init.go

index 71fe1c5dc60c8501353da59f5f49df31a2f7f805..467c2f0b51ad29d46bc0892a8f9f596108da8951 100644 (file)
@@ -30,6 +30,7 @@ func (Command) RunCommand(prog string, args []string, stdin io.Reader, stdout, s
        f := flag.NewFlagSet(prog, flag.ContinueOnError)
        f.StringVar(&diag.projectName, "project-name", "scratch area for diagnostics", "name of project to find/create in home project and use for temporary/test objects")
        f.StringVar(&diag.logLevel, "log-level", "info", "logging level (debug, info, warning, error)")
        f := flag.NewFlagSet(prog, flag.ContinueOnError)
        f.StringVar(&diag.projectName, "project-name", "scratch area for diagnostics", "name of project to find/create in home project and use for temporary/test objects")
        f.StringVar(&diag.logLevel, "log-level", "info", "logging level (debug, info, warning, error)")
+       f.StringVar(&diag.dockerImage, "docker-image", "alpine:latest", "image to use when running a test container")
        f.BoolVar(&diag.checkInternal, "internal-client", false, "check that this host is considered an \"internal\" client")
        f.BoolVar(&diag.checkExternal, "external-client", false, "check that this host is considered an \"external\" client")
        f.IntVar(&diag.priority, "priority", 500, "priority for test container (1..1000, or 0 to skip)")
        f.BoolVar(&diag.checkInternal, "internal-client", false, "check that this host is considered an \"internal\" client")
        f.BoolVar(&diag.checkExternal, "external-client", false, "check that this host is considered an \"external\" client")
        f.IntVar(&diag.priority, "priority", 500, "priority for test container (1..1000, or 0 to skip)")
@@ -60,6 +61,7 @@ type diagnoser struct {
        logLevel      string
        priority      int
        projectName   string
        logLevel      string
        priority      int
        projectName   string
+       dockerImage   string
        checkInternal bool
        checkExternal bool
        timeout       time.Duration
        checkInternal bool
        checkExternal bool
        timeout       time.Duration
@@ -545,7 +547,7 @@ func (diag *diagnoser) runtests() {
                err := client.RequestAndDecodeContext(ctx, &cr, "POST", "arvados/v1/container_requests", nil, map[string]interface{}{"container_request": map[string]interface{}{
                        "owner_uuid":      project.UUID,
                        "name":            fmt.Sprintf("diagnostics container request %s", timestamp),
                err := client.RequestAndDecodeContext(ctx, &cr, "POST", "arvados/v1/container_requests", nil, map[string]interface{}{"container_request": map[string]interface{}{
                        "owner_uuid":      project.UUID,
                        "name":            fmt.Sprintf("diagnostics container request %s", timestamp),
-                       "container_image": "arvados/jobs",
+                       "container_image": diag.dockerImage,
                        "command":         []string{"echo", timestamp},
                        "use_existing":    false,
                        "output_path":     "/mnt/output",
                        "command":         []string{"echo", timestamp},
                        "use_existing":    false,
                        "output_path":     "/mnt/output",
index 11a62f18e98c8a37bf79e962b811c74d40c7033c..3eeac5c54984c101587e4df93d72b2a3adf643ab 100644 (file)
@@ -351,6 +351,29 @@ func (initcmd *initCommand) RunCommand(prog string, args []string, stdin io.Read
                fmt.Fprintln(stderr, "...looks good")
        }
 
                fmt.Fprintln(stderr, "...looks good")
        }
 
+       if out, err := exec.CommandContext(ctx, "docker", "version").CombinedOutput(); err == nil && strings.Contains(string(out), "\nServer:\n") {
+               fmt.Fprintln(stderr, "loading alpine docker image for diagnostics...")
+               cmd := exec.CommandContext(ctx, "docker", "pull", "alpine")
+               cmd.Stdout = stderr
+               cmd.Stderr = stderr
+               err = cmd.Run()
+               if err != nil {
+                       err = fmt.Errorf("%v: %w", cmd.Args, err)
+                       return 1
+               }
+               cmd = exec.CommandContext(ctx, "arv", "root", "keep", "docker", "alpine")
+               cmd.Stdout = stderr
+               cmd.Stderr = stderr
+               err = cmd.Run()
+               if err != nil {
+                       err = fmt.Errorf("%v: %w", cmd.Args, err)
+                       return 1
+               }
+               fmt.Fprintln(stderr, "...done")
+       } else {
+               fmt.Fprintln(stderr, "docker is not installed -- skipping step of downloading 'alpine' image")
+       }
+
        fmt.Fprintln(stderr, "Setup complete. You should now be able to log in to workbench2 at", cluster.Services.Workbench2.ExternalURL.String())
 
        return 0
        fmt.Fprintln(stderr, "Setup complete. You should now be able to log in to workbench2 at", cluster.Services.Workbench2.ExternalURL.String())
 
        return 0