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()) }
package config_test import ( "github.com/hatofmonkeys/cloudfocker/config" . "github.com/onsi/ginkgo" . "github.com/onsi/gomega" ) var _ = Describe("RunConfig", func() { Describe("Generating a RunConfig for staging", func() { It("should return a valid RunConfig with the correct staging information", func() { stageConfig := config.NewStageRunConfig("/home/testuser/testapp") Expect(stageConfig.ContainerName).To(Equal("cloudfocker-staging")) Expect(len(stageConfig.Mounts)).To(Equal(6)) Expect(stageConfig.Mounts["/home/testuser/testapp"]).To(Equal("/app")) Expect(stageConfig.ImageTag).To(Equal("cloudfocker-base:latest")) Expect(stageConfig.Command).To(Equal([]string{"/focker/fock", "stage", "internal"})) }) }) Describe("Generating a RunConfig for runtime", func() { Context("with a valid staging_info.yml", func() { It("should return a valid RunConfig with the correct runtime information", func() { runtimeConfig := config.NewRuntimeRunConfig("fixtures/testdroplet") Expect(runtimeConfig.ContainerName).To(Equal("cloudfocker-runtime")) Expect(runtimeConfig.Daemon).To(Equal(true)) Expect(len(runtimeConfig.Mounts)).To(Equal(1)) Expect(runtimeConfig.Mounts["fixtures/testdroplet/app"]).To(Equal("/app")) Expect(runtimeConfig.PublishedPorts).To(Equal(map[int]int{8080: 8080})) Expect(len(runtimeConfig.EnvVars)).To(Equal(4))
It("should tell Docker to import the rootfs from the supplied URL", func() { url := "http://test.com/test-img" fakeDockerClient = new(FakeDockerClient) stdout, stdoutPipe := io.Pipe() docker.ImportRootfsImage(fakeDockerClient, stdout, stdoutPipe, buffer, url) Expect(len(fakeDockerClient.cmdImportArgs)).To(Equal(2)) Expect(fakeDockerClient.cmdImportArgs[0]).To(Equal("http://test.com/test-img")) Expect(fakeDockerClient.cmdImportArgs[1]).To(Equal("cloudfocker-base")) }) }) Describe("Running a configured container", func() { It("should tell Docker to run the container with the correct arguments", func() { fakeDockerClient = new(FakeDockerClient) stdout, stdoutPipe := io.Pipe() docker.RunConfiguredContainer(fakeDockerClient, stdout, stdoutPipe, buffer, config.NewStageRunConfig("/tmp/fakeappdir")) Expect(len(fakeDockerClient.cmdRunArgs)).To(Equal(12)) Expect(fakeDockerClient.cmdRunArgs[11]).To(Equal("internal")) }) }) Describe("Stopping the docker container", func() { It("should tell Docker to stop the container", func() { fakeDockerClient = new(FakeDockerClient) stdout, stdoutPipe := io.Pipe() docker.StopContainer(fakeDockerClient, stdout, stdoutPipe, buffer, "cloudfocker-container") Expect(len(fakeDockerClient.cmdStopArgs)).To(Equal(1)) Expect(fakeDockerClient.cmdStopArgs[0]).To(Equal("cloudfocker-container")) }) })