1 // Copyright (C) The Arvados Authors. All rights reserved.
3 // SPDX-License-Identifier: AGPL-3.0
14 "git.arvados.org/arvados.git/lib/install"
15 "git.arvados.org/arvados.git/sdk/go/ctxlog"
16 "github.com/sirupsen/logrus"
19 type buildPackage struct{}
21 func (bld buildPackage) RunCommand(prog string, args []string, stdin io.Reader, stdout, stderr io.Writer) int {
22 logger := ctxlog.New(stderr, "text", "info")
24 PackageVersion: "0.0.0",
26 }).run(context.Background(), prog, args, stdin, stdout, stderr)
28 logger.WithError(err).Error("failed")
39 logger logrus.FieldLogger
42 func (bldr *builder) run(ctx context.Context, prog string, args []string, stdin io.Reader, stdout, stderr io.Writer) error {
43 flags := flag.NewFlagSet("", flag.ContinueOnError)
44 flags.StringVar(&bldr.PackageVersion, "package-version", bldr.PackageVersion, "package version")
45 flags.StringVar(&bldr.SourcePath, "source", bldr.SourcePath, "source tree location")
46 flags.StringVar(&bldr.OutputDir, "output-directory", bldr.OutputDir, "destination directory for new package (default is cwd)")
47 flags.BoolVar(&bldr.SkipInstall, "skip-install", bldr.SkipInstall, "skip install step, assume you have already run 'arvados-server install -type package'")
48 err := flags.Parse(args)
52 if len(flags.Args()) > 0 {
53 return fmt.Errorf("unrecognized command line arguments: %v", flags.Args())
55 if !bldr.SkipInstall {
56 exitcode := install.Command.RunCommand("arvados-server install", []string{
58 "-package-version", bldr.PackageVersion,
59 "-source", bldr.SourcePath,
60 }, stdin, stdout, stderr)
62 return fmt.Errorf("arvados-server install failed: exit code %d", exitcode)
65 cmd := exec.Command("/var/lib/arvados/bin/gem", "install", "--user", "--no-rdoc", "--no-ri", "fpm")
70 return fmt.Errorf("gem install fpm: %w", err)
73 format := "deb" // TODO: rpm
75 cmd = exec.Command("/root/.gem/ruby/2.5.0/bin/fpm",
76 "--name", "arvados-server-easy",
77 "--version", bldr.PackageVersion,
78 "--input-type", "dir",
79 "--output-type", format)
80 deps, err := install.ProductionDependencies()
84 for _, pkg := range deps {
85 cmd.Args = append(cmd.Args, "--depends", pkg)
87 cmd.Args = append(cmd.Args,
88 "--exclude", "/var/lib/arvados/go",
91 "/var/www/.passenger",
93 fmt.Fprintf(stderr, "%s...\n", cmd.Args)
94 cmd.Dir = bldr.OutputDir