// New initializes a new engine managing the directory specified at `root`. // `root` is used to store containers and any other state private to the engine. // Changing the contents of the root without executing a job will cause unspecified // behavior. func New(root string) (*Engine, error) { // Check for unsupported architectures if runtime.GOARCH != "amd64" { return nil, fmt.Errorf("The docker runtime currently only supports amd64 (not %s). This will change in the future. Aborting.", runtime.GOARCH) } // Check for unsupported kernel versions // FIXME: it would be cleaner to not test for specific versions, but rather // test for specific functionalities. // Unfortunately we can't test for the feature "does not cause a kernel panic" // without actually causing a kernel panic, so we need this workaround until // the circumstances of pre-3.8 crashes are clearer. // For details see http://github.com/dotcloud/docker/issues/407 if k, err := utils.GetKernelVersion(); err != nil { log.Printf("WARNING: %s\n", err) } else { if utils.CompareKernelVersion(k, &utils.KernelVersionInfo{Kernel: 3, Major: 8, Minor: 0}) < 0 { log.Printf("WARNING: You are running linux kernel version %s, which might be unstable running docker. Please upgrade your kernel to 3.8.0.", k.String()) } } if err := os.MkdirAll(root, 0700); err != nil && !os.IsExist(err) { return nil, err } eng := &Engine{ root: root, handlers: make(map[string]Handler), id: utils.RandomString(), } // Copy existing global handlers for k, v := range globalHandlers { eng.handlers[k] = v } return eng, nil }
// New initializes a new engine managing the directory specified at `root`. // `root` is used to store containers and any other state private to the engine. // Changing the contents of the root without executing a job will cause unspecified // behavior. func New(root string) (*Engine, error) { // Check for unsupported architectures if runtime.GOARCH != "amd64" { return nil, fmt.Errorf("The docker runtime currently only supports amd64 (not %s). This will change in the future. Aborting.", runtime.GOARCH) } // Check for unsupported kernel versions // FIXME: it would be cleaner to not test for specific versions, but rather // test for specific functionalities. // Unfortunately we can't test for the feature "does not cause a kernel panic" // without actually causing a kernel panic, so we need this workaround until // the circumstances of pre-3.8 crashes are clearer. // For details see http://github.com/dotcloud/docker/issues/407 if k, err := utils.GetKernelVersion(); err != nil { log.Printf("WARNING: %s\n", err) } else { if utils.CompareKernelVersion(k, &utils.KernelVersionInfo{Kernel: 3, Major: 8, Minor: 0}) < 0 { if os.Getenv("DOCKER_NOWARN_KERNEL_VERSION") == "" { log.Printf("WARNING: You are running linux kernel version %s, which might be unstable running docker. Please upgrade your kernel to 3.8.0.", k.String()) } } } if err := os.MkdirAll(root, 0700); err != nil && !os.IsExist(err) { return nil, err } // Docker makes some assumptions about the "absoluteness" of root // ... so let's make sure it has no symlinks if p, err := filepath.Abs(root); err != nil { log.Fatalf("Unable to get absolute root (%s): %s", root, err) } else { root = p } if p, err := filepath.EvalSymlinks(root); err != nil { log.Fatalf("Unable to canonicalize root (%s): %s", root, err) } else { root = p } eng := &Engine{ root: root, handlers: make(map[string]Handler), id: utils.RandomString(), Stdout: os.Stdout, Stderr: os.Stderr, Stdin: os.Stdin, } eng.Register("commands", func(job *Job) Status { for _, name := range eng.commands() { job.Printf("%s\n", name) } return StatusOK }) // Copy existing global handlers for k, v := range globalHandlers { eng.handlers[k] = v } return eng, nil }
// Run executes the job and blocks until the job completes. // If the job returns a failure status, an error is returned // which includes the status. func (job *Job) Run() error { randId := utils.RandomString()[:4] fmt.Printf("Job #%s: %s\n", randId, job) defer fmt.Printf("Job #%s: %s = '%s'", randId, job, job.status) if job.handler == nil { job.status = "command not found" } else { job.status = job.handler(job) } if job.status != "0" { return fmt.Errorf("%s: %s", job.Name, job.status) } return nil }
// New initializes a new engine. func New() *Engine { eng := &Engine{ handlers: make(map[string]Handler), id: utils.RandomString(), Stdout: os.Stdout, Stderr: os.Stderr, Stdin: os.Stdin, Logging: true, } eng.Register("commands", func(job *Job) Status { for _, name := range eng.commands() { job.Printf("%s\n", name) } return StatusOK }) // Copy existing global handlers for k, v := range globalHandlers { eng.handlers[k] = v } return eng }
func mkEngine(t *testing.T) *Engine { // Use the caller function name as a prefix. // This helps trace temp directories back to their test. pc, _, _, _ := runtime.Caller(1) callerLongName := runtime.FuncForPC(pc).Name() parts := strings.Split(callerLongName, ".") callerShortName := parts[len(parts)-1] if globalTestID == "" { globalTestID = utils.RandomString()[:4] } prefix := fmt.Sprintf("docker-test%s-%s-", globalTestID, callerShortName) root, err := ioutil.TempDir("", prefix) if err != nil { t.Fatal(err) } eng, err := New(root) if err != nil { t.Fatal(err) } return eng }