Exemplo n.º 1
0
func TestNameCache(t *testing.T) {
	assert := assert.New(t)
	sous.Log.Debug.SetOutput(os.Stdout)

	ResetSingularity()
	defer ResetSingularity()

	drc := docker_registry.NewClient()
	drc.BecomeFoolishlyTrusting()

	db, err := docker.GetDatabase(&docker.DBConfig{
		Driver:     "sqlite3_sous",
		Connection: docker.InMemoryConnection("testnamecache"),
	})
	if err != nil {
		t.Fatal(err)
	}
	nc := docker.NewNameCache("", drc, db)

	repoOne := "https://github.com/opentable/one.git"
	manifest(nc, "opentable/one", "test-one", repoOne, "1.1.1")

	cn, err := nc.GetCanonicalName(BuildImageName("opentable/one", "1.1.1"))
	if err != nil {
		assert.FailNow(err.Error())
	}
	labels, err := drc.LabelsForImageName(cn)

	if assert.NoError(err) {
		assert.Equal("1.1.1", labels[docker.DockerVersionLabel])
	}
}
Exemplo n.º 2
0
// makeDockerRegistry creates a Docker version of sous.Registry
func makeDockerRegistry(cfg LocalSousConfig, cl LocalDockerClient) (*docker.NameCache, error) {
	dbCfg := cfg.Docker.DBConfig()
	db, err := docker.GetDatabase(&dbCfg)
	if err != nil {
		return nil, errors.Wrap(err, "building name cache DB")
	}
	drh := cfg.Docker.RegistryHost
	return docker.NewNameCache(drh, cl.Client, db), nil
}
Exemplo n.º 3
0
func newInMemoryDB(name string) *sql.DB {
	db, err := docker.GetDatabase(&docker.DBConfig{
		Driver:     "sqlite3_sous",
		Connection: docker.InMemoryConnection(name),
	})
	if err != nil {
		panic(err)
	}
	return db
}
Exemplo n.º 4
0
func TestBuildDeployments(t *testing.T) {

	t.Skipf("Failing test on master preventing progress on other stories.")

	assert := assert.New(t)
	sous.Log.Debug.SetOutput(os.Stdout)

	ResetSingularity()
	defer ResetSingularity()

	drc := docker_registry.NewClient()
	drc.BecomeFoolishlyTrusting()

	db, err := docker.GetDatabase(&docker.DBConfig{
		Driver:     "sqlite3_sous",
		Connection: docker.InMemoryConnection("testresolve"),
	})
	if err != nil {
		panic(err)
	}

	appLocation := "testhelloreq"
	clusterNick := "tcluster"
	reqID := appLocation + clusterNick

	nc := docker.NewNameCache("", drc, db)

	singCl := sing.NewClient(SingularityURL)
	//singCl.Debug = true

	sr, err := singReqDep(
		SingularityURL,
		whitespace.CleanWS(`
		{
			"instances": 1,
			"id": "`+reqID+`",
			"requestType": "SERVICE",
			"owners": ["*****@*****.**", "*****@*****.**"]
		}`),
		whitespace.CleanWS(`
		{
			"deploy": {
				"id": "`+singularity.MakeDeployID(uuid.NewV4().String())+`",
				"requestId": "`+reqID+`",
				"resources": {
					"cpus": 0.1,
					"memoryMb": 32,
					"numPorts": 1
				},
				"containerInfo": {
					"type": "DOCKER",
					"docker": {
						"image": "`+BuildImageName("hello-server-labels", "latest")+`"
					},
					"volumes": [{"hostPath":"/tmp", "containerPath":"/tmp","mode":"RO"}]
				},
				"env": {
					"TEST": "yes"
				}
			}
		}`),
	)

	req := singularity.SingReq{
		SourceURL: SingularityURL,
		Sing:      singCl,
		ReqParent: sr,
	}

	if assert.NoError(err) {
		clusters := sous.Clusters{clusterNick: {BaseURL: SingularityURL}}
		dep, err := singularity.BuildDeployment(nc, clusters, req)

		if assert.NoError(err) {
			if assert.Len(dep.DeployConfig.Volumes, 1) {
				assert.Equal(dep.DeployConfig.Volumes[0].Host, "/tmp")
			}
			assert.Equal("github.com/docker/dockercloud-hello-world", dep.SourceID.Location.Repo)
		}
	}
}