1 // Copyright (C) The Arvados Authors. All rights reserved.
3 // SPDX-License-Identifier: AGPL-3.0
16 "git.arvados.org/arvados.git/lib/cmd"
17 "git.arvados.org/arvados.git/lib/install"
18 "git.arvados.org/arvados.git/sdk/go/ctxlog"
22 handler = cmd.Multi(map[string]cmd.Handler{
23 "version": cmd.Version,
24 "-version": cmd.Version,
25 "--version": cmd.Version,
27 "build": cmdFunc(build),
28 "testinstall": cmdFunc(testinstall),
29 "_fpm": cmdFunc(fpm), // internal use
30 "_install": install.Command, // internal use
35 if len(os.Args) < 2 || strings.HasPrefix(os.Args[1], "-") {
36 parseFlags([]string{"-help"})
39 os.Exit(handler.RunCommand(os.Args[0], os.Args[1:], os.Stdin, os.Stdout, os.Stderr))
42 type cmdFunc func(ctx context.Context, opts opts, stdin io.Reader, stdout, stderr io.Writer) error
44 func (cf cmdFunc) RunCommand(prog string, args []string, stdin io.Reader, stdout, stderr io.Writer) int {
45 logger := ctxlog.New(stderr, "text", "info")
46 ctx := ctxlog.Context(context.Background(), logger)
47 opts, err := parseFlags(args)
49 logger.WithError(err).Error("error parsing command line flags")
52 err = cf(ctx, opts, stdin, stdout, stderr)
54 logger.WithError(err).Error("failed")
71 func parseFlags(args []string) (opts, error) {
74 TargetOS: "debian:10",
75 Maintainer: "Arvados Package Maintainers <packaging@arvados.org>",
76 Vendor: "The Arvados Project",
78 flags := flag.NewFlagSet("", flag.ContinueOnError)
79 flags.StringVar(&opts.PackageVersion, "package-version", opts.PackageVersion, "package version to build/test, like \"1.2.3\"")
80 flags.StringVar(&opts.SourceDir, "source", opts.SourceDir, "arvados source tree location")
81 flags.StringVar(&opts.PackageDir, "package-dir", opts.PackageDir, "destination directory for new package (default is cwd)")
82 flags.StringVar(&opts.PackageChown, "package-chown", opts.PackageChown, "desired uid:gid for new package (default is current user:group)")
83 flags.StringVar(&opts.TargetOS, "target-os", opts.TargetOS, "target operating system vendor:version")
84 flags.StringVar(&opts.Maintainer, "package-maintainer", opts.Maintainer, "maintainer to be listed in package metadata")
85 flags.StringVar(&opts.Vendor, "package-vendor", opts.Vendor, "vendor to be listed in package metadata")
86 flags.BoolVar(&opts.RebuildImage, "rebuild-image", opts.RebuildImage, "rebuild docker image(s) instead of using existing")
87 flags.Usage = func() {
88 fmt.Fprint(flags.Output(), `Usage: arvados-package <subcommand> [options]
92 use a docker container to build a package from a checked
93 out version of the arvados source tree
95 use a docker container to install a package and confirm
96 the resulting installation is functional
100 Internally used subcommands:
104 equivalent to "arvados-server install"
106 Automation/integration notes:
107 The first time a given machine runs "build" or "testinstall" (and
108 any time the -rebuild-image is used), new docker images are built,
109 which is quite slow. If you use on-demand VMs to run automated builds,
110 run "build" and "testinstall" once when setting up your initial VM
111 image, and be prepared to rebuild that VM image when package-building
112 slows down (this will happen when new dependencies are introduced).
114 The "build" subcommand, if successful, also runs
115 dpkg-scanpackages to create/replace Packages.gz in the package
116 dir. This enables the "testinstall" subcommand to list the
117 package dir as a source in /etc/apt/sources.*.
121 flags.PrintDefaults()
123 err := flags.Parse(args)
127 if len(flags.Args()) > 0 {
128 return opts, fmt.Errorf("unrecognized command line arguments: %v", flags.Args())
130 if opts.SourceDir == "" {
133 return opts, fmt.Errorf("Getwd: %w", err)
137 opts.PackageDir = filepath.Clean(opts.PackageDir)
138 opts.SourceDir, err = filepath.Abs(opts.SourceDir)