19175: Merge branch 'main' into 19175-doc-refactor-multi-host-installation
[arvados.git] / sdk / go / arvadostest / busybox_image.go
1 // Copyright (C) The Arvados Authors. All rights reserved.
2 //
3 // SPDX-License-Identifier: AGPL-3.0
4
5 package arvadostest
6
7 import (
8         "io"
9         "io/ioutil"
10         "net/http"
11         "os"
12
13         . "gopkg.in/check.v1"
14 )
15
16 // BusyboxDockerImage downloads the busybox:uclibc docker image
17 // (busybox_uclibc.tar) from cache.arvados.org into a temporary file
18 // and returns the temporary file name.
19 func BusyboxDockerImage(c *C) string {
20         fnm := "busybox_uclibc.tar"
21         cachedir := c.MkDir()
22         cachefile := cachedir + "/" + fnm
23         if _, err := os.Stat(cachefile); err == nil {
24                 return cachefile
25         }
26
27         f, err := ioutil.TempFile(cachedir, "")
28         c.Assert(err, IsNil)
29         defer f.Close()
30         defer os.Remove(f.Name())
31
32         resp, err := http.Get("https://cache.arvados.org/" + fnm)
33         c.Assert(err, IsNil)
34         defer resp.Body.Close()
35         _, err = io.Copy(f, resp.Body)
36         c.Assert(err, IsNil)
37         err = f.Close()
38         c.Assert(err, IsNil)
39         err = os.Rename(f.Name(), cachefile)
40         c.Assert(err, IsNil)
41
42         return cachefile
43 }