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(os.Args[0], []string{"-help"}, os.Stderr)
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, ok, code := parseFlags(prog, args, stderr)
51 err := cf(ctx, opts, stdin, stdout, stderr)
53 logger.WithError(err).Error("failed")
71 func parseFlags(prog string, args []string, stderr io.Writer) (_ opts, ok bool, exitCode int) {
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.StringVar(&opts.Live, "live", opts.Live, "run controller at https://`example.com`, use host's /var/lib/acme/live certificates, wait for ^C before shutting down")
87 flags.BoolVar(&opts.RebuildImage, "rebuild-image", opts.RebuildImage, "rebuild docker image(s) instead of using existing")
88 flags.Usage = func() {
89 fmt.Fprint(flags.Output(), `Usage: arvados-package <subcommand> [options]
93 use a docker container to build a package from a checked
94 out version of the arvados source tree
96 use a docker container to install a package and confirm
97 the resulting installation is functional
101 Internally used subcommands:
105 equivalent to "arvados-server install"
107 Automation/integration notes:
108 The first time a given machine runs "build" or "testinstall" (and
109 any time the -rebuild-image is used), new docker images are built,
110 which is quite slow. If you use on-demand VMs to run automated builds,
111 run "build" and "testinstall" once when setting up your initial VM
112 image, and be prepared to rebuild that VM image when package-building
113 slows down (this will happen when new dependencies are introduced).
115 The "build" subcommand, if successful, also runs
116 dpkg-scanpackages to create/replace Packages.gz in the package
117 dir. This enables the "testinstall" subcommand to list the
118 package dir as a source in /etc/apt/sources.*.
122 flags.PrintDefaults()
124 if ok, code := cmd.ParseFlags(flags, prog, args, "", stderr); !ok {
125 return opts, false, code
127 if opts.SourceDir == "" {
130 fmt.Fprintf(stderr, "error getting current working directory: %s\n", err)
131 return opts, false, 1
135 opts.PackageDir = filepath.Clean(opts.PackageDir)
136 abs, err := filepath.Abs(opts.SourceDir)
138 fmt.Fprintf(stderr, "error resolving source dir %q: %s\n", opts.SourceDir, err)
139 return opts, false, 1