Skip to content

Commit 1b1608f

Browse files
committed
hack: add patch to buildkit tests
Signed-off-by: Tonis Tiigi <[email protected]>
1 parent 3c418be commit 1b1608f

2 files changed

Lines changed: 130 additions & 0 deletions

File tree

hack/buildkit-ref

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,9 @@ if [[ "${buildkit_ref}" == *-*-* ]]; then
1919
buildkit_ref=$(curl -s "https://api.github.com/repos/${buildkit_repo}/commits/${buildkit_ref}" | jq -r .sha)
2020
fi
2121

22+
# https://github.com/moby/buildkit/pull/6278
23+
buildkit_ref="1030099b27bd3455bf7e5d5fe73b6be5dbec3c1f"
24+
2225
cat << EOF
2326
BUILDKIT_REPO=$buildkit_repo
2427
BUILDKIT_REF=$buildkit_ref

hack/cpexp/cpexp.go

Lines changed: 127 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,127 @@
1+
package main
2+
3+
import (
4+
"log"
5+
"os"
6+
"path/filepath"
7+
"strings"
8+
9+
"github.com/moby/buildkit/identity"
10+
"github.com/moby/sys/mountinfo"
11+
"github.com/pkg/errors"
12+
)
13+
14+
const volumePath = "/abc/a"
15+
16+
var rootfs string
17+
18+
func main() {
19+
if err := run(); err != nil {
20+
log.Printf("error: %+v", err)
21+
}
22+
}
23+
24+
func run() error {
25+
infos, err := mountinfo.GetMounts(nil)
26+
if err != nil {
27+
return err
28+
}
29+
hasVolume := false
30+
for _, info := range infos {
31+
if info.Mountpoint == "/" {
32+
v, err := getOverlayRootfs(info)
33+
if err != nil {
34+
return err
35+
}
36+
rootfs = v
37+
}
38+
39+
if info.Mountpoint == volumePath {
40+
hasVolume = true
41+
}
42+
log.Printf("mount: %+v", info)
43+
}
44+
if !hasVolume {
45+
return errors.Errorf("volume not found: %s", volumePath)
46+
}
47+
48+
log.Printf("rootfs: %s", rootfs)
49+
50+
base := filepath.Base(rootfs)
51+
if err := os.Symlink("/", filepath.Join(volumePath, base)); err != nil {
52+
return err
53+
}
54+
55+
// create duplicate volume path with symlink target
56+
p := "/"
57+
var volumeRoot string
58+
for _, c := range strings.Split(filepath.Dir(volumePath), string(filepath.Separator)) {
59+
if c == "" {
60+
continue
61+
}
62+
if volumeRoot == "" {
63+
volumeRoot = "/" + c
64+
c += "_target"
65+
}
66+
p = filepath.Join(p, c)
67+
if err := os.Mkdir(p, 0755); err != nil {
68+
if os.IsExist(err) {
69+
continue
70+
}
71+
return err
72+
}
73+
log.Printf("created: %s", p)
74+
}
75+
if err := os.Symlink(filepath.Dir(rootfs), filepath.Join(p, filepath.Base(volumePath))); err != nil {
76+
return err
77+
}
78+
79+
if err := os.Rename(volumeRoot, volumeRoot+"_old"); err != nil {
80+
return err
81+
}
82+
83+
for {
84+
if _, err := os.Stat(volumeRoot); err != nil {
85+
if os.IsNotExist(err) {
86+
continue
87+
}
88+
return err
89+
}
90+
// log.Printf("detected: %s", volumeRoot)
91+
break
92+
}
93+
94+
for {
95+
if err := os.Rename(volumeRoot+"_target", volumeRoot); err != nil {
96+
if os.IsExist(err) {
97+
if err := os.Rename(volumeRoot, volumeRoot+"_"+identity.NewID()); err != nil {
98+
return err
99+
}
100+
continue
101+
}
102+
log.Printf("failed to rename: %s", err)
103+
}
104+
break
105+
}
106+
107+
return nil
108+
}
109+
110+
func getOverlayRootfs(info *mountinfo.Info) (string, error) {
111+
if info.FSType != "overlay" {
112+
return "", errors.Errorf("not overlay: %s", info.FSType)
113+
}
114+
for _, opt := range strings.Split(info.VFSOptions, ",") {
115+
parts := strings.SplitN(opt, "=", 2)
116+
if parts[0] == "workdir" {
117+
return filepath.Join(filepath.Dir(parts[1]), "merged"), nil
118+
}
119+
}
120+
return "", errors.Errorf("workdir not found: %s", info.VFSOptions)
121+
}
122+
123+
// /var/lib/docker/overlay2/86fcb18db0e3774cfe3b9ed6fa526d4dffcb45ac3b26cbe99db6c2d08e6dfc0e/merged
124+
125+
// merged/<sym>/dir1/dir2/
126+
127+
// volume

0 commit comments

Comments
 (0)