1 // Copyright (C) The Arvados Authors. All rights reserved.
3 // SPDX-License-Identifier: AGPL-3.0
16 "git.arvados.org/arvados.git/lib/install"
19 func fpm(ctx context.Context, opts opts, stdin io.Reader, stdout, stderr io.Writer) error {
20 var chownUid, chownGid int
21 if opts.PackageChown != "" {
22 _, err := fmt.Sscanf(opts.PackageChown, "%d:%d", &chownUid, &chownGid)
24 return fmt.Errorf("invalid value %q for PackageChown: %w", opts.PackageChown, err)
28 exitcode := install.Command.RunCommand("arvados-server install", []string{
30 "-package-version", opts.PackageVersion,
31 "-source", opts.SourceDir,
32 }, stdin, stdout, stderr)
34 return fmt.Errorf("arvados-server install failed: exit code %d", exitcode)
37 cmd := exec.Command("/var/lib/arvados/bin/gem", "install", "--user", "--no-document", "fpm")
42 return fmt.Errorf("gem install fpm: %w", err)
45 cmd = exec.Command("/var/lib/arvados/bin/gem", "env", "gempath")
47 buf, err := cmd.Output() // /root/.gem/ruby/2.7.0:...
48 if err != nil || len(buf) == 0 {
49 return fmt.Errorf("gem env gempath: %w", err)
51 gempath := string(bytes.TrimRight(bytes.Split(buf, []byte{':'})[0], "\n"))
53 if _, err := os.Stat(gempath + "/gems/fpm-1.11.0/lib/fpm/package/deb.rb"); err == nil {
54 // Workaround for fpm bug https://github.com/jordansissel/fpm/issues/1739
55 cmd = exec.Command("sed", "-i", `/require "digest"/a require "zlib"`, gempath+"/gems/fpm-1.11.0/lib/fpm/package/deb.rb")
60 return fmt.Errorf("monkeypatch fpm: %w", err)
64 // Remove unneeded files. This is much faster than "fpm
65 // --exclude X" because fpm copies everything into a staging
66 // area before looking at the --exclude args.
67 cmd = exec.Command("bash", "-c", "cd /var/www/.gem/ruby && rm -rf */cache */bundler/gems/*/.git */bundler/gems/arvados-*/[^s]* */bundler/gems/arvados-*/s[^d]* */bundler/gems/arvados-*/sdk/[^cr]* */gems/passenger-*/src/cxx* ruby/*/gems/*/ext /var/lib/arvados/go")
72 return fmt.Errorf("rm -rf [...]: %w", err)
75 format := "deb" // TODO: rpm
76 pkgfile := filepath.Join(opts.PackageDir, "arvados-server-easy_"+opts.PackageVersion+"_amd64."+format)
78 cmd = exec.Command(gempath+"/bin/fpm",
80 "--name", "arvados-server-easy",
81 "--version", opts.PackageVersion,
82 "--url", "https://arvados.org",
83 "--maintainer", opts.Maintainer,
84 "--vendor", opts.Vendor,
85 "--license", "GNU Affero General Public License, version 3.0",
86 "--description", "platform for managing, processing, and sharing genomic and other large scientific and biomedical data",
87 "--input-type", "dir",
88 "--output-type", format)
89 deps, err := install.ProductionDependencies()
93 for _, pkg := range deps {
94 cmd.Args = append(cmd.Args, "--depends", pkg)
96 cmd.Args = append(cmd.Args,
98 "--deb-use-file-permissions",
99 "--rpm-use-file-permissions",
102 "/var/www/.passenger",
105 fmt.Fprintf(stderr, "... %s\n", cmd.Args)
106 cmd.Dir = opts.PackageDir
111 return fmt.Errorf("fpm: %w", err)
114 if opts.PackageChown != "" {
115 err = os.Chown(pkgfile, chownUid, chownGid)
117 return fmt.Errorf("chown %s: %w", pkgfile, err)
121 cmd = exec.Command("ls", "-l", pkgfile)