moby: Add debug logging to "moby build" code

Signed-off-by: Rolf Neugebauer <rolf.neugebauer@docker.com>
This commit is contained in:
Rolf Neugebauer 2017-03-28 22:26:31 +01:00
parent adb0f9db3d
commit 37545913a6
3 changed files with 28 additions and 0 deletions

View File

@ -10,9 +10,12 @@ import (
"io/ioutil"
"os/exec"
"strings"
log "github.com/Sirupsen/logrus"
)
func dockerRun(args ...string) ([]byte, error) {
log.Debugf("docker run: %s", strings.Join(args, " "))
docker, err := exec.LookPath("docker")
if err != nil {
return []byte{}, errors.New("Docker does not seem to be installed")
@ -50,10 +53,12 @@ func dockerRun(args ...string) ([]byte, error) {
return []byte{}, fmt.Errorf("%v: %s", err, stderr)
}
log.Debugf("docker run: %s...Done", strings.Join(args, " "))
return stdout, nil
}
func dockerRunInput(input io.Reader, args ...string) ([]byte, error) {
log.Debugf("docker run (input): %s", strings.Join(args, " "))
docker, err := exec.LookPath("docker")
if err != nil {
return []byte{}, errors.New("Docker does not seem to be installed")
@ -92,10 +97,12 @@ func dockerRunInput(input io.Reader, args ...string) ([]byte, error) {
return []byte{}, fmt.Errorf("%v: %s", err, stderr)
}
log.Debugf("docker run (input): %s...Done", strings.Join(args, " "))
return stdout, nil
}
func dockerCreate(image string) (string, error) {
log.Debugf("docker create: %s", image)
docker, err := exec.LookPath("docker")
if err != nil {
return "", errors.New("Docker does not seem to be installed")
@ -135,10 +142,12 @@ func dockerCreate(image string) (string, error) {
}
container := strings.TrimSpace(string(stdout))
log.Debugf("docker create: %s...Done", image)
return container, nil
}
func dockerExport(container string) ([]byte, error) {
log.Debugf("docker export: %s", container)
docker, err := exec.LookPath("docker")
if err != nil {
return []byte{}, errors.New("Docker does not seem to be installed")
@ -176,10 +185,12 @@ func dockerExport(container string) ([]byte, error) {
return []byte{}, fmt.Errorf("%v: %s", err, stderr)
}
log.Debugf("docker export: %s...Done", container)
return stdout, nil
}
func dockerRm(container string) error {
log.Debugf("docker rm: %s", container)
docker, err := exec.LookPath("docker")
if err != nil {
return errors.New("Docker does not seem to be installed")
@ -217,10 +228,12 @@ func dockerRm(container string) error {
return fmt.Errorf("%v: %s", err, stderr)
}
log.Debugf("docker rm: %s...Done", container)
return nil
}
func dockerPull(image string) error {
log.Debugf("docker pull: %s", image)
docker, err := exec.LookPath("docker")
if err != nil {
return errors.New("Docker does not seem to be installed")
@ -258,5 +271,6 @@ func dockerPull(image string) error {
return fmt.Errorf("%v: %s", err, stderr)
}
log.Debugf("docker pull: %s...Done", image)
return nil
}

View File

@ -7,6 +7,8 @@ import (
"io"
"io/ioutil"
"strings"
log "github.com/Sirupsen/logrus"
)
// This uses Docker to convert a Docker image into a tarball. It would be an improvement if we
@ -39,6 +41,7 @@ nameserver 2001:4860:4860::8844
// ImageExtract extracts the filesystem from an image and returns a tarball with the files prefixed by the given path
func ImageExtract(image, prefix string) ([]byte, error) {
log.Debugf("image extract: %s %s", image, prefix)
out := new(bytes.Buffer)
tw := tar.NewWriter(out)
err := tarPrefix(prefix, tw)
@ -83,6 +86,7 @@ func tarPrefix(path string, tw *tar.Writer) error {
}
func imageTar(image, prefix string, tw *tar.Writer) error {
log.Debugf("image tar: %s %s", image, prefix)
if prefix != "" && prefix[len(prefix)-1] != byte('/') {
return fmt.Errorf("prefix does not end with /: %s", prefix)
}
@ -113,16 +117,19 @@ func imageTar(image, prefix string, tw *tar.Writer) error {
return err
}
if exclude[hdr.Name] {
log.Debugf("image tar: %s %s exclude %s", image, prefix, hdr.Name)
io.Copy(ioutil.Discard, tr)
} else if replace[hdr.Name] != "" {
contents := replace[hdr.Name]
hdr.Size = int64(len(contents))
hdr.Name = prefix + hdr.Name
log.Debugf("image tar: %s %s add %s", image, prefix, hdr.Name)
tw.WriteHeader(hdr)
buf := bytes.NewBufferString(contents)
io.Copy(tw, buf)
io.Copy(ioutil.Discard, tr)
} else {
log.Debugf("image tar: %s %s add %s", image, prefix, hdr.Name)
hdr.Name = prefix + hdr.Name
tw.WriteHeader(hdr)
io.Copy(tw, tr)
@ -137,6 +144,7 @@ func imageTar(image, prefix string, tw *tar.Writer) error {
// ImageBundle produces an OCI bundle at the given path in a tarball, given an image and a config.json
func ImageBundle(path, image, config string) ([]byte, error) {
log.Debugf("image bundle: %s %s cfg: %s", path, image, config)
out := new(bytes.Buffer)
tw := tar.NewWriter(out)
err := tarPrefix(path+"/rootfs/", tw)

View File

@ -6,6 +6,8 @@ import (
"fmt"
"io/ioutil"
"os"
log "github.com/Sirupsen/logrus"
)
const (
@ -18,6 +20,7 @@ const (
)
func outputs(m *Moby, base string, bzimage []byte, initrd []byte) error {
log.Debugf("output: %s %s", m.Outputs, base)
for _, o := range m.Outputs {
switch o.Format {
case "kernel+initrd":
@ -129,6 +132,7 @@ func tarInitrdKernel(bzimage, initrd []byte) (*bytes.Buffer, error) {
}
func outputImg(image, filename string, bzimage []byte, initrd []byte, args ...string) error {
log.Debugf("output img: %s %s", image, filename)
buf, err := tarInitrdKernel(bzimage, initrd)
if err != nil {
return err
@ -146,6 +150,7 @@ func outputImg(image, filename string, bzimage []byte, initrd []byte, args ...st
}
func outputISO(image, filename string, bzimage []byte, initrd []byte, args ...string) error {
log.Debugf("output iso: %s %s", image, filename)
buf, err := tarInitrdKernel(bzimage, initrd)
if err != nil {
return err
@ -163,6 +168,7 @@ func outputISO(image, filename string, bzimage []byte, initrd []byte, args ...st
}
func outputKernelInitrd(base string, bzimage []byte, initrd []byte, cmdline string) error {
log.Debugf("output kernel/initrd: %s %s", base, cmdline)
err := ioutil.WriteFile(base+"-initrd.img", initrd, os.FileMode(0644))
if err != nil {
return err