Exemplo n.º 1
0
func deleteApp(c *cli.Context) {
	name := c.Args()[0]
	if name == "" {
		fatal("Must specify name")
	}

	repo := host.GetAppRepo()
	if err := repo.Delete(name); err != nil {
		fatal(err)
	}

	fmt.Printf("Deleted app %v\n", name)
}
Exemplo n.º 2
0
func setAPI(c *cli.Context) error {
	conf, err := config.Open(c.GlobalString("config"))
	if err != nil {
		log.Fatal("Host is not running or invalid config file")
	}

	client, err := docker.NewClientFromEnv()
	if err != nil {
		return err
	}

	host = api.New(client, conf, log.New(os.Stderr, "", log.Flags()))
	if err := host.ConnectDB(); err != nil {
		return err
	}

	return nil
}
Exemplo n.º 3
0
func createApp(c *cli.Context) {
	name := c.Args()[0]
	if name == "" {
		fatal("Must specify name")
	}

	app := &api.App{
		Name: name,
	}

	repo := host.GetAppRepo()
	if err := repo.Create(app); err != nil {
		fatal(err)
	}

	tbl := table.New(2)
	tbl.Add("ID:", app.ID)

	fmt.Println("=== App " + app.Name)
	fmt.Print(tbl.String())
}
Exemplo n.º 4
0
func receive(c *cli.Context) {
	log.SetFlags(0)

	app := c.Args()[0]
	rev := c.Args()[1]
	cache := c.Args()[2]

	client, err := docker.NewClientFromEnv()
	if err != nil {
		log.Fatal(err)
	}

	stat, _ := os.Stdin.Stat()
	if (stat.Mode() & os.ModeCharDevice) == 0 {
		cnt, err := buildApp(app, client, cache)
		if err != nil {
			log.Fatal(err)
		}
		log.Printf("Built app %v rev %v into container %v\n", app, rev, cnt.ID)
	} else {
		log.Fatal("no app input received")
	}
}
Exemplo n.º 5
0
func startDaemon(c *cli.Context) {
	defer shutdown.Exit()

	confPath := c.GlobalString("config")
	port := c.String("port")
	dev := c.Bool("dev")
	logger := setupLogger(c.String("log-dir"))

	conf, err := config.Ensure(confPath, c.String("host-key"), c.String("home"))
	if err != nil {
		if os.IsExist(err) {
			log.Fatal("Host is already running")
		}

		log.Fatal(err)
	}

	client, err := docker.NewClientFromEnv()
	if err != nil {
		log.Fatal(err)
	}

	hostAPI := api.New(client, conf, logger)

	shutdown.BeforeExit(func() {
		log.Println("Cleaning up...")
		if err := hostAPI.StopDB(); err != nil {
			log.Printf("Error stopping host DB: %v", err)
		}

		if err := conf.Cleanup(); err != nil {
			log.Printf("Error cleaning config: %v", err)
		}
	})

	if dev {
		log.Printf("Starting host, dev mode\n")
	} else {
		log.Printf("Starting host\n")
	}

	if err := hostAPI.StartDB(dev); err != nil {
		log.Printf("Error starting host DB: %v", err)
		return
	}

	if err := http.Serve(port, hostAPI, conf, logger); err != nil {
		log.Printf("HTTP API error: %v", err)
	}
}