Limit concurrency.
[lightning.git] / cmd.go
1 package main
2
3 import (
4         "fmt"
5         "io"
6         "io/ioutil"
7         "os"
8         "os/exec"
9
10         "git.arvados.org/arvados.git/lib/cmd"
11 )
12
13 var (
14         handler = cmd.Multi(map[string]cmd.Handler{
15                 "version":   cmd.Version,
16                 "-version":  cmd.Version,
17                 "--version": cmd.Version,
18
19                 "gvcf2numpy":         &gvcf2numpy{},
20                 "build-docker-image": &buildDockerImage{},
21         })
22 )
23
24 func main() {
25         os.Exit(handler.RunCommand(os.Args[0], os.Args[1:], os.Stdin, os.Stdout, os.Stderr))
26 }
27
28 type buildDockerImage struct{}
29
30 func (cmd *buildDockerImage) RunCommand(prog string, args []string, stdin io.Reader, stdout, stderr io.Writer) int {
31         tmpdir, err := ioutil.TempDir("", "")
32         if err != nil {
33                 fmt.Fprint(stderr, err)
34                 return 1
35         }
36         defer os.RemoveAll(tmpdir)
37         err = ioutil.WriteFile(tmpdir+"/Dockerfile", []byte(`FROM debian:10
38 RUN apt-get update
39 RUN DEBIAN_FRONTEND=noninteractive apt-get install -y --no-install-recommends bcftools samtools
40 `), 0644)
41         if err != nil {
42                 fmt.Fprint(stderr, err)
43                 return 1
44         }
45         docker := exec.Command("docker", "build", "--tag=lightning-runtime", tmpdir)
46         docker.Stdout = os.Stdout
47         docker.Stderr = os.Stderr
48         err = docker.Run()
49         if err != nil {
50                 return 1
51         }
52         return 0
53 }