Example #1
0
func main() {
	name := filepath.Base(os.Args[0])
	if name == "golem_runner" {
		runnerMain()
		return
	}
	var (
		dockerBinary string
		cacheDir     string
		buildCache   string
	)
	co := clientutil.NewClientOptions()
	cm := runner.NewConfigurationManager()

	// Move Docker Specific options to separate type
	flag.StringVar(&dockerBinary, "db", "", "Docker binary to test")
	flag.StringVar(&cacheDir, "cache", "", "Cache directory")
	flag.StringVar(&buildCache, "build-cache", "", "Build cache location, if outside of default cache directory")
	// TODO: Add swarm flag and host option

	flag.Parse()

	// TODO: Allow quiet and verbose mode
	logrus.SetLevel(logrus.DebugLevel)

	if cacheDir == "" {
		td, err := ioutil.TempDir("", "build-cache-")
		if err != nil {
			logrus.Fatalf("Error creating tempdir: %v", err)
		}
		cacheDir = td
		defer os.RemoveAll(td)
	}

	if buildCache == "" {
		buildCache = filepath.Join(cacheDir, "builds")
		if err := os.MkdirAll(buildCache, 0755); err != nil {
			logrus.Fatalf("Error creating build cache directory")
		}
	}
	c := runner.CacheConfiguration{
		ImageCache: runner.NewImageCache(filepath.Join(cacheDir, "images")),
		BuildCache: buildutil.NewFSBuildCache(buildCache),
	}

	if dockerBinary != "" {
		v, err := versionutil.BinaryVersion(dockerBinary)
		if err != nil {
			logrus.Fatalf("Error getting binary version of %s: %v", dockerBinary, err)
		}
		logrus.Debugf("Using local binary with version %s", v.String())
		if err := c.BuildCache.PutVersion(v, dockerBinary); err != nil {
			logrus.Fatalf("Error putting %s in cache as %s: %v", dockerBinary, v, err)
		}

		flag.Set("docker-version", v.String())
	}

	client, err := runner.NewDockerClient(co)
	if err != nil {
		logrus.Fatalf("Failed to create client: %v", err)
	}

	v, err := client.Version()
	if err != nil {
		logrus.Fatalf("Error getting version: %v", err)
	}

	serverVersion, err := versionutil.ParseVersion(v.Get("Version"))
	if err != nil {
		logrus.Fatalf("Unexpected version value: %s", v.Get("Version"))
	}
	// TODO: Support arbitrary load version instead of server version by
	// starting up separate daemon for load
	// TODO: Check cache here to ensure that load will not have issues
	logrus.Debugf("Using docker daemon for image export, version %s", serverVersion)

	r, err := cm.CreateRunner(serverVersion, c)
	if err != nil {
		logrus.Fatalf("Error creating runner: %v", err)
	}

	if err := r.Build(client); err != nil {
		logrus.Fatalf("Error building test images: %v", err)
	}

	if err := r.Run(client); err != nil {
		logrus.Fatalf("Error running tests: %v", err)
	}
}
Example #2
0
func main() {
	name := filepath.Base(os.Args[0])
	if name == "golem_runner" {
		runnerMain()
		return
	}
	if name == "golem_tapper" {
		tapperMain()
		return
	}
	var (
		cacheDir    string
		startDaemon bool
		debug       bool
	)

	cm := runner.NewConfigurationManager(name)

	cm.FlagSet.StringVar(&cacheDir, "cache", "", "Cache directory")
	cm.FlagSet.BoolVar(&startDaemon, "rundaemon", false, "Start daemon")
	cm.FlagSet.BoolVar(&debug, "debug", false, "Whether to output debug logs")

	if err := cm.ParseFlags(os.Args[1:]); err != nil {
		logrus.Fatalf("Invalid options: %v", err)
	}

	if debug {
		logrus.SetLevel(logrus.DebugLevel)
	}

	runConfig, err := cm.RunnerConfiguration()
	if err != nil {
		logrus.Fatalf("Error creating run configuration: %v", err)
	}

	if cacheDir == "" {
		td, err := ioutil.TempDir("", "golem-cache-")
		if err != nil {
			logrus.Fatalf("Error creating tempdir: %v", err)
		}
		cacheDir = td
		defer os.RemoveAll(td)
	}

	cacheConfig := runner.CacheConfiguration{
		ImageCache: runner.NewImageCache(filepath.Join(cacheDir, "images")),
	}

	var client runner.DockerClient
	if startDaemon {
		logger := runner.NewConsoleLogCapturer()
		c, shutdown, err := runner.StartDaemon(context.Background(), "docker", logger)
		if err != nil {
			logrus.Fatalf("Error starting deamon: %v", err)
		}
		defer shutdown()
		client = c
	} else {
		c, err := cm.DockerClient()
		if err != nil {
			logrus.Fatalf("Failed to create client: %v", err)
		}
		client = c
	}

	// require running on docker 1.10 to ensure content addressable
	// image identifiers are used
	if err := client.CheckServerVersion(versionutil.StaticVersion(1, 10, 0)); err != nil {
		logrus.Fatal(err)
	}

	r := runner.NewRunner(runConfig, cacheConfig, debug)

	if err := r.Build(client); err != nil {
		logrus.Fatalf("Error building test images: %v", err)
	}

	if err := r.Run(client); err != nil {
		logrus.Fatalf("Error running tests: %v", err)
	}
}