Пример #1
0
func (s *Server) pullHandler(response http.ResponseWriter, req *http.Request) {
	defer req.Body.Close()

	response.Header().Set("Content-Type", "application/json")

	cfg, err := config.NewServerConfig(req.Header.Get("X-Registry-Auth"))
	if err != nil {
		response.Write(s.errorJSON(err.Error()))
		return
	}

	dogestryCli, err := cli.NewDogestryCli(cfg, make([]string, 0))
	if err != nil {
		response.Write(s.errorJSON(err.Error()))
		return
	}

	image := req.URL.Query().Get("fromImage")

	response.Write(s.statusJSON(fmt.Sprintf("Pulling %s from S3...", image)))

	// Try to flush
	if f, ok := response.(http.Flusher); ok {
		f.Flush()
	}

	if err := dogestryCli.CmdPull(cfg.AWS.S3URL.String(), image); err != nil {
		fmt.Printf("Error pulling image from S3: %v\n", err.Error())
		response.Write(s.errorJSON("Dogestry server error: " + err.Error()))
		return
	}

	response.Write(s.statusJSON("Done"))
}
Пример #2
0
func main() {
	runtime.GOMAXPROCS(runtime.NumCPU())

	flag.Usage = func() {
		fmt.Fprintln(os.Stderr, cli.HelpMessage)
	}

	flag.Parse()

	if flVersion {
		if err := cli.PrintVersion(); err != nil {
			log.Fatal(err)
		}
		return
	}

	if flServerMode {
		fullAddress := fmt.Sprintf("%v:%v", flServerAddress, flServerPort)

		log.Printf("Running dogestry in server mode on '%v'", fullAddress)

		s := server.New(fullAddress)
		s.ServeHttp()
	} else {
		args := flag.Args()

		// Allow 'help', 'version' and 'login' to not require AWS cred env vars
		requireEnvVars := true

		if len(args) == 0 || (args[0] == "help" || args[0] == "login" || args[0] == "version") {
			requireEnvVars = false
		}

		cfg, err := config.NewConfig(flUseMetaService, flServerPort, flForceLocal, requireEnvVars)
		if err != nil {
			log.Fatal(err)
		}

		dogestryCli, err := cli.NewDogestryCli(cfg, flPullHosts)
		if err != nil {
			log.Fatal(err)
		}

		if flLockFile != "" {
			utils.LockByFile(dogestryCli, args, flLockFile)
		} else {
			err = dogestryCli.RunCmd(args...)

			dogestryCli.Cleanup()

			if err != nil {
				log.Fatal(err)
			}
		}
	}
}
Пример #3
0
func main() {
	runtime.GOMAXPROCS(runtime.NumCPU())

	flag.Usage = func() {
		fmt.Fprintln(os.Stderr, cli.HelpMessage)
	}

	flag.Parse()

	if flVersion {
		err := cli.PrintVersion()
		if err != nil {
			log.Fatal(err)
		}
		return
	}

	args := flag.Args()

	cfg, err := config.NewConfig(flUseMetaService)
	if err != nil {
		log.Fatal(err)
	}

	dogestryCli, err := cli.NewDogestryCli(cfg, flPullHosts)
	if err != nil {
		log.Fatal(err)
	}

	if flLockFile != "" {
		utils.LockByFile(dogestryCli, args, flLockFile)
	} else {
		err = dogestryCli.RunCmd(args...)

		if err == nil {
			dogestryCli.Cleanup()
		} else {
			dogestryCli.Cleanup()
			log.Fatal(err)
		}
	}
}