func (f Focker) RunRuntime(writer io.Writer) { prepareRuntimeFilesystem(utils.CloudfockerHome()) runConfig := config.NewRuntimeRunConfig(utils.CloudfockerHome() + "/droplet") cli, Stdout, stdoutpipe := docker.GetNewClient() if docker.GetContainerId(cli, Stdout, stdoutpipe, runConfig.ContainerName) != "" { fmt.Println("Deleting running runtime container...") f.StopRuntime(writer) } cli, Stdout, stdoutpipe = docker.GetNewClient() docker.RunConfiguredContainer(cli, Stdout, stdoutpipe, writer, runConfig) fmt.Fprintln(writer, "Connect to your running application at http://localhost:8080/") }
func (f Focker) RunStager(writer io.Writer, appDir string) error { prepareStagingFilesystem(utils.CloudfockerHome()) stagingAppDir := prepareStagingApp(appDir, utils.CloudfockerHome()+"/staging") runConfig := config.NewStageRunConfig(stagingAppDir) cli, Stdout, stdoutpipe := docker.GetNewClient() docker.RunConfiguredContainer(cli, Stdout, stdoutpipe, writer, runConfig) f.DeleteContainer(writer, runConfig.ContainerName) return stager.ValidateStagedApp(utils.CloudfockerHome()) }
func (Focker) DeleteContainer(writer io.Writer, name string) { cli, Stdout, stdoutpipe := docker.GetNewClient() docker.DeleteContainer(cli, Stdout, stdoutpipe, writer, name) }
func (f Focker) StopContainer(writer io.Writer, name string) { cli, Stdout, stdoutpipe := docker.GetNewClient() docker.StopContainer(cli, Stdout, stdoutpipe, writer, name) }
func (Focker) ImportRootfsImage(writer io.Writer) { cli, Stdout, stdoutpipe := docker.GetNewClient() docker.ImportRootfsImage(cli, Stdout, stdoutpipe, writer, utils.GetRootfsUrl()) }
func (Focker) DockerVersion(writer io.Writer) { cli, Stdout, stdoutpipe := docker.GetNewClient() docker.PrintVersion(cli, Stdout, stdoutpipe, writer) }
fakeDockerClient = new(FakeDockerClient) stdout, stdoutPipe := io.Pipe() containerId := make(chan string) go func() { containerId <- docker.GetContainerId(fakeDockerClient, stdout, stdoutPipe, "cloudfocker-runtime") }() io.Copy(stdoutPipe, bytes.NewBufferString("CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES\n180e16d9ef28 cloudfocker:latest /usr/sbin/nginx -c / 13 minutes ago Up 13 minutes 0.0.0.0:8080->8080/tcp cloudfocker-runtime\n")) Eventually(fakeDockerClient.cmdPsCalled).Should(Equal(true)) Eventually(containerId).Should(Receive(Equal("180e16d9ef28"))) }) }) }) Describe("Getting a Docker client", func() { It("should return a usable docker client on unix", func() { cli, stdout, stdoutpipe := docker.GetNewClient() docker.PrintVersion(cli, stdout, stdoutpipe, buffer) Eventually(buffer).Should(gbytes.Say(`Client API version: `)) }) }) Describe("Printing to stdout", func() { It("should print from a pipe", func() { stdout, stdoutPipe := io.Pipe() go func() { docker.PrintToStdout(stdout, stdoutPipe, "stoptag", buffer) }() io.Copy(stdoutPipe, bytes.NewBufferString("THIS IS A TEST STRING\n")) Eventually(buffer).Should(gbytes.Say(`THIS IS A TEST STRING`)) }) It("should stop printing when it reaches a stoptag", func() {