mirror of
https://github.com/linuxkit/linuxkit.git
synced 2025-07-19 17:26:28 +00:00
moby: Add debug logging to "moby build" code
Signed-off-by: Rolf Neugebauer <rolf.neugebauer@docker.com>
This commit is contained in:
parent
adb0f9db3d
commit
37545913a6
@ -10,9 +10,12 @@ import (
|
|||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"os/exec"
|
"os/exec"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
|
log "github.com/Sirupsen/logrus"
|
||||||
)
|
)
|
||||||
|
|
||||||
func dockerRun(args ...string) ([]byte, error) {
|
func dockerRun(args ...string) ([]byte, error) {
|
||||||
|
log.Debugf("docker run: %s", strings.Join(args, " "))
|
||||||
docker, err := exec.LookPath("docker")
|
docker, err := exec.LookPath("docker")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return []byte{}, errors.New("Docker does not seem to be installed")
|
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)
|
return []byte{}, fmt.Errorf("%v: %s", err, stderr)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
log.Debugf("docker run: %s...Done", strings.Join(args, " "))
|
||||||
return stdout, nil
|
return stdout, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func dockerRunInput(input io.Reader, args ...string) ([]byte, error) {
|
func dockerRunInput(input io.Reader, args ...string) ([]byte, error) {
|
||||||
|
log.Debugf("docker run (input): %s", strings.Join(args, " "))
|
||||||
docker, err := exec.LookPath("docker")
|
docker, err := exec.LookPath("docker")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return []byte{}, errors.New("Docker does not seem to be installed")
|
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)
|
return []byte{}, fmt.Errorf("%v: %s", err, stderr)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
log.Debugf("docker run (input): %s...Done", strings.Join(args, " "))
|
||||||
return stdout, nil
|
return stdout, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func dockerCreate(image string) (string, error) {
|
func dockerCreate(image string) (string, error) {
|
||||||
|
log.Debugf("docker create: %s", image)
|
||||||
docker, err := exec.LookPath("docker")
|
docker, err := exec.LookPath("docker")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return "", errors.New("Docker does not seem to be installed")
|
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))
|
container := strings.TrimSpace(string(stdout))
|
||||||
|
log.Debugf("docker create: %s...Done", image)
|
||||||
return container, nil
|
return container, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func dockerExport(container string) ([]byte, error) {
|
func dockerExport(container string) ([]byte, error) {
|
||||||
|
log.Debugf("docker export: %s", container)
|
||||||
docker, err := exec.LookPath("docker")
|
docker, err := exec.LookPath("docker")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return []byte{}, errors.New("Docker does not seem to be installed")
|
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)
|
return []byte{}, fmt.Errorf("%v: %s", err, stderr)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
log.Debugf("docker export: %s...Done", container)
|
||||||
return stdout, nil
|
return stdout, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func dockerRm(container string) error {
|
func dockerRm(container string) error {
|
||||||
|
log.Debugf("docker rm: %s", container)
|
||||||
docker, err := exec.LookPath("docker")
|
docker, err := exec.LookPath("docker")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return errors.New("Docker does not seem to be installed")
|
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)
|
return fmt.Errorf("%v: %s", err, stderr)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
log.Debugf("docker rm: %s...Done", container)
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func dockerPull(image string) error {
|
func dockerPull(image string) error {
|
||||||
|
log.Debugf("docker pull: %s", image)
|
||||||
docker, err := exec.LookPath("docker")
|
docker, err := exec.LookPath("docker")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return errors.New("Docker does not seem to be installed")
|
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)
|
return fmt.Errorf("%v: %s", err, stderr)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
log.Debugf("docker pull: %s...Done", image)
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
@ -7,6 +7,8 @@ import (
|
|||||||
"io"
|
"io"
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
|
log "github.com/Sirupsen/logrus"
|
||||||
)
|
)
|
||||||
|
|
||||||
// This uses Docker to convert a Docker image into a tarball. It would be an improvement if we
|
// 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
|
// 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) {
|
func ImageExtract(image, prefix string) ([]byte, error) {
|
||||||
|
log.Debugf("image extract: %s %s", image, prefix)
|
||||||
out := new(bytes.Buffer)
|
out := new(bytes.Buffer)
|
||||||
tw := tar.NewWriter(out)
|
tw := tar.NewWriter(out)
|
||||||
err := tarPrefix(prefix, tw)
|
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 {
|
func imageTar(image, prefix string, tw *tar.Writer) error {
|
||||||
|
log.Debugf("image tar: %s %s", image, prefix)
|
||||||
if prefix != "" && prefix[len(prefix)-1] != byte('/') {
|
if prefix != "" && prefix[len(prefix)-1] != byte('/') {
|
||||||
return fmt.Errorf("prefix does not end with /: %s", prefix)
|
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
|
return err
|
||||||
}
|
}
|
||||||
if exclude[hdr.Name] {
|
if exclude[hdr.Name] {
|
||||||
|
log.Debugf("image tar: %s %s exclude %s", image, prefix, hdr.Name)
|
||||||
io.Copy(ioutil.Discard, tr)
|
io.Copy(ioutil.Discard, tr)
|
||||||
} else if replace[hdr.Name] != "" {
|
} else if replace[hdr.Name] != "" {
|
||||||
contents := replace[hdr.Name]
|
contents := replace[hdr.Name]
|
||||||
hdr.Size = int64(len(contents))
|
hdr.Size = int64(len(contents))
|
||||||
hdr.Name = prefix + hdr.Name
|
hdr.Name = prefix + hdr.Name
|
||||||
|
log.Debugf("image tar: %s %s add %s", image, prefix, hdr.Name)
|
||||||
tw.WriteHeader(hdr)
|
tw.WriteHeader(hdr)
|
||||||
buf := bytes.NewBufferString(contents)
|
buf := bytes.NewBufferString(contents)
|
||||||
io.Copy(tw, buf)
|
io.Copy(tw, buf)
|
||||||
io.Copy(ioutil.Discard, tr)
|
io.Copy(ioutil.Discard, tr)
|
||||||
} else {
|
} else {
|
||||||
|
log.Debugf("image tar: %s %s add %s", image, prefix, hdr.Name)
|
||||||
hdr.Name = prefix + hdr.Name
|
hdr.Name = prefix + hdr.Name
|
||||||
tw.WriteHeader(hdr)
|
tw.WriteHeader(hdr)
|
||||||
io.Copy(tw, tr)
|
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
|
// 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) {
|
func ImageBundle(path, image, config string) ([]byte, error) {
|
||||||
|
log.Debugf("image bundle: %s %s cfg: %s", path, image, config)
|
||||||
out := new(bytes.Buffer)
|
out := new(bytes.Buffer)
|
||||||
tw := tar.NewWriter(out)
|
tw := tar.NewWriter(out)
|
||||||
err := tarPrefix(path+"/rootfs/", tw)
|
err := tarPrefix(path+"/rootfs/", tw)
|
||||||
|
@ -6,6 +6,8 @@ import (
|
|||||||
"fmt"
|
"fmt"
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"os"
|
"os"
|
||||||
|
|
||||||
|
log "github.com/Sirupsen/logrus"
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
@ -18,6 +20,7 @@ const (
|
|||||||
)
|
)
|
||||||
|
|
||||||
func outputs(m *Moby, base string, bzimage []byte, initrd []byte) error {
|
func outputs(m *Moby, base string, bzimage []byte, initrd []byte) error {
|
||||||
|
log.Debugf("output: %s %s", m.Outputs, base)
|
||||||
for _, o := range m.Outputs {
|
for _, o := range m.Outputs {
|
||||||
switch o.Format {
|
switch o.Format {
|
||||||
case "kernel+initrd":
|
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 {
|
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)
|
buf, err := tarInitrdKernel(bzimage, initrd)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
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 {
|
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)
|
buf, err := tarInitrdKernel(bzimage, initrd)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
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 {
|
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))
|
err := ioutil.WriteFile(base+"-initrd.img", initrd, os.FileMode(0644))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
|
Loading…
Reference in New Issue
Block a user