예제 #1
0
파일: git.go 프로젝트: liamjbennett/sous
func GetInfo() *Info {
	nearestTagSHA := ""
	nearestTag, err := cmd.StdoutErr("git", "describe", "--tags", "--abbrev=0")
	if err != nil {
		nearestTag = ""
	} else {
		nearestTagSHA = cmd.Stdout("git", "rev-parse", nearestTag)
	}
	return &Info{
		CommitSHA:     cmd.Stdout("git", "rev-parse", "HEAD"),
		OriginURL:     getOriginURL(),
		NearestTag:    nearestTag,
		NearestTagSHA: nearestTagSHA,
	}
}
예제 #2
0
파일: state.go 프로젝트: liamjbennett/sous
// CalculateSousHash returns a hash of the current version of Sous and its main
// configuration file.
func CalculateSousHash() string {
	inputs := []string{cmd.Stdout("sous", "version")}
	if c, ok := file.ReadString("~/.sous/config"); ok {
		inputs = append(inputs, c)
	}
	return HashSum(inputs...)
}
예제 #3
0
// DockerRun returns a configured *docker.Run, which is used to create a new
// container when the old one is stale or does not exist.
func (t *CompileTarget) DockerRun(c *core.Context) *docker.Run {
	containerName := t.ContainerName(c)
	run := docker.NewRun(c.DockerTag())
	run.Name = containerName
	run.AddEnv("ARTIFACT_NAME", t.artifactName(c))
	uid := cmd.Stdout("id", "-u")
	gid := cmd.Stdout("id", "-g")
	artifactOwner := fmt.Sprintf("%s:%s", uid, gid)
	run.AddEnv("ARTIFACT_OWNER", artifactOwner)
	artDir := t.artifactDir(c)
	dir.EnsureExists(artDir)
	run.AddVolume(artDir, "/artifacts")
	run.AddVolume(c.WorkDir, "/wd")
	run.Command = "npm install"
	return run
}
예제 #4
0
func (t *TestTarget) DockerRun(c *core.Context) *docker.Run {
	containerName := t.ContainerName(c)
	run := docker.NewRun(c.DockerTag())
	run.Name = containerName
	//run.AddEnv("ARTIFACT_NAME", t.artifactName(c))
	uid := cmd.Stdout("id", "-u")
	gid := cmd.Stdout("id", "-g")
	artifactOwner := fmt.Sprintf("%s:%s", uid, gid)
	run.AddEnv("ARTIFACT_OWNER", artifactOwner)
	artDir := t.artifactDir(c)
	dir.EnsureExists(artDir)
	run.AddVolume(artDir, "/artifacts")
	run.AddVolume(c.WorkDir, "/wd")
	run.Command = fmt.Sprintf("go generate && { [ -d Godeps ] && godep go test ./... || go test ./...; }")
	return run
}
예제 #5
0
파일: docker.go 프로젝트: liamjbennett/sous
func RequireDaemon() {
	if c := cmd.ExitCode("docker", "ps"); c != 0 {
		cli.Logf("`docker ps` exited with code %d", c)
		if dockermachine.Installed() {
			vms := dockermachine.RunningVMs()
			if len(vms) != 0 {
				cli.Fatalf(`Tip: eval "$(docker-machine env %s)"`, vms[0])
			}
			vms = dockermachine.VMs()
			switch len(vms) {
			case 0:
				cli.Logf("Tip: you should create a machine using docker-machine")
			case 1:
				start := ""
				if cmd.Stdout("docker-machine", "status", vms[0]) != "Running" {
					start = fmt.Sprintf("docker-machine start %s && ", vms[0])
				}
				cli.Logf(`Tip: %seval "$(docker-machine env %s)"`, start, vms[0])
			default:
				cli.Logf("Tip: start one of your docker machines (%s)",
					strings.Join(vms, ", "))
			}
		}
		cli.Fatal()
	}
}
예제 #6
0
// Dockerfile returns a configured *docker.Dockerfile which is used by Sous
// to build new Docker images when needed.
func (t *CompileTarget) Dockerfile(*core.Context) *docker.Dockerfile {
	df := t.NodeJSPack.baseDockerfile(t.Name())
	// This is a non-portable container, since it includes the UID of the
	// logged-in user.
	uid := cmd.Stdout("id", "-u")
	gid := cmd.Stdout("id", "-g")
	username := cmd.Stdout("whoami")
	// Just use the username for group name, it doesn't matter as long as
	// the IDs are right.
	df.AddRun(fmt.Sprintf("groupadd -g %s %s", gid, username))
	// Explanation of some of the below useradd flags:
	//   -M means do not create home directory, which we do not need
	//   --no-log-init means do not create a 32G sparse file (which Docker commit
	//       cannot handle properly, and tries to create a non-sparse 32G file.)
	df.AddRun(fmt.Sprintf("useradd --no-log-init -M --uid %s --gid %s %s", uid, gid, username))
	df.AddRun("npm install -g npm@2")
	return df
}
예제 #7
0
func (t *CompileTarget) DockerRun(c *core.Context) *docker.Run {
	containerName := t.ContainerName(c)
	run := docker.NewRun(c.DockerTag())
	run.Name = containerName
	run.AddEnv("ARTIFACT_NAME", t.artifactName(c))
	uid := cmd.Stdout("id", "-u")
	gid := cmd.Stdout("id", "-g")
	artifactOwner := fmt.Sprintf("%s:%s", uid, gid)
	run.AddEnv("ARTIFACT_OWNER", artifactOwner)
	artDir := t.artifactDir(c)
	dir.EnsureExists(artDir)
	run.AddVolume(artDir, "/artifacts")
	run.AddVolume(c.WorkDir, "/wd")
	binName := fmt.Sprintf("%s-%s", c.CanonicalPackageName(), c.BuildVersion)
	run.Command = fmt.Sprintf("[ -d Godeps ] && godep go build -o %s || go build -o %s",
		binName, binName)
	return run
}
예제 #8
0
func RunningVMs() []string {
	list := []string{}
	for _, v := range VMs() {
		if cmd.Stdout("docker-machine", "status", v) == "Running" {
			list = append(list, v)
		}
	}
	return list
}
예제 #9
0
func GetContext(action string) *Context {
	var c = config.Load()
	registry := c.DockerRegistry
	gitInfo := git.GetInfo()
	bs := GetBuildState(action, gitInfo)
	wd, err := os.Getwd()
	if err != nil {
		cli.Fatalf("Unable to get current working directory: %s", err)
	}
	return &Context{
		Git:            gitInfo,
		WorkDir:        wd,
		TargetName:     action,
		DockerRegistry: registry,
		Host:           cmd.Stdout("hostname"),
		FullHost:       cmd.Stdout("hostname", "-f"),
		User:           getUser(),
		BuildState:     bs,
		BuildVersion:   buildVersion(gitInfo),
	}
}
예제 #10
0
func (t *TestTarget) Dockerfile(c *core.Context) *docker.Dockerfile {
	df := &docker.Dockerfile{}
	df.From = t.pack.baseImageTag("test")
	c.TemporaryLinkResource("build-prep.bash")
	buildPrepContainerPath := "/build-prep.bash"
	df.AddAdd("build-prep.bash", buildPrepContainerPath)
	df.AddRun(fmt.Sprintf("chmod +x %s", buildPrepContainerPath))
	uid := cmd.Stdout("id", "-u")
	gid := cmd.Stdout("id", "-g")
	username := cmd.Stdout("whoami")
	// Just use the username for group name, it doesn't matter as long as
	// the IDs are right.
	groupAdd := fmt.Sprintf("groupadd -g %s %s", gid, username)
	// Explanation of some of the below useradd flags:
	//   -M means do not create home directory, which we do not need
	//   --no-log-init means do not create a 32G sparse file (which Docker commit
	//       cannot handle properly, and tries to create a non-sparse 32G file.)
	userAdd := fmt.Sprintf("useradd --no-log-init -M --uid %s --gid %s %s", uid, gid, username)
	df.AddRun(fmt.Sprintf("%s && %s", groupAdd, userAdd))
	df.Entrypoint = []string{"/build-prep.bash"}
	return df
}
예제 #11
0
파일: state.go 프로젝트: liamjbennett/sous
// CalculateTreeHash returns a hash of the current state of the working tree,
// leaning heavily on git for optimisation.
func CalculateTreeHash() string {
	inputs := []string{}
	indexDiffs := cmd.Stdout("git", "diff-index", "HEAD")
	if len(indexDiffs) != 0 {
		inputs = append(inputs, indexDiffs)
	}
	newFiles := git.UntrackedUnignoredFiles()
	if len(newFiles) != 0 {
		for _, f := range newFiles {
			inputs = append(inputs, f)
			if content, ok := file.ReadString(f); ok {
				inputs = append(inputs, content)
			}
		}
	}
	return HashSum(inputs...)
}
예제 #12
0
func getUser() string {
	if buildingInCI() {
		return "ci"
	}
	return cmd.Stdout("id", "-un")
}