Skip to content

Commit 2afc050

Browse files
authored
Merge pull request #4735 from moby/v0.13.0-picks
[v0.13] cherry-picks for v0.13.0
2 parents 5872120 + b9e1581 commit 2afc050

File tree

16 files changed

+215
-23
lines changed

16 files changed

+215
-23
lines changed

.github/workflows/validate.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,9 @@ jobs:
6363

6464
archutil-arm64:
6565
runs-on: ubuntu-22.04
66+
# TODO: enable when binutils-loongarch64-linux-gnu pkg is available for aarch64 arch
67+
# https://github.com/moby/buildkit/pull/4392#issuecomment-1938223235
68+
if: false
6669
steps:
6770
-
6871
name: Checkout

docs/windows.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,7 @@ Now that everything is setup, let's build a [simple _hello world_ image](https:/
8989
```powershell
9090
Set-Content Dockerfile @"
9191
FROM mcr.microsoft.com/windows/nanoserver:ltsc2022
92+
USER ContainerAdministrator
9293
COPY hello.txt C:/
9394
RUN echo "Goodbye!" >> hello.txt
9495
CMD ["cmd", "/C", "type C:\\hello.txt"]

frontend/dockerfile/dockerfile2llb/convert.go

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1252,18 +1252,30 @@ func dispatchCopy(d *dispatchState, cfg copyConfig) error {
12521252
a = a.Copy(st, f, dest, opts...)
12531253
}
12541254
} else {
1255+
var patterns []string
1256+
if cfg.parents {
1257+
// detect optional pivot point
1258+
parent, pattern, ok := strings.Cut(src, "/./")
1259+
if !ok {
1260+
pattern = src
1261+
src = "/"
1262+
} else {
1263+
src = parent
1264+
}
1265+
1266+
pattern, err = system.NormalizePath("/", pattern, d.platform.OS, false)
1267+
if err != nil {
1268+
return errors.Wrap(err, "removing drive letter")
1269+
}
1270+
1271+
patterns = []string{strings.TrimPrefix(pattern, "/")}
1272+
}
1273+
12551274
src, err = system.NormalizePath("/", src, d.platform.OS, false)
12561275
if err != nil {
12571276
return errors.Wrap(err, "removing drive letter")
12581277
}
12591278

1260-
var patterns []string
1261-
if cfg.parents {
1262-
path := strings.TrimPrefix(src, "/")
1263-
patterns = []string{path}
1264-
src = "/"
1265-
}
1266-
12671279
opts := append([]llb.CopyOption{&llb.CopyInfo{
12681280
Mode: mode,
12691281
FollowSymlinks: true,

frontend/dockerfile/dockerfile_parents_test.go

Lines changed: 106 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ import (
1818

1919
var parentsTests = integration.TestFuncs(
2020
testCopyParents,
21+
testCopyRelativeParents,
2122
)
2223

2324
func init() {
@@ -75,3 +76,108 @@ COPY --parents foo1/foo2/ba* .
7576
require.NoError(t, err)
7677
require.Equal(t, "testing2", string(dt))
7778
}
79+
80+
func testCopyRelativeParents(t *testing.T, sb integration.Sandbox) {
81+
f := getFrontend(t, sb)
82+
83+
dockerfile := []byte(`
84+
FROM alpine AS base
85+
WORKDIR /test
86+
RUN <<eot
87+
set -ex
88+
mkdir -p a/b/c/d/e
89+
mkdir -p a/b2/c/d/e
90+
mkdir -p a/b/c2/d/e
91+
mkdir -p a/b/c2/d/e2
92+
touch a/b/c/d/foo
93+
touch a/b/c/d/e/bay
94+
touch a/b2/c/d/e/bar
95+
touch a/b/c2/d/e/baz
96+
touch a/b/c2/d/e2/baz
97+
eot
98+
99+
FROM alpine AS middle
100+
COPY --from=base --parents /test/a/b/./c/d /out/
101+
RUN <<eot
102+
set -ex
103+
[ -d /out/c/d/e ]
104+
[ -f /out/c/d/foo ]
105+
[ ! -d /out/a ]
106+
[ ! -d /out/e ]
107+
eot
108+
109+
FROM alpine AS end
110+
COPY --from=base --parents /test/a/b/c/d/. /out/
111+
RUN <<eot
112+
set -ex
113+
[ -d /out/test/a/b/c/d/e ]
114+
[ -f /out/test/a/b/c/d/foo ]
115+
eot
116+
117+
FROM alpine AS start
118+
COPY --from=base --parents ./test/a/b/c/d /out/
119+
RUN <<eot
120+
set -ex
121+
[ -d /out/test/a/b/c/d/e ]
122+
[ -f /out/test/a/b/c/d/foo ]
123+
eot
124+
125+
FROM alpine AS double
126+
COPY --from=base --parents /test/a/./b/./c /out/
127+
RUN <<eot
128+
set -ex
129+
[ -d /out/b/c/d/e ]
130+
[ -f /out/b/c/d/foo ]
131+
eot
132+
133+
FROM alpine AS wildcard
134+
COPY --from=base --parents /test/a/./*/c /out/
135+
RUN <<eot
136+
set -ex
137+
[ -d /out/b/c/d/e ]
138+
[ -f /out/b2/c/d/e/bar ]
139+
eot
140+
141+
FROM alpine AS doublewildcard
142+
COPY --from=base --parents /test/a/b*/./c/**/e /out/
143+
RUN <<eot
144+
set -ex
145+
[ -d /out/c/d/e ]
146+
[ -f /out/c/d/e/bay ] # via b
147+
[ -f /out/c/d/e/bar ] # via b2
148+
eot
149+
150+
FROM alpine AS doubleinputs
151+
COPY --from=base --parents /test/a/b/c*/./d/**/baz /test/a/b*/./c/**/bar /out/
152+
RUN <<eot
153+
set -ex
154+
[ -f /out/d/e/baz ]
155+
[ ! -f /out/d/e/bay ]
156+
[ -f /out/d/e2/baz ]
157+
[ -f /out/c/d/e/bar ] # via b2
158+
eot
159+
`)
160+
161+
dir := integration.Tmpdir(
162+
t,
163+
fstest.CreateFile("Dockerfile", dockerfile, 0600),
164+
)
165+
166+
c, err := client.New(sb.Context(), sb.Address())
167+
require.NoError(t, err)
168+
defer c.Close()
169+
170+
for _, target := range []string{"middle", "end", "start", "double", "wildcard", "doublewildcard", "doubleinputs"} {
171+
t.Logf("target: %s", target)
172+
_, err = f.Solve(sb.Context(), c, client.SolveOpt{
173+
FrontendAttrs: map[string]string{
174+
"target": target,
175+
},
176+
LocalMounts: map[string]fsutil.FS{
177+
dockerui.DefaultLocalNameDockerfile: dir,
178+
dockerui.DefaultLocalNameContext: dir,
179+
},
180+
}, nil)
181+
require.NoError(t, err)
182+
}
183+
}

frontend/dockerfile/docs/reference.md

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1596,8 +1596,28 @@ COPY --parents ./x/a.txt ./y/a.txt /parents/
15961596
# /parents/y/a.txt
15971597
```
15981598

1599-
This behavior is analogous to the [Linux `cp` utility's](https://www.man7.org/linux/man-pages/man1/cp.1.html)
1600-
`--parents` flag.
1599+
This behavior is similar to the [Linux `cp` utility's](https://www.man7.org/linux/man-pages/man1/cp.1.html)
1600+
`--parents` or [`rsync`](https://man7.org/linux/man-pages/man1/rsync.1.html) `--relative` flag.
1601+
1602+
As with Rsync, it is possible to limit which parent directories are preserved by
1603+
inserting a dot and a slash (`./`) into the source path. If such point exists, only parent
1604+
directories after it will be preserved. This may be especially useful copies between stages
1605+
with `--from` where the source paths need to be absolute.
1606+
1607+
```dockerfile
1608+
# syntax=docker/dockerfile-upstream:master-labs
1609+
FROM scratch
1610+
1611+
COPY --parents ./x/./y/*.txt /parents/
1612+
1613+
# Build context:
1614+
# ./x/y/a.txt
1615+
# ./x/y/b.txt
1616+
#
1617+
# Output:
1618+
# /parents/y/a.txt
1619+
# /parents/y/b.txt
1620+
```
16011621

16021622
Note that, without the `--parents` flag specified, any filename collision will
16031623
fail the Linux `cp` operation with an explicit error message

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ require (
6767
github.com/sirupsen/logrus v1.9.3
6868
github.com/spdx/tools-golang v0.5.3
6969
github.com/stretchr/testify v1.8.4
70-
github.com/tonistiigi/fsutil v0.0.0-20240223190444-7a889f53dbf6
70+
github.com/tonistiigi/fsutil v0.0.0-20240301111122-7525a1af2bb5
7171
github.com/tonistiigi/go-actions-cache v0.0.0-20240227172821-a0b64f338598
7272
github.com/tonistiigi/go-archvariant v1.0.0
7373
github.com/tonistiigi/units v0.0.0-20180711220420-6950e57a87ea

go.sum

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -405,8 +405,8 @@ github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO
405405
github.com/stretchr/testify v1.8.1/go.mod h1:w2LPCIKwWwSfY2zedu0+kehJoqGctiVI29o6fzry7u4=
406406
github.com/stretchr/testify v1.8.4 h1:CcVxjf3Q8PM0mHUKJCdn+eZZtm5yQwehR5yeSVQQcUk=
407407
github.com/stretchr/testify v1.8.4/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo=
408-
github.com/tonistiigi/fsutil v0.0.0-20240223190444-7a889f53dbf6 h1:v9u6pmdUkarXL/1S/6LGcG9wsiBLd9N/WyJq/Y9WPcg=
409-
github.com/tonistiigi/fsutil v0.0.0-20240223190444-7a889f53dbf6/go.mod h1:vbbYqJlnswsbJqWUcJN8fKtBhnEgldDrcagTgnBVKKM=
408+
github.com/tonistiigi/fsutil v0.0.0-20240301111122-7525a1af2bb5 h1:oZS8KCqAg62sxJkEq/Ppzqrb6EooqzWtL8Oaex7bc5c=
409+
github.com/tonistiigi/fsutil v0.0.0-20240301111122-7525a1af2bb5/go.mod h1:vbbYqJlnswsbJqWUcJN8fKtBhnEgldDrcagTgnBVKKM=
410410
github.com/tonistiigi/go-actions-cache v0.0.0-20240227172821-a0b64f338598 h1:DA/NDC0YbMdnfcOSUzAnbUZE6dSM54d+0hrBqG+bOfs=
411411
github.com/tonistiigi/go-actions-cache v0.0.0-20240227172821-a0b64f338598/go.mod h1:anhKd3mnC1shAbQj1Q4IJ+w6xqezxnyDYlx/yKa7IXM=
412412
github.com/tonistiigi/go-archvariant v1.0.0 h1:5LC1eDWiBNflnTF1prCiX09yfNHIxDC/aukdhCdTyb0=

hack/dockerfiles/archutil.Dockerfile

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,8 @@ RUN apt-get update && apt-get --no-install-recommends install -y git binutils \
1515
binutils-s390x-linux-gnu \
1616
binutils-powerpc64le-linux-gnu \
1717
binutils-mips64el-linux-gnuabi64 \
18-
binutils-mips64-linux-gnuabi64
18+
binutils-mips64-linux-gnuabi64 \
19+
binutils-loongarch64-linux-gnu
1920
WORKDIR /src
2021

2122
FROM base AS exit-amd64
@@ -58,6 +59,10 @@ FROM base AS exit-mips64
5859
COPY util/archutil/fixtures/exit.mips64.s .
5960
RUN mips64-linux-gnuabi64-as --noexecstack -o exit.o exit.mips64.s && mips64-linux-gnuabi64-ld -o exit -s exit.o && mips64-linux-gnuabi64-strip --strip-unneeded exit
6061

62+
FROM base AS exit-loong64
63+
COPY util/archutil/fixtures/exit.loongarch64.s .
64+
RUN loongarch64-linux-gnu-as --noexecstack -o exit.o exit.loongarch64.s && loongarch64-linux-gnu-ld -o exit -s exit.o && loongarch64-linux-gnu-strip --strip-unneeded exit
65+
6166
FROM scratch AS exits
6267
COPY --from=exit-amd64 /src/exit amd64
6368
COPY --from=exit-386 /src/exit 386
@@ -69,6 +74,7 @@ COPY --from=exit-ppc64 /src/exit ppc64
6974
COPY --from=exit-ppc64le /src/exit ppc64le
7075
COPY --from=exit-mips64le /src/exit mips64le
7176
COPY --from=exit-mips64 /src/exit mips64
77+
COPY --from=exit-loong64 /src/exit loong64
7278

7379
FROM golang:${GO_VERSION}-alpine${ALPINE_VERSION} AS generate
7480
WORKDIR /go/src/github.com/moby/buildkit
@@ -86,7 +92,8 @@ RUN --mount=type=bind,target=.,rw \
8692
bin/archutil/ppc64 \
8793
bin/archutil/ppc64le \
8894
bin/archutil/mips64le \
89-
bin/archutil/mips64
95+
bin/archutil/mips64 \
96+
bin/archutil/loong64
9097
tree -nh bin/archutil
9198
cp bin/archutil/*_binary.go /out
9299
EOT

util/archutil/detect.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,11 @@ func SupportedPlatforms(noCache bool) []ocispecs.Platform {
7878
arr = append(arr, linux(p))
7979
}
8080
}
81+
if p := "loong64"; def.Architecture != p {
82+
if _, err := loong64Supported(); err == nil {
83+
arr = append(arr, linux(p))
84+
}
85+
}
8186
if p := "arm"; def.Architecture != p {
8287
if _, err := armSupported(); err == nil {
8388
p := linux("arm")
@@ -144,6 +149,11 @@ func WarnIfUnsupported(pfs []ocispecs.Platform) {
144149
printPlatformWarning(p, err)
145150
}
146151
}
152+
if p.Architecture == "loong64" {
153+
if _, err := loong64Supported(); err != nil {
154+
printPlatformWarning(p, err)
155+
}
156+
}
147157
if p.Architecture == "arm" {
148158
if _, err := armSupported(); err != nil {
149159
printPlatformWarning(p, err)
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
.global _start
2+
.text
3+
_start:
4+
li.w $a0,0
5+
li.w $a7,93
6+
syscall 0

util/archutil/loong64_binary.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
//go:build !loong64
2+
// +build !loong64
3+
4+
package archutil
5+
6+
// This file is generated by running "make archutil".
7+
// Do not edit manually.
8+
9+
const Binaryloong64 = "\x1f\x8b\x08\x00\x00\x00\x00\x00\x02\xff\xaa\x77\xf5\x71\x63\x62\x64\x64\x80\x01\x26\x06\x08\x6f\x03\x03\x83\x02\x88\x76\x80\x8a\x5f\x80\xd2\xce\x60\x31\x0b\x06\x26\x06\x07\x06\x66\x06\x26\x06\x90\x1a\x56\x06\x14\xa0\xc0\x88\x44\xef\x81\x0a\xc2\x68\x98\x81\x81\x4f\x4b\x52\xd8\x18\x88\x07\x02\x50\x9a\x85\x41\x94\x81\xbb\xa4\x91\x99\x81\x41\x9b\x81\x41\xaf\x38\xa3\xb8\xa4\xa8\x24\x31\x89\x41\xaf\x24\xb5\xa2\x84\x81\x0a\x80\x9b\x81\x01\xec\x27\x98\xdb\x60\xe1\xb0\x01\xca\xe7\x41\x53\xcf\x88\x85\xcf\x8c\xc5\x5c\x98\xff\x05\x09\xe8\x07\x04\x00\x00\xff\xff\x5f\xc5\x9b\x9d\x90\x01\x00\x00"

util/archutil/loong64_check.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
//go:build !loong64
2+
// +build !loong64
3+
4+
package archutil
5+
6+
func loong64Supported() (string, error) {
7+
return check("loong64", Binaryloong64)
8+
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
//go:build loong64
2+
3+
package archutil
4+
5+
func loong64Supported() (string, error) {
6+
return "", nil
7+
}

util/system/path.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ func DefaultPathEnv(os string) string {
2727

2828
// NormalizePath cleans the path based on the operating system the path is meant for.
2929
// It takes into account a potential parent path, and will join the path to the parent
30-
// if the path is relative. Additionally, it will apply the folliwing rules:
30+
// if the path is relative. Additionally, it will apply the following rules:
3131
// - always return an absolute path
3232
// - always strip drive letters for Windows paths
3333
// - optionally keep the trailing slashes on paths

vendor/github.com/tonistiigi/fsutil/send.go

Lines changed: 10 additions & 7 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

vendor/modules.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -765,7 +765,7 @@ github.com/spdx/tools-golang/spdx/v2/v2_3
765765
## explicit; go 1.20
766766
github.com/stretchr/testify/assert
767767
github.com/stretchr/testify/require
768-
# github.com/tonistiigi/fsutil v0.0.0-20240223190444-7a889f53dbf6
768+
# github.com/tonistiigi/fsutil v0.0.0-20240301111122-7525a1af2bb5
769769
## explicit; go 1.20
770770
github.com/tonistiigi/fsutil
771771
github.com/tonistiigi/fsutil/copy

0 commit comments

Comments
 (0)