AppRunner: Reports detailed status

Status includes: commit hash, running commands and logs

Change-Id: I5f28f69710b30508bb3296a22fc97b9ad7553844
diff --git a/apps/app-runner/main.go b/apps/app-runner/main.go
index 9c57225..b9acaa6 100644
--- a/apps/app-runner/main.go
+++ b/apps/app-runner/main.go
@@ -35,7 +35,7 @@
 	Env  []string `json:"env"`
 }
 
-func CloneRepositoryBranch(addr, branch, rootDir string, signer ssh.Signer, path string) error {
+func CloneRepositoryBranch(addr, branch, rootDir string, signer ssh.Signer, path string) (string, error) {
 	ref := fmt.Sprintf("refs/heads/%s", branch)
 	opts := &git.CloneOptions{
 		URL:             addr,
@@ -61,29 +61,13 @@
 	}
 	c, err := git.Clone(memory.NewStorage(), osfs.New(path, osfs.WithBoundOS()), opts)
 	if err != nil {
-		return err
+		return "", err
 	}
-	wt, err := c.Worktree()
+	head, err := c.Head()
 	if err != nil {
-		return err
+		return "", err
 	}
-	if wt == nil {
-		panic(wt)
-	}
-	// TODO(gio): This should probably be removed.
-	// sb, err := wt.Submodules()
-	// if err != nil {
-	// 	return err
-	// }
-	// if err := sb.Init(); err != nil {
-	// 	return err
-	// }
-	// if err := sb.Update(&git.SubmoduleUpdateOptions{
-	// 	Depth: 1,
-	// }); err != nil {
-	// 	return err
-	// }
-	return err
+	return head.Hash().String(), nil
 }
 
 func main() {
@@ -92,6 +76,10 @@
 	if !ok {
 		panic("no SELF_IP")
 	}
+	id, ok := os.LookupEnv("SELF_ID")
+	if !ok {
+		panic("no SELF_ID")
+	}
 	var signer ssh.Signer
 	// TODO(gio): revisit this logic
 	if *sshKey != "" && !(strings.HasPrefix(*repoAddr, "http://") || strings.HasPrefix(*repoAddr, "https://")) {
@@ -104,7 +92,7 @@
 			panic(err)
 		}
 	}
-	if err := CloneRepositoryBranch(*repoAddr, *branch, *rootDir, signer, *appDir); err != nil {
+	if err := os.Mkdir(*appDir, os.ModePerm); err != nil {
 		panic(err)
 	}
 	r, err := os.Open(*runCfg)
@@ -116,7 +104,7 @@
 	if err := json.NewDecoder(r).Decode(&cmds); err != nil {
 		panic(err)
 	}
-	s := NewServer(*port, *appId, *service, *repoAddr, *branch, *rootDir, signer, *appDir, cmds, self, *managerAddr)
+	s := NewServer(*port, *appId, *service, id, *repoAddr, *branch, *rootDir, signer, *appDir, cmds, self, *managerAddr)
 	if err := s.Start(); err != nil {
 		log.Fatal(err)
 	}