1 // Copyright (C) The Arvados Authors. All rights reserved.
3 // SPDX-License-Identifier: AGPL-3.0
18 "github.com/docker/docker/api/types"
19 "github.com/docker/docker/client"
22 // sourcesfile=/tmp/sources.conf.d-arvados
23 // echo >$sourcesfile "deb [trusted=yes] file:///pkg ./"
25 // installimage="arvados-installpackage-${osbase}"
26 // if [[ "${opts[force-installimage]}" || -z "$(docker images --format {{.Repository}} "${installimage}")" ]]; then
27 // echo >&2 building ${installimage}...
28 // installctr=${installimage/:/-}
29 // docker rm "${installctr}" || true
31 // --name "${installctr}" \
33 // -v /tmp/pkg:/pkg:ro \
34 // -v ${sourcesfile}:/etc/apt/sources.list.d/arvados-local.list:ro \
35 // --env DEBIAN_FRONTEND=noninteractive \
37 // bash -c 'apt update && apt install -y eatmydata && eatmydata apt install -y arvados-server-easy postgresql && eatmydata apt remove -y arvados-server-easy'
38 // docker commit "${installctr}" "${installimage}"
39 // docker rm "${installctr}"
43 func testinstall(ctx context.Context, opts opts, stdin io.Reader, stdout, stderr io.Writer) error {
44 if opts.PackageVersion != "" {
45 return errors.New("not implemented: package version was specified, but I only know how to test the latest version in pkgdir")
47 depsImageName := "arvados-package-deps-" + opts.TargetOS
48 depsCtrName := strings.Replace(depsImageName, ":", "-", -1)
50 _, prog := filepath.Split(os.Args[0])
51 tmpdir, err := ioutil.TempDir("", prog+".")
53 return fmt.Errorf("TempDir: %w", err)
55 defer os.RemoveAll(tmpdir)
57 sourcesFile := tmpdir + "/arvados-local.list"
58 err = ioutil.WriteFile(sourcesFile, []byte("deb [trusted=yes] file:///pkg ./\n"), 0644)
60 return fmt.Errorf("Write %s: %w", sourcesFile, err)
63 if exists, err := dockerImageExists(ctx, depsImageName); err != nil {
65 } else if !exists || opts.RebuildImage {
66 err = dockerRm(ctx, depsCtrName)
70 defer dockerRm(ctx, depsCtrName)
71 cmd := exec.CommandContext(ctx, "docker", "run",
72 "--name", depsCtrName,
73 "--tmpfs", "/tmp:exec,mode=01777",
74 "-v", opts.PackageDir+":/pkg:ro",
75 "-v", sourcesFile+":/etc/apt/sources.list.d/arvados-local.list:ro",
76 "--env", "DEBIAN_FRONTEND=noninteractive",
81 apt-get install -y eatmydata
82 eatmydata apt-get install -y --no-install-recommends arvados-server-easy postgresql
83 eatmydata apt-get remove -y arvados-server-easy
89 return fmt.Errorf("docker run: %w", err)
92 cmd = exec.CommandContext(ctx, "docker", "commit", depsCtrName, depsImageName)
97 return fmt.Errorf("docker commit: %w", err)
101 cmd := exec.CommandContext(ctx, "docker", "run", "--rm",
102 "--tmpfs", "/tmp:exec,mode=01777",
103 "-v", opts.PackageDir+":/pkg:ro",
104 "-v", sourcesFile+":/etc/apt/sources.list.d/arvados-local.list:ro",
105 "--env", "DEBIAN_FRONTEND=noninteractive",
109 PATH="/var/lib/arvados/bin:$PATH"
111 eatmydata apt-get install --reinstall -y --no-install-recommends arvados-server-easy
112 apt-get -y autoremove
113 /etc/init.d/postgresql start
114 arvados-server init -cluster-id x1234
115 exec arvados-server boot -listen-host 0.0.0.0 -shutdown
121 return fmt.Errorf("docker run: %w", err)
126 func dockerImageExists(ctx context.Context, name string) (bool, error) {
127 cli, err := client.NewEnvClient()
131 imgs, err := cli.ImageList(ctx, types.ImageListOptions{All: true})
135 for _, img := range imgs {
136 for _, tag := range img.RepoTags {