Пример #1
0
func TestPush(t *testing.T) {
	output := manifest.NewOutput()
	str := output.Stream("build")
	dr := manifest.DefaultRunner
	te := NewTestExecer()
	manifest.DefaultRunner = te
	defer func() { manifest.DefaultRunner = dr }()

	m, err := manifestFixture("full-v1")
	if err != nil {
		t.Error(err)
	}

	cmd1 := []string{"docker", "tag", "app/database", "registry/flatten:database.tag"}
	cmd2 := []string{"docker", "push", "registry/flatten:database.tag"}
	cmd3 := []string{"docker", "tag", "app/web", "registry/flatten:web.tag"}
	cmd4 := []string{"docker", "push", "registry/flatten:web.tag"}
	m.Push(str, "app", "registry", "tag", "flatten")

	assert.Equal(t, len(te.Commands), 4)
	assert.Equal(t, te.Commands[0].Args, cmd1)
	assert.Equal(t, te.Commands[1].Args, cmd2)
	assert.Equal(t, te.Commands[2].Args, cmd3)
	assert.Equal(t, te.Commands[3].Args, cmd4)
}
Пример #2
0
func TestBuildWithCache(t *testing.T) {
	output := manifest.NewOutput()
	str := output.Stream("build")
	dr := manifest.DefaultRunner
	te := NewTestExecer()
	te.CannedResponses = []ExecResponse{
		ExecResponse{
			Output: []byte("dockerid"),
			Error:  nil,
		},
	}

	manifest.DefaultRunner = te
	defer func() { manifest.DefaultRunner = dr }()

	m, err := manifestFixture("full-v1")
	if err != nil {
		t.Error(err)
	}

	err = m.Build(".", "web", str, true)

	cmd1 := []string{"docker", "build", "-f", "./Dockerfile.dev", "-t", "web/web", "."}
	cmd2 := []string{"docker", "tag", "convox/postgres", "web/database"}

	assert.Equal(t, len(te.Commands), 2)
	assert.Equal(t, te.Commands[0].Args, cmd1)
	assert.Equal(t, te.Commands[1].Args, cmd2)
}
Пример #3
0
func TestBuildRepeatComplex(t *testing.T) {
	output := manifest.NewOutput()
	str := output.Stream("build")
	dr := manifest.DefaultRunner
	te := NewTestExecer()
	manifest.DefaultRunner = te
	defer func() { manifest.DefaultRunner = dr }()

	m, err := manifestFixture("repeat-complex")
	if err != nil {
		t.Error(err)
	}

	err = m.Build(".", "web", str, false)

	te.AssertCommands(t, TestCommands{
		[]string{"docker", "build", "--no-cache", "-f", "./Dockerfile", "-t", "web/first", "."},
		[]string{"docker", "build", "--no-cache", "-f", "./Dockerfile", "-t", "web/monitor", "."},
		[]string{"docker", "build", "--no-cache", "-f", "./other/Dockerfile", "-t", "web/othera", "./other"},
		[]string{"docker", "build", "--no-cache", "-f", "./Dockerfile.other", "-t", "web/otherb", "."},
		[]string{"docker", "build", "--no-cache", "-f", "./Dockerfile", "-t", "web/otherc", "."},
		[]string{"docker", "build", "--no-cache", "-f", "./Dockerfile", "-t", "web/otherd", "."},
		[]string{"docker", "tag", "web/first", "web/othere"},
		[]string{"docker", "build", "--no-cache", "-f", "./Dockerfile.otherf", "-t", "web/otherf", "."},
		[]string{"docker", "tag", "web/otherf", "web/otherg"},
		[]string{"docker", "tag", "web/monitor", "web/web"},
	})
}
Пример #4
0
func TestBuildRepeatImage(t *testing.T) {
	output := manifest.NewOutput()
	str := output.Stream("build")
	dr := manifest.DefaultRunner
	te := NewTestExecer()
	te.CannedResponses = []ExecResponse{
		ExecResponse{
			Output: []byte(""),
			Error:  nil,
		},
	}
	manifest.DefaultRunner = te
	defer func() { manifest.DefaultRunner = dr }()

	m, err := manifestFixture("repeat-image")
	if err != nil {
		t.Error(err)
	}

	err = m.Build(".", "web", str, false)

	cmd1 := []string{"docker", "pull", "convox/rails"}
	cmd2 := []string{"docker", "tag", "convox/rails", "web/web1"}
	cmd3 := []string{"docker", "tag", "convox/rails", "web/web2"}

	if assert.Equal(t, len(te.Commands), 3) {
		assert.Equal(t, te.Commands[0].Args, cmd1)
		assert.Equal(t, te.Commands[1].Args, cmd2)
		assert.Equal(t, te.Commands[2].Args, cmd3)
	}
}
Пример #5
0
func TestBuildRepeatSimple(t *testing.T) {
	output := manifest.NewOutput(true)
	str := output.Stream("build")
	dr := manifest.DefaultRunner
	te := NewTestExecer()
	manifest.DefaultRunner = te
	defer func() { manifest.DefaultRunner = dr }()

	m, err := manifestFixture("repeat-simple")
	if err != nil {
		t.Error(err)
	}

	err = m.Build(".", "web", str, manifest.BuildOptions{
		Cache: false,
	})

	cmd1 := []string{"docker", "build", "--no-cache", "-f", "Dockerfile", "-t", "web/monitor", "."}
	cmd2 := []string{"docker", "build", "--no-cache", "-f", "other/Dockerfile", "-t", "web/other", "other"}
	cmd3 := []string{"docker", "tag", "web/monitor", "web/web"}

	assert.Equal(t, len(te.Commands), 3)
	assert.Equal(t, te.Commands[0].Args, cmd1)
	assert.Equal(t, te.Commands[1].Args, cmd2)
	assert.Equal(t, te.Commands[2].Args, cmd3)
}
Пример #6
0
func TestBuildNoCache(t *testing.T) {
	output := manifest.NewOutput(true)
	str := output.Stream("build")
	dr := manifest.DefaultRunner
	te := NewTestExecer()
	te.CannedResponses = []ExecResponse{
		{
			Output: []byte("dockeid"),
			Error:  nil,
		},
	}

	manifest.DefaultRunner = te
	defer func() { manifest.DefaultRunner = dr }()

	m, err := manifestFixture("full-v1")
	if err != nil {
		t.Error(err)
	}

	err = m.Build(".", "web", str, manifest.BuildOptions{
		Service: "web",
		Cache:   false,
	})

	cmd1 := []string{"docker", "build", "--no-cache", "-f", "Dockerfile.dev", "-t", "web/web", "."}
	cmd2 := []string{"docker", "pull", "convox/postgres:latest"}
	cmd3 := []string{"docker", "tag", "convox/postgres:latest", "web/database"}

	assert.Equal(t, len(te.Commands), 3)
	assert.Equal(t, te.Commands[0].Args, cmd1)
	assert.Equal(t, te.Commands[1].Args, cmd2)
	assert.Equal(t, te.Commands[2].Args, cmd3)
}
Пример #7
0
func main() {
	if len(os.Args) != 2 {
		fmt.Println("usage: build <src>")
		os.Exit(1)
	}
	defer handlePanic()

	src := os.Args[1]

	if src == "-" {
		extractTar()
	} else {
		cloneGit(src)
	}

	writeDockerAuth()

	m, err := manifest.LoadFile(fmt.Sprintf("src/%s", manifestPath))
	handleError(err)

	data, err := m.Raw()
	handleError(err)

	cwd, err := os.Getwd()
	handleError(err)

	output := manifest.NewOutput()
	str := output.Stream("build")

	handleError(os.Chdir("./src"))
	handleError(m.Build(".", app, str, cache))
	handleError(os.Chdir(cwd))
	handleError(m.Push(str, app, registryAddress, buildId, repository))

	_, err = rackClient.UpdateBuild(os.Getenv("APP"), os.Getenv("BUILD"), string(data), "complete", "")
	handleError(err)
}