1 // Copyright (C) The Arvados Authors. All rights reserved.
3 // SPDX-License-Identifier: AGPL-3.0
17 "git.arvados.org/arvados.git/lib/crunchrun"
18 "github.com/docker/docker/api/types"
19 "github.com/docker/docker/client"
22 func testinstall(ctx context.Context, opts opts, stdin io.Reader, stdout, stderr io.Writer) error {
23 depsImageName := "arvados-package-deps-" + opts.TargetOS
24 depsCtrName := strings.Replace(depsImageName, ":", "-", -1)
25 absPackageDir, err := filepath.Abs(opts.PackageDir)
27 return fmt.Errorf("error resolving PackageDir %q: %w", opts.PackageDir, err)
30 _, prog := filepath.Split(os.Args[0])
31 tmpdir, err := ioutil.TempDir("", prog+".")
33 return fmt.Errorf("TempDir: %w", err)
35 defer os.RemoveAll(tmpdir)
37 if exists, err := dockerImageExists(ctx, depsImageName); err != nil {
39 } else if !exists || opts.RebuildImage {
40 err = dockerRm(ctx, depsCtrName)
44 defer dockerRm(ctx, depsCtrName)
45 cmd := exec.CommandContext(ctx, "docker", "run",
46 "--name", depsCtrName,
47 "--tmpfs", "/tmp:exec,mode=01777",
48 "-v", absPackageDir+":/pkg:ro",
49 "--env", "DEBIAN_FRONTEND=noninteractive",
53 apt-get --allow-releaseinfo-change update
54 apt-get install -y --no-install-recommends dpkg-dev eatmydata
57 ln -s /pkg/*.deb /tmp/pkg/
58 (cd /tmp/pkg; dpkg-scanpackages --multiversion . | gzip > Packages.gz)
59 echo >/etc/apt/sources.list.d/arvados-local.list "deb [trusted=yes] file:///tmp/pkg ./"
60 apt-get --allow-releaseinfo-change update
62 eatmydata apt-get install -y --no-install-recommends arvados-server-easy postgresql
63 eatmydata apt-get remove -y dpkg-dev
64 SUDO_FORCE_REMOVE=yes apt-get autoremove -y
65 eatmydata apt-get remove -y arvados-server-easy
66 rm /etc/apt/sources.list.d/arvados-local.list
72 return fmt.Errorf("%v: %w", cmd.Args, err)
75 cmd = exec.CommandContext(ctx, "docker", "commit", depsCtrName, depsImageName)
80 return fmt.Errorf("%v: %w", cmd.Args, err)
85 if opts.PackageVersion != "" {
86 versionsuffix = "=" + opts.PackageVersion
88 cmd := exec.CommandContext(ctx, "docker", "run", "--rm",
89 "--tmpfs=/tmp:exec,mode=01777",
90 "--volume="+absPackageDir+":/pkg:ro",
91 "--env=DEBIAN_FRONTEND=noninteractive")
93 cmd.Args = append(cmd.Args,
94 "--env=domain="+opts.Live,
95 "--env=initargs=-tls=acme",
98 "--publish=:4440-4460:4440-4460",
99 "--publish=:9000-9020:9000-9020",
100 "--add-host="+opts.Live+":0.0.0.0",
101 "--volume=/var/lib/acme:/var/lib/acme:ro")
103 cmd.Args = append(cmd.Args,
104 "--env=domain=localhost",
105 "--env=initargs=-tls=insecure",
106 "--env=bootargs=-shutdown")
108 cmd.Args = append(cmd.Args,
112 PATH="/var/lib/arvados/bin:$PATH"
113 apt-get --allow-releaseinfo-change update
114 apt-get install -y --no-install-recommends dpkg-dev
116 ln -s /pkg/*.deb /tmp/pkg/
117 (cd /tmp/pkg; dpkg-scanpackages --multiversion . | gzip > Packages.gz)
118 apt-get remove -y dpkg-dev
121 echo >/etc/apt/sources.list.d/arvados-local.list "deb [trusted=yes] file:///tmp/pkg ./"
122 apt-get --allow-releaseinfo-change update
123 eatmydata apt-get install --reinstall -y --no-install-recommends arvados-server-easy`+versionsuffix+`
124 SUDO_FORCE_REMOVE=yes apt-get autoremove -y
126 /etc/init.d/postgresql start
127 arvados-server init -cluster-id x1234 -domain=$domain -login=test -start=false $initargs
128 exec arvados-server boot -listen-host=0.0.0.0 $bootargs
134 return fmt.Errorf("%v: %w", cmd.Args, err)
139 func dockerImageExists(ctx context.Context, name string) (bool, error) {
140 cli, err := client.NewClient(client.DefaultDockerHost, crunchrun.DockerAPIVersion, nil, nil)
144 imgs, err := cli.ImageList(ctx, types.ImageListOptions{All: true})
148 for _, img := range imgs {
149 for _, tag := range img.RepoTags {