func (v *configurationVersion) Set(value string) error { dv, err := versionutil.ParseVersion(value) if err != nil { return err } *v = configurationVersion(dv) return nil }
// CheckServerVersion checks that the server version is atleast // the provided version, throws an error if not func (dc DockerClient) CheckServerVersion(version versionutil.Version) error { ctx := context.Background() v, err := dc.ServerVersion(ctx) if err != nil { return fmt.Errorf("error getting version: %v", err) } serverVersion, err := versionutil.ParseVersion(v.Version) if err != nil { return fmt.Errorf("error parsing version %s: %v", v.Version, err) } if serverVersion.LessThan(version) { return fmt.Errorf("unsupported Docker version %s, golem requires running on at least %s", serverVersion, version) } logrus.Debugf("Client connected to server with version %s", serverVersion) return nil }
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) } }