func main() { project, err := docker.NewProject(&docker.Context{ Context: project.Context{ ComposeFile: "docker-compose.yml", ProjectName: "yeah-compose", }, }) if err != nil { log.Fatal(err) } project.Up() }
func (ComposeService) Compose(s string) error { project, err := docker.NewProject(&docker.Context{ Context: project.Context{ ComposeFile: "docker-compose.yml", ProjectName: "my-compose", }, }) check(err) fmt.Println(s) project.Up() return nil }
func main() { project, err := docker.NewProject(&docker.Context{ Context: project.Context{ ComposeFiles: []string{"docker-compose.yml"}, ProjectName: "yeah-compose", }, }, nil) if err != nil { log.Fatal(err) } err = project.Up(context.Background(), options.Up{}) if err != nil { log.Fatal(err) } }
func (s *APISuite) TestVolumeWithoutComposeFile(c *C) { service := ` service: image: busybox command: echo Hello world! volumes: - /etc/selinux:/etc/selinux` project, err := docker.NewProject(&docker.Context{ Context: project.Context{ ComposeBytes: [][]byte{[]byte(service)}, ProjectName: "test-volume-without-compose-file", }, }) c.Assert(err, IsNil) err = project.Up() c.Assert(err, IsNil) }
func (s *APISuite) TestEvents(c *check.C) { testRequires(c, not(DaemonVersionIs("1.9"))) composeFile := ` simple: image: busybox:latest command: top another: image: busybox:latest command: top ` project, err := docker.NewProject(&ctx.Context{ Context: project.Context{ ComposeBytes: [][]byte{[]byte(composeFile)}, ProjectName: "test-api-events", }, }, nil) c.Assert(err, check.IsNil) ctx, cancelFun := context.WithCancel(context.Background()) evts, err := project.Events(ctx) c.Assert(err, check.IsNil) go func() { c.Assert(project.Up(ctx, options.Up{}), check.IsNil) // Close after everything is done time.Sleep(250 * time.Millisecond) cancelFun() close(evts) }() actual := []events.ContainerEvent{} for event := range evts { actual = append(actual, event) } // Should be 4 events (2 create, 2 start) c.Assert(len(actual), check.Equals, 4, check.Commentf("%v", actual)) }
func (c *UpCommand) Run(args []string) int { var insecure bool var logLevel string flags := flag.NewFlagSet("up", flag.ContinueOnError) flags.BoolVar(&insecure, "insecure", false, "") flags.StringVar(&logLevel, "log-level", "info", "") flags.Usage = func() { c.Ui.Error(c.Help()) } errR, errW := io.Pipe() errScanner := bufio.NewScanner(errR) go func() { for errScanner.Scan() { c.Ui.Error(errScanner.Text()) } }() flags.SetOutput(errW) if err := flags.Parse(args); err != nil { return 1 } compose, err := config.Asset("k8s.yml") if err != nil { c.Ui.Error(fmt.Sprintf( "Failed to read k8s.yml: %s", err)) return 1 } // Set up docker client clientFactory, err := docker.NewDefaultClientFactory( docker.ClientOpts{ TLS: !insecure, }, ) if err != nil { c.Ui.Error(fmt.Sprintf( "Failed to construct Docker client: %s", err)) return 1 } // Setup new docker-compose project context := &docker.Context{ Context: project.Context{ Log: false, ComposeBytes: compose, ProjectName: "boot2k8s", }, ClientFactory: clientFactory, } // Setup new docker-compose project project, err := docker.NewProject(context) if err != nil { c.Ui.Error(fmt.Sprintf( "Failed to setup project: %s", err)) return 1 } c.Ui.Output("Start kubernetes cluster!") upErrCh := make(chan error) go func() { if err := project.Up(); err != nil { upErrCh <- err } }() client := clientFactory.Create(nil) sigCh := make(chan os.Signal) signal.Notify(sigCh, os.Interrupt) select { case <-afterContainerReady(client): c.Ui.Info("Successfully start kubernetes cluster") case err := <-upErrCh: c.Ui.Error("") c.Ui.Error(fmt.Sprintf("Failed to start containers: %s", err)) c.Ui.Error("Check docker daemon is wroking") return 1 case <-sigCh: c.Ui.Error("") c.Ui.Error("Interrupted!") c.Ui.Error("It's ambiguous that boot2kubernetes could correctly start containers.") c.Ui.Error("So request to kubelet may be failed. Check the containers are working") c.Ui.Error("with `docker ps` command by yourself.") return 1 case <-time.After(CheckTimeOut): c.Ui.Error("") c.Ui.Error("Timeout happened while waiting cluster containers are ready.") c.Ui.Error("It's ambiguous that boot2kubernetes could correctly start containers.") c.Ui.Error("So request to kubelet may be failed. Check the containers are working") c.Ui.Error("with `docker ps` command by yourself.") return 1 } // If docker runs on boot2docker, port forwarding is needed. if runtime.GOOS == "darwin" { c.Ui.Output("") c.Ui.Output("==> WARNING: You're running docker on boot2docker!") c.Ui.Output(" To connect to master api server from local environment,") c.Ui.Output(" port forwarding is needed. boot2kubernetes starts ") c.Ui.Output(" server for that. To stop server, use ^C (Interrupt).\n") // Create logger with Log level logger := log.New(&logutils.LevelFilter{ Levels: []logutils.LogLevel{"DEBUG", "INFO", "WARN", "ERROR"}, MinLevel: (logutils.LogLevel)(strings.ToUpper(logLevel)), Writer: os.Stderr, }, "", log.LstdFlags) logger.Printf("[DEBUG] LogLevel: %s", logLevel) // Setup port forward server server := &PortForwardServer{ Logger: logger, LocalServer: DefaultLocalServer, RemoteServer: DefaultRemoteServer, } doneCh, errCh, err := server.Start() if err != nil { c.Ui.Error(fmt.Sprintf( "Failed to start port forwarding server: %s", err)) return 1 } sigCh := make(chan os.Signal) signal.Notify(sigCh, os.Interrupt) select { case err := <-errCh: c.Ui.Error(fmt.Sprintf( "Error while running port forwarding server: %s", err)) close(doneCh) return 1 case <-sigCh: c.Ui.Error("\nInterrupted!") close(doneCh) // Need some time for closing work... time.Sleep(ClosingTime) } } return 0 }