in source.go [465:580]
func (s Source) Doc(name string) (io.Reader, error) {
b := bytes.NewBuffer(nil)
switch {
case s.Context != nil:
fmt.Fprintln(b, "Generated from a local docker build context and is unreproducible.")
case s.Build != nil:
fmt.Fprintln(b, "Generated from a docker build:")
fmt.Fprintln(b, " Docker Build Target:", s.Build.Target)
sub, err := s.Build.Source.Doc(name)
if err != nil {
return nil, err
}
scanner := bufio.NewScanner(sub)
for scanner.Scan() {
fmt.Fprintf(b, " %s\n", scanner.Text())
}
if scanner.Err() != nil {
return nil, scanner.Err()
}
if len(s.Build.Args) > 0 {
sorted := SortMapKeys(s.Build.Args)
fmt.Fprintln(b, " Build Args:")
for _, k := range sorted {
fmt.Fprintf(b, " %s=%s\n", k, s.Build.Args[k])
}
}
p := "Dockerfile"
if s.Build.DockerfilePath != "" {
p = s.Build.DockerfilePath
}
fmt.Fprintln(b, " Dockerfile path in context:", p)
case s.HTTP != nil:
fmt.Fprintln(b, "Generated from a http(s) source:")
fmt.Fprintln(b, " URL:", s.HTTP.URL)
case s.Git != nil:
git := s.Git
ref, err := gitutil.ParseGitRef(git.URL)
if err != nil {
return nil, err
}
fmt.Fprintln(b, "Generated from a git repository:")
fmt.Fprintln(b, " Remote:", ref.Remote)
fmt.Fprintln(b, " Ref:", git.Commit)
if s.Path != "" {
fmt.Fprintln(b, " Extracted path:", s.Path)
}
case s.DockerImage != nil:
img := s.DockerImage
if img.Cmd == nil {
fmt.Fprintln(b, "Generated from a docker image:")
fmt.Fprintln(b, " Image:", img.Ref)
if s.Path != "" {
fmt.Fprintln(b, " Extracted path:", s.Path)
}
} else {
fmt.Fprintln(b, "Generated from running a command(s) in a docker image:")
fmt.Fprintln(b, " Image:", img.Ref)
if s.Path != "" {
fmt.Fprintln(b, " Extracted path:", s.Path)
}
if len(img.Cmd.Env) > 0 {
fmt.Fprintln(b, " With the following environment variables set for all commands:")
sorted := SortMapKeys(img.Cmd.Env)
for _, k := range sorted {
fmt.Fprintf(b, " %s=%s\n", k, img.Cmd.Env[k])
}
}
if img.Cmd.Dir != "" {
fmt.Fprintln(b, " Working Directory:", img.Cmd.Dir)
}
fmt.Fprintln(b, " Command(s):")
for _, step := range img.Cmd.Steps {
fmt.Fprintf(b, " %s\n", step.Command)
if len(step.Env) > 0 {
fmt.Fprintln(b, " With the following environment variables set for this command:")
sorted := SortMapKeys(step.Env)
for _, k := range sorted {
fmt.Fprintf(b, " %s=%s\n", k, step.Env[k])
}
}
}
if len(img.Cmd.Mounts) > 0 {
fmt.Fprintln(b, " With the following items mounted:")
for _, src := range img.Cmd.Mounts {
sub, err := src.Spec.Doc(name)
if err != nil {
return nil, err
}
fmt.Fprintln(b, " Destination Path:", src.Dest)
scanner := bufio.NewScanner(sub)
for scanner.Scan() {
fmt.Fprintf(b, " %s\n", scanner.Text())
}
if scanner.Err() != nil {
return nil, scanner.Err()
}
}
}
return b, nil
}
case s.Inline != nil:
fmt.Fprintln(b, "Generated from an inline source:")
s.Inline.Doc(b, name)
default:
// This should be unrecable.
// We could panic here, but ultimately this is just a doc string and parsing user generated content.
fmt.Fprintln(b, "Generated from an unknown source type")
}
return b, nil
}