|
5 | 5 | package ociruntime |
6 | 6 |
|
7 | 7 | import ( |
8 | | - "bytes" |
9 | 8 | "context" |
10 | 9 | "errors" |
11 | 10 | "fmt" |
12 | | - "github.com/rs/zerolog/log" |
13 | | - "github.com/steadybit/action-kit/go/action_kit_commons/utils" |
14 | 11 | "os" |
15 | 12 | "path/filepath" |
16 | | - "runtime/trace" |
17 | 13 | "strconv" |
| 14 | + |
| 15 | + "github.com/rs/zerolog/log" |
| 16 | + "github.com/steadybit/action-kit/go/action_kit_commons/utils" |
18 | 17 | ) |
19 | 18 |
|
20 | 19 | type containerBundle struct { |
@@ -86,38 +85,28 @@ func (b *containerBundle) mountRootfsOverlay(ctx context.Context, image string) |
86 | 85 | } |
87 | 86 |
|
88 | 87 | func (b *containerBundle) CopyFileFromProcess(ctx context.Context, pid int, fromPath, toPath string) error { |
89 | | - defer trace.StartRegion(ctx, "utils.CopyFileFromProcessToBundle").End() |
90 | | - var out bytes.Buffer |
91 | | - cmd := utils.RootCommandContext(ctx, "cat", filepath.Join("/proc", strconv.Itoa(pid), "root", fromPath)) |
92 | | - cmd.Stdout = &out |
93 | | - cmd.Stderr = &out |
94 | | - if err := cmd.Run(); err != nil { |
95 | | - return fmt.Errorf("%w: %s", err, out.String()) |
| 88 | + out, err := utils.RootCommandContext(ctx, "cat", filepath.Join("/proc", strconv.Itoa(pid), "root", fromPath)).CombinedOutput() |
| 89 | + if err != nil { |
| 90 | + return fmt.Errorf("failed to mount %s (%w): %s", fromPath, err, out) |
96 | 91 | } |
97 | 92 |
|
98 | | - return os.WriteFile(filepath.Join(b.path, "rootfs", toPath), out.Bytes(), 0644) |
| 93 | + return os.WriteFile(filepath.Join(b.path, "rootfs", toPath), out, 0644) |
99 | 94 | } |
100 | 95 |
|
101 | 96 | func (b *containerBundle) MountFromProcess(ctx context.Context, fromPid int, fromPath, toPath string) error { |
102 | | - defer trace.StartRegion(ctx, "utils.MountFromProcessToBundle").End() |
103 | | - |
104 | 97 | mountpoint := filepath.Join(b.path, "rootfs", toPath) |
105 | 98 | log.Trace(). |
106 | 99 | Int("fromPid", fromPid). |
107 | 100 | Str("fromPath", fromPath). |
108 | | - Str("mountpoint", mountpoint). |
| 101 | + Str("mount-point", mountpoint). |
109 | 102 | Msg("mount from process to bundle") |
110 | 103 |
|
111 | 104 | if err := os.Mkdir(mountpoint, 0755); err != nil && !os.IsExist(err) { |
112 | | - return fmt.Errorf("failed to create mountpoint %s: %w", mountpoint, err) |
| 105 | + return fmt.Errorf("failed to create mount point %s: %w", mountpoint, err) |
113 | 106 | } |
114 | 107 |
|
115 | | - var out bytes.Buffer |
116 | | - cmd := utils.RootCommandContext(ctx, nsmountPath, strconv.Itoa(fromPid), fromPath, strconv.Itoa(os.Getpid()), mountpoint) |
117 | | - cmd.Stdout = &out |
118 | | - cmd.Stderr = &out |
119 | | - if err := cmd.Run(); err != nil { |
120 | | - return fmt.Errorf("%w: %s", err, out.String()) |
| 108 | + if out, err := utils.RootCommandContext(ctx, nsmountPath, strconv.Itoa(fromPid), fromPath, strconv.Itoa(os.Getpid()), mountpoint).CombinedOutput(); err != nil { |
| 109 | + return fmt.Errorf("failed to mount %s (%w): %s", fromPath, err, out) |
121 | 110 | } |
122 | 111 | b.addFinalizer(func() error { |
123 | 112 | return unmount(context.Background(), mountpoint) |
|
0 commit comments