Skip to content

Instantly share code, notes, and snippets.

@rochacon
Created October 20, 2014 05:28
Show Gist options
  • Save rochacon/5cf61b18bf789f87ab08 to your computer and use it in GitHub Desktop.
Save rochacon/5cf61b18bf789f87ab08 to your computer and use it in GitHub Desktop.
Simple script to list Procfile entries from a tar stream
//
// Read and parse an Procfile of a tar stream from stdin
//
// example: git archive HEAD | list-app-processes
//
//
package main
import (
"archive/tar"
"fmt"
"gopkg.in/yaml.v1"
"io"
"io/ioutil"
"log"
"os"
)
type Processes map[string]string
func main() {
tarfile := tar.NewReader(os.Stdin)
for {
header, err := tarfile.Next()
if err == io.EOF {
break
}
if err != nil {
log.Fatal(err)
}
if header.Name == "Procfile" {
procfile, err := ioutil.ReadAll(tarfile)
if err != nil {
log.Fatal(err)
}
processes := Processes{}
err = yaml.Unmarshal(procfile, &processes)
if err != nil {
log.Fatal(err)
}
for process, _ := range processes {
fmt.Println(process)
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment