20846: Merge branch 'main' into 20846-ruby3
[arvados.git] / lib / install / deps.go
index fc0062cd754b032101dc0f7cdad6052373d3b95c..7b32984348346b24e4a2106b94dba8a1582bbd8a 100644 (file)
@@ -49,6 +49,7 @@ var arvadosServiceFile []byte
 type installCommand struct {
        ClusterType    string
        SourcePath     string
+       Commit         string
        PackageVersion string
        EatMyData      bool
 }
@@ -71,6 +72,7 @@ func (inst *installCommand) RunCommand(prog string, args []string, stdin io.Read
        versionFlag := flags.Bool("version", false, "Write version information to stdout and exit 0")
        flags.StringVar(&inst.ClusterType, "type", "production", "cluster `type`: development, test, production, or package")
        flags.StringVar(&inst.SourcePath, "source", "/arvados", "source tree location (required for -type=package)")
+       flags.StringVar(&inst.Commit, "commit", "", "source commit `hash` to embed (blank means use 'git log' or all-zero placeholder)")
        flags.StringVar(&inst.PackageVersion, "package-version", "0.0.0", "version string to embed in executable files")
        flags.BoolVar(&inst.EatMyData, "eatmydata", false, "use eatmydata to speed up install")
 
@@ -80,6 +82,14 @@ func (inst *installCommand) RunCommand(prog string, args []string, stdin io.Read
                return cmd.Version.RunCommand(prog, args, stdin, stdout, stderr)
        }
 
+       if inst.Commit == "" {
+               if commit, err := exec.Command("env", "-C", inst.SourcePath, "git", "log", "-n1", "--format=%H").CombinedOutput(); err == nil {
+                       inst.Commit = strings.TrimSpace(string(commit))
+               } else {
+                       inst.Commit = "0000000000000000000000000000000000000000"
+               }
+       }
+
        var dev, test, prod, pkg bool
        switch inst.ClusterType {
        case "development":
@@ -306,7 +316,8 @@ wget --progress=dot:giga -O- https://cache.ruby-lang.org/pub/ruby/`+rubymajorver
 cd "${tmp}/ruby-`+rubyversion+`"
 ./configure --disable-install-static-library --enable-shared --disable-install-doc --prefix /var/lib/arvados
 make -j8
-make install <(yes || true)
+rm -f /var/lib/arvados/bin/erb
+make install
 /var/lib/arvados/bin/gem update --no-document --system 3.4.21
 /var/lib/arvados/bin/gem install bundler --no-document
 `, stdout, stderr)
@@ -565,7 +576,10 @@ ln -sfv /var/lib/arvados/node-`+nodejsversion+`-linux-x64/bin/{yarn,yarnpkg} /us
                        // container using a non-root-owned git tree
                        // mounted from the host -- as in
                        // "arvados-package build".
-                       cmd := exec.Command("go", "install", "-buildvcs=false", "-ldflags", "-X git.arvados.org/arvados.git/lib/cmd.version="+inst.PackageVersion+" -X main.version="+inst.PackageVersion+" -s -w")
+                       cmd := exec.Command("go", "install", "-buildvcs=false",
+                               "-ldflags", "-s -w"+
+                                       " -X git.arvados.org/arvados.git/lib/cmd.version="+inst.PackageVersion+
+                                       " -X git.arvados.org/arvados.git/lib/cmd.commit="+inst.Commit)
                        cmd.Env = append(cmd.Env, os.Environ()...)
                        cmd.Env = append(cmd.Env, "GOBIN=/var/lib/arvados/bin")
                        cmd.Dir = filepath.Join(inst.SourcePath, srcdir)
@@ -600,94 +614,103 @@ v=/var/lib/arvados/lib/python
 tmp=/var/lib/arvados/tmp/python
 python3 -m venv "$v"
 . "$v/bin/activate"
-pip3 install --no-cache-dir 'setuptools>=18.5' 'pip>=7'
+pip3 install --no-cache-dir 'setuptools>=68' 'pip>=20'
 export ARVADOS_BUILDING_VERSION="`+inst.PackageVersion+`"
 for src in "`+inst.SourcePath+`/sdk/python" "`+inst.SourcePath+`/services/fuse"; do
   rsync -a --delete-after "$src/" "$tmp/"
-  cd "$tmp"
-  python3 setup.py install
-  cd ..
+  env -C "$tmp" python3 setup.py build
+  pip3 install "$tmp"
   rm -rf "$tmp"
 done
 `, stdout, stderr); err != nil {
                        return 1
                }
 
-               // Install Rails apps to /var/lib/arvados/{railsapi,workbench1}/
-               for dstdir, srcdir := range map[string]string{
-                       "railsapi":   "services/api",
-                       "workbench1": "apps/workbench",
+               // Install RailsAPI to /var/lib/arvados/railsapi/
+               fmt.Fprintln(stderr, "building railsapi...")
+               cmd = exec.Command("rsync",
+                       "-a", "--no-owner", "--no-group", "--delete-after", "--delete-excluded",
+                       "--exclude", "/coverage",
+                       "--exclude", "/log",
+                       "--exclude", "/node_modules",
+                       "--exclude", "/tmp",
+                       "--exclude", "/public/assets",
+                       "--exclude", "/vendor",
+                       "--exclude", "/config/environments",
+                       "./", "/var/lib/arvados/railsapi/")
+               cmd.Dir = filepath.Join(inst.SourcePath, "services", "api")
+               cmd.Stdout = stdout
+               cmd.Stderr = stderr
+               err = cmd.Run()
+               if err != nil {
+                       return 1
+               }
+               for _, cmdline := range [][]string{
+                       {"mkdir", "-p", "log", "public/assets", "tmp", "vendor", ".bundle", "/var/www/.bundle", "/var/www/.gem", "/var/www/.npm", "/var/www/.passenger"},
+                       {"touch", "log/production.log"},
+                       {"chown", "-R", "--from=root", "www-data:www-data", "/var/www/.bundle", "/var/www/.gem", "/var/www/.npm", "/var/www/.passenger", "log", "tmp", "vendor", ".bundle", "Gemfile.lock", "config.ru", "config/environment.rb"},
+                       {"sudo", "-u", "www-data", "/var/lib/arvados/bin/gem", "install", "--user", "--conservative", "--no-document", "bundler:" + bundlerversion},
+                       {"sudo", "-u", "www-data", "/var/lib/arvados/bin/bundle", "config", "set", "--local", "deployment", "true"},
+                       {"sudo", "-u", "www-data", "/var/lib/arvados/bin/bundle", "config", "set", "--local", "path", "/var/www/.gem"},
+                       {"sudo", "-u", "www-data", "/var/lib/arvados/bin/bundle", "config", "set", "--local", "without", "development test diagnostics performance"},
+                       {"sudo", "-u", "www-data", "/var/lib/arvados/bin/bundle", "install", "--jobs", fmt.Sprintf("%d", runtime.NumCPU())},
+
+                       {"chown", "www-data:www-data", ".", "public/assets"},
+                       // {"sudo", "-u", "www-data", "/var/lib/arvados/bin/bundle", "config", "set", "--local", "system", "true"},
+                       {"sudo", "-u", "www-data", "ARVADOS_CONFIG=none", "RAILS_GROUPS=assets", "RAILS_ENV=production", "PATH=/var/lib/arvados/bin:" + os.Getenv("PATH"), "/var/lib/arvados/bin/bundle", "exec", "rake", "npm:install"},
+                       {"sudo", "-u", "www-data", "ARVADOS_CONFIG=none", "RAILS_GROUPS=assets", "RAILS_ENV=production", "PATH=/var/lib/arvados/bin:" + os.Getenv("PATH"), "/var/lib/arvados/bin/bundle", "exec", "rake", "assets:precompile"},
+                       {"chown", "root:root", "."},
+                       {"chown", "-R", "root:root", "public/assets", "vendor"},
+
+                       {"sudo", "-u", "www-data", "/var/lib/arvados/bin/bundle", "exec", "passenger-config", "build-native-support"},
+                       {"sudo", "-u", "www-data", "/var/lib/arvados/bin/bundle", "exec", "passenger-config", "install-standalone-runtime"},
                } {
-                       fmt.Fprintf(stderr, "building %s...\n", srcdir)
-                       cmd := exec.Command("rsync",
-                               "-a", "--no-owner", "--no-group", "--delete-after", "--delete-excluded",
-                               "--exclude", "/coverage",
-                               "--exclude", "/log",
-                               "--exclude", "/node_modules",
-                               "--exclude", "/tmp",
-                               "--exclude", "/public/assets",
-                               "--exclude", "/vendor",
-                               "--exclude", "/config/environments",
-                               "./", "/var/lib/arvados/"+dstdir+"/")
-                       cmd.Dir = filepath.Join(inst.SourcePath, srcdir)
-                       cmd.Stdout = stdout
-                       cmd.Stderr = stderr
-                       err = cmd.Run()
-                       if err != nil {
-                               return 1
+                       if cmdline[len(cmdline)-2] == "rake" {
+                               continue
                        }
-                       for _, cmdline := range [][]string{
-                               {"mkdir", "-p", "log", "public/assets", "tmp", "vendor", ".bundle", "/var/www/.bundle", "/var/www/.gem", "/var/www/.npm", "/var/www/.passenger"},
-                               {"touch", "log/production.log"},
-                               {"chown", "-R", "--from=root", "www-data:www-data", "/var/www/.bundle", "/var/www/.gem", "/var/www/.npm", "/var/www/.passenger", "log", "tmp", "vendor", ".bundle", "Gemfile.lock", "config.ru", "config/environment.rb"},
-                               {"sudo", "-u", "www-data", "/var/lib/arvados/bin/gem", "install", "--user", "--conservative", "--no-document", "bundler:" + bundlerversion},
-                               {"sudo", "-u", "www-data", "/var/lib/arvados/bin/bundle", "config", "set", "--local", "deployment", "true"},
-                               {"sudo", "-u", "www-data", "/var/lib/arvados/bin/bundle", "config", "set", "--local", "path", "/var/www/.gem"},
-                               {"sudo", "-u", "www-data", "/var/lib/arvados/bin/bundle", "config", "set", "--local", "without", "development test diagnostics performance"},
-                               {"sudo", "-u", "www-data", "/var/lib/arvados/bin/bundle", "install", "--jobs", fmt.Sprintf("%d", runtime.NumCPU())},
-
-                               {"chown", "www-data:www-data", ".", "public/assets"},
-                               // {"sudo", "-u", "www-data", "/var/lib/arvados/bin/bundle", "config", "set", "--local", "system", "true"},
-                               {"sudo", "-u", "www-data", "ARVADOS_CONFIG=none", "RAILS_GROUPS=assets", "RAILS_ENV=production", "PATH=/var/lib/arvados/bin:" + os.Getenv("PATH"), "/var/lib/arvados/bin/bundle", "exec", "rake", "npm:install"},
-                               {"sudo", "-u", "www-data", "ARVADOS_CONFIG=none", "RAILS_GROUPS=assets", "RAILS_ENV=production", "PATH=/var/lib/arvados/bin:" + os.Getenv("PATH"), "/var/lib/arvados/bin/bundle", "exec", "rake", "assets:precompile"},
-                               {"chown", "root:root", "."},
-                               {"chown", "-R", "root:root", "public/assets", "vendor"},
-
-                               {"sudo", "-u", "www-data", "/var/lib/arvados/bin/bundle", "exec", "passenger-config", "build-native-support"},
-                               {"sudo", "-u", "www-data", "/var/lib/arvados/bin/bundle", "exec", "passenger-config", "install-standalone-runtime"},
-                       } {
-                               if cmdline[len(cmdline)-2] == "rake" && dstdir != "workbench1" {
-                                       continue
-                               }
-                               cmd = exec.Command(cmdline[0], cmdline[1:]...)
-                               cmd.Dir = "/var/lib/arvados/" + dstdir
-                               cmd.Stdout = stdout
-                               cmd.Stderr = stderr
-                               fmt.Fprintf(stderr, "... %s\n", cmd.Args)
-                               err = cmd.Run()
-                               if err != nil {
-                                       return 1
-                               }
-                       }
-                       cmd = exec.Command("sudo", "-u", "www-data", "/var/lib/arvados/bin/bundle", "exec", "passenger-config", "validate-install")
-                       cmd.Dir = "/var/lib/arvados/" + dstdir
+                       cmd = exec.Command(cmdline[0], cmdline[1:]...)
+                       cmd.Dir = "/var/lib/arvados/railsapi"
                        cmd.Stdout = stdout
                        cmd.Stderr = stderr
+                       fmt.Fprintf(stderr, "... %s\n", cmd.Args)
                        err = cmd.Run()
-                       if err != nil && !strings.Contains(err.Error(), "exit status 2") {
-                               // Exit code 2 indicates there were warnings (like
-                               // "other passenger installations have been detected",
-                               // which we can't expect to avoid) but no errors.
-                               // Other non-zero exit codes (1, 9) indicate errors.
+                       if err != nil {
                                return 1
                        }
                }
+               cmd = exec.Command("sudo", "-u", "www-data", "/var/lib/arvados/bin/bundle", "exec", "passenger-config", "validate-install")
+               cmd.Dir = "/var/lib/arvados/railsapi"
+               cmd.Stdout = stdout
+               cmd.Stderr = stderr
+               err = cmd.Run()
+               if err != nil && !strings.Contains(err.Error(), "exit status 2") {
+                       // Exit code 2 indicates there were warnings (like
+                       // "other passenger installations have been detected",
+                       // which we can't expect to avoid) but no errors.
+                       // Other non-zero exit codes (1, 9) indicate errors.
+                       return 1
+               }
 
-               // Install workbench2 app to /var/lib/arvados/workbench2/
+               // Install workbench2 app to
+               // /var/lib/arvados/workbench2/.
+               //
+               // We copy the source tree from the (possibly
+               // readonly) source tree into a temp dir because `yarn
+               // build` writes to {source-tree}/build/. When we
+               // upgrade to react-scripts >= 4.0.2 we may be able to
+               // build from the source dir and write directly to the
+               // final destination (using
+               // YARN_INSTALL_STATE_PATH=/dev/null
+               // BUILD_PATH=/var/lib/arvados/workbench2) instead of
+               // using two rsync steps here.
                if err = inst.runBash(`
-cd `+inst.SourcePath+`/services/workbench2
-VERSION="`+inst.PackageVersion+`" BUILD_NUMBER=1 GIT_COMMIT=000000000 yarn build
-rsync -a --delete-after build/ /var/lib/arvados/workbench2/
+src="`+inst.SourcePath+`/services/workbench2"
+tmp=/var/lib/arvados/tmp/workbench2
+trap "rm -r ${tmp}" ERR EXIT
+dst=/var/lib/arvados/workbench2
+rsync -a --delete-after "$src/" "$tmp/"
+env -C "$tmp" VERSION="`+inst.PackageVersion+`" BUILD_NUMBER=1 GIT_COMMIT="`+inst.Commit[:9]+`" yarn build
+rsync -a --delete-after "$tmp/build/" "$dst/"
 `, stdout, stderr); err != nil {
                        return 1
                }