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", "env", "gempath")
39 buf, err := cmd.Output() // /root/.gem/ruby/2.7.0:...
40 if err != nil || len(buf) == 0 {
41 return fmt.Errorf("gem env gempath: %w", err)
43 gempath := string(bytes.TrimRight(bytes.Split(buf, []byte{':'})[0], "\n"))
45 cmd = exec.Command("/var/lib/arvados/bin/gem", "install", "--user", "--no-document", "fpm")
48 // Avoid "WARNING: You don't have [...] in your PATH, gem
49 // executables will not run"
50 cmd.Env = append(os.Environ(), "PATH="+os.Getenv("PATH")+":"+gempath)
53 return fmt.Errorf("gem install fpm: %w", err)
56 if _, err := os.Stat(gempath + "/gems/fpm-1.11.0/lib/fpm/package/deb.rb"); err == nil {
57 // Workaround for fpm bug https://github.com/jordansissel/fpm/issues/1739
58 cmd = exec.Command("sed", "-i", `/require "digest"/a require "zlib"`, gempath+"/gems/fpm-1.11.0/lib/fpm/package/deb.rb")
63 return fmt.Errorf("monkeypatch fpm: %w", err)
67 // Remove unneeded files. This is much faster than "fpm
68 // --exclude X" because fpm copies everything into a staging
69 // area before looking at the --exclude args.
70 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 /var/lib/arvados/arvados-workbench2 /var/lib/arvados/node-*")
75 return fmt.Errorf("%v: %w", cmd.Args, err)
78 format := "deb" // TODO: rpm
79 pkgfile := filepath.Join(opts.PackageDir, "arvados-server-easy_"+opts.PackageVersion+"_amd64."+format)
81 cmd = exec.Command(gempath+"/bin/fpm",
83 "--name", "arvados-server-easy",
84 "--version", opts.PackageVersion,
85 "--url", "https://arvados.org",
86 "--maintainer", opts.Maintainer,
87 "--vendor", opts.Vendor,
88 "--license", "GNU Affero General Public License, version 3.0",
89 "--description", "platform for managing, processing, and sharing genomic and other large scientific and biomedical data",
90 "--input-type", "dir",
91 "--output-type", format)
92 deps, err := install.ProductionDependencies()
96 for _, pkg := range deps {
97 cmd.Args = append(cmd.Args, "--depends", pkg)
99 cmd.Args = append(cmd.Args,
101 "--deb-use-file-permissions",
102 "--rpm-use-file-permissions",
103 "--deb-systemd", "/lib/systemd/system/arvados.service",
104 "--deb-systemd-enable",
105 "--no-deb-systemd-auto-start",
106 "--no-deb-systemd-restart-after-upgrade",
107 "--deb-suggests", "postgresql",
108 "--deb-suggests", "docker.io",
109 "/usr/bin/arvados-client",
110 "/usr/bin/arvados-server",
116 "/usr/bin/arv-federation-migrate",
118 "/usr/bin/arv-keepdocker",
120 "/usr/bin/arv-migrate-docker19",
121 "/usr/bin/arv-normalize",
124 "/usr/bin/arv-mount",
126 "/var/www/.passenger",
129 fmt.Fprintf(stderr, "... %s\n", cmd.Args)
130 cmd.Dir = opts.PackageDir
135 return fmt.Errorf("fpm: %w", err)
138 if opts.PackageChown != "" {
139 err = os.Chown(pkgfile, chownUid, chownGid)
141 return fmt.Errorf("chown %s: %w", pkgfile, err)