From 4d0557c70a3551f08fc12d8224c668314f10db53 Mon Sep 17 00:00:00 2001 From: David Karlsson <35727626+dvdksn@users.noreply.github.com> Date: Fri, 17 Nov 2023 11:02:20 +0100 Subject: [PATCH 01/13] docs: update du cmd description Signed-off-by: David Karlsson <35727626+dvdksn@users.noreply.github.com> (cherry picked from commit 940e0a4a3ce25ed5a4dd123c1549d4115a5ce4d4) --- docs/reference/buildx_du.md | 66 ++++++++++++++++++++++++++++++++++++- 1 file changed, 65 insertions(+), 1 deletion(-) diff --git a/docs/reference/buildx_du.md b/docs/reference/buildx_du.md index 043f58131b8e..c4687911ae5c 100644 --- a/docs/reference/buildx_du.md +++ b/docs/reference/buildx_du.md @@ -20,6 +20,70 @@ Disk usage ## Examples +### Show disk usage + +The `docker buildx du` command shows the disk usage for the currently selected +builder. + +```console +$ docker buildx du +ID RECLAIMABLE SIZE LAST ACCESSED +12wgll9os87pazzft8lt0yztp* true 1.704GB 13 days ago +iupsv3it5ubh92aweb7c1wojc* true 1.297GB 36 minutes ago +ek4ve8h4obyv5kld6vicmtqyn true 811.7MB 13 days ago +isovrfnmkelzhtdx942w9vjcb* true 811.7MB 13 days ago +0jty7mjrndi1yo7xkv1baralh true 810.5MB 13 days ago +jyzkefmsysqiaakgwmjgxjpcz* true 810.5MB 13 days ago +z8w1y95jn93gvj92jtaj6uhwk true 318MB 2 weeks ago +rz2zgfcwlfxsxd7d41w2sz2tt true 8.224kB* 43 hours ago +n5bkzpewmk2eiu6hn9tzx18jd true 8.224kB* 43 hours ago +ao94g6vtbzdl6k5zgdmrmnwpt true 8.224kB* 43 hours ago +2pyjep7njm0wh39vcingxb97i true 8.224kB* 43 hours ago +Shared: 115.5MB +Private: 10.25GB +Reclaimable: 10.36GB +Total: 10.36GB +``` + +If `RECLAIMABLE` is false, the `docker buildx du prune` command won't delete +the record, even if you use `--all`. That's because the record is actively in +use by some component of the builder. + +The asterisks (\*) in the output indicate the following: + +- An asterisk next to an ID (`zu7m6evdpebh5h8kfkpw9dlf2*`) indicates that the record + is mutable. The size of the record may change, or another build can take ownership of + it and change or commit to it. If you run the `du` command again, this item may + not be there anymore, or the size might be different. +- An asterisk next to a size (`8.288kB*`) indicates that the record is shared. + Storage of the record is shared with some other resource, typically an image. + If you prune such a record then you will lose build cache but only metadata + will be deleted as the image still needs to actual storage layers. + ### Override the configured builder instance (--builder) -Same as [`buildx --builder`](buildx.md#builder). +Use the `--builder` flag to inspect the disk usage of a particular builder. + +```console +$ docker buildx du --builder youthful_shtern +ID RECLAIMABLE SIZE LAST ACCESSED +g41agepgdczekxg2mtw0dujsv* true 1.312GB 47 hours ago +e6ycrsa0bn9akigqgzu0sc6kr true 318MB 47 hours ago +our9zg4ndly65ze1ccczdksiz true 204.9MB 45 hours ago +b7xv3xpxnwupc81tc9ya3mgq6* true 120.6MB 47 hours ago +zihgye15ss6vum3wmck9egdoy* true 79.81MB 2 days ago +aaydharssv1ug98yhuwclkfrh* true 79.81MB 2 days ago +ta1r4vmnjug5dhub76as4kkol* true 74.51MB 47 hours ago +murma9f83j9h8miifbq68udjf* true 74.51MB 47 hours ago +47f961866a49g5y8myz80ixw1* true 74.51MB 47 hours ago +tzh99xtzlaf6txllh3cobag8t true 74.49MB 47 hours ago +ld6laoeuo1kwapysu6afwqybl* true 59.89MB 47 hours ago +yitxizi5kaplpyomqpos2cryp* true 59.83MB 47 hours ago +iy8aa4b7qjn0qmy9wiga9cj8w true 33.65MB 47 hours ago +mci7okeijyp8aqqk16j80dy09 true 19.86MB 47 hours ago +lqvj091he652slxdla4wom3pz true 14.08MB 47 hours ago +fkt31oiv793nd26h42llsjcw7* true 11.87MB 2 days ago +uj802yxtvkcjysnjb4kgwvn2v true 11.68MB 45 hours ago +Reclaimable: 2.627GB +Total: 2.627GB +``` From 8ba17a6b26671f2c712bc3b11ff5cbfd38b87614 Mon Sep 17 00:00:00 2001 From: David Karlsson <35727626+dvdksn@users.noreply.github.com> Date: Tue, 21 Nov 2023 15:27:12 +0100 Subject: [PATCH 02/13] docs: add buildx du verbose example Signed-off-by: David Karlsson <35727626+dvdksn@users.noreply.github.com> (cherry picked from commit 5bf02d9f7b1a55a9e18a4b83d824962597a1cf1d) --- docs/reference/buildx_du.md | 33 +++++++++++++++++++++++++++++++-- 1 file changed, 31 insertions(+), 2 deletions(-) diff --git a/docs/reference/buildx_du.md b/docs/reference/buildx_du.md index c4687911ae5c..b1fdbcbf1c1d 100644 --- a/docs/reference/buildx_du.md +++ b/docs/reference/buildx_du.md @@ -13,7 +13,7 @@ Disk usage |:------------------------|:---------|:--------|:-----------------------------------------| | [`--builder`](#builder) | `string` | | Override the configured builder instance | | `--filter` | `filter` | | Provide filter values | -| `--verbose` | | | Provide a more verbose output | +| [`--verbose`](#verbose) | | | Provide a more verbose output | @@ -49,7 +49,7 @@ If `RECLAIMABLE` is false, the `docker buildx du prune` command won't delete the record, even if you use `--all`. That's because the record is actively in use by some component of the builder. -The asterisks (\*) in the output indicate the following: +The asterisks (\*) in the default output indicate the following: - An asterisk next to an ID (`zu7m6evdpebh5h8kfkpw9dlf2*`) indicates that the record is mutable. The size of the record may change, or another build can take ownership of @@ -60,6 +60,35 @@ The asterisks (\*) in the output indicate the following: If you prune such a record then you will lose build cache but only metadata will be deleted as the image still needs to actual storage layers. +### Use verbose output (--verbose) + +The verbose output of the `docker buildx du` command is useful for inspecting +the disk usage records in more detail. The verbose output shows the mutable and +shared states more clearly, as well as additional information about the +corresponding layer. + +```console +$ docker buildx du --verbose +... +Last used: 2 days ago +Type: regular + +ID: 05d0elirb4mmvpmnzbrp3ssrg +Parent: e8sfdn4mygrg7msi9ak1dy6op +Created at: 2023-11-20 09:53:30.881558721 +0000 UTC +Mutable: false +Reclaimable: true +Shared: false +Size: 0B +Description: [gobase 3/3] WORKDIR /src +Usage count: 3 +Last used: 24 hours ago +Type: regular + +Reclaimable: 4.453GB +Total: 4.453GB +``` + ### Override the configured builder instance (--builder) Use the `--builder` flag to inspect the disk usage of a particular builder. From c700a67d6ba145875b1262c5679e32eecb5bdcc9 Mon Sep 17 00:00:00 2001 From: David Karlsson <35727626+dvdksn@users.noreply.github.com> Date: Wed, 20 Dec 2023 08:58:52 +0100 Subject: [PATCH 03/13] docs: add --no-cache-filter example Signed-off-by: David Karlsson <35727626+dvdksn@users.noreply.github.com> (cherry picked from commit ebae070f7e76aa2846c7b3de75abeb20f2f5c001) --- docs/reference/buildx_build.md | 57 +++++++++++++++++++++++++++++++++- 1 file changed, 56 insertions(+), 1 deletion(-) diff --git a/docs/reference/buildx_build.md b/docs/reference/buildx_build.md index a7b17ad34640..abd1e11ca46a 100644 --- a/docs/reference/buildx_build.md +++ b/docs/reference/buildx_build.md @@ -33,7 +33,7 @@ Start a build | [`--metadata-file`](#metadata-file) | `string` | | Write build result metadata to the file | | `--network` | `string` | `default` | Set the networking mode for the `RUN` instructions during build | | `--no-cache` | | | Do not use cache when building the image | -| `--no-cache-filter` | `stringArray` | | Do not cache specified stages | +| [`--no-cache-filter`](#no-cache-filter) | `stringArray` | | Do not cache specified stages | | [`-o`](#output), [`--output`](#output) | `stringArray` | | Output destination (format: `type=local,dest=path`) | | [`--platform`](#platform) | `stringArray` | | Set target platform for build | | `--print` | `string` | | Print result of information request (e.g., outline, targets) | @@ -341,6 +341,61 @@ $ cat metadata.json } ``` +### Ignore build cache for specific stages (--no-cache-filter) + +The `--no-cache-filter` lets you specify one or more stages of a multi-stage +Dockerfile for which build cache should be ignored. To specify multiple stages, +use a comma-separated syntax: + +```console +$ docker buildx build --no-cache-filter stage1,stage2,stage3 . +``` + +For example, the following Dockerfile contains four stages: + +- `base` +- `install` +- `test` +- `release` + +```dockerfile +# syntax=docker/dockerfile:1 + +FROM oven/bun:1 as base +WORKDIR /app + +FROM base AS install +WORKDIR /temp/dev +RUN --mount=type=bind,source=package.json,target=package.json \ + --mount=type=bind,source=bun.lockb,target=bun.lockb \ + bun install --frozen-lockfile + +FROM base AS test +COPY --from=install /temp/dev/node_modules node_modules +COPY . . +RUN bun test + +FROM base AS release +ENV NODE_ENV=production +COPY --from=install /temp/dev/node_modules node_modules +COPY . . +ENTRYPOINT ["bun", "run", "index.js"] +``` + +To ignore the cache for the `install` stage: + +```console +$ docker buildx build --no-cache-filter install . +``` + +To ignore the cache the `install` and `release` stages: + +```console +$ docker buildx build --no-cache-filter install,release . +``` + +The arguments for the `--no-cache-filter` flag must be names of stages. + ### Set the export action for the build result (-o, --output) ```text From 4d48c28c304742620509bafe41be18f013180aac Mon Sep 17 00:00:00 2001 From: CrazyMax <1951866+crazy-max@users.noreply.github.com> Date: Fri, 15 Dec 2023 15:33:10 +0100 Subject: [PATCH 04/13] gitutil: sanitize root dir on WSL Signed-off-by: CrazyMax <1951866+crazy-max@users.noreply.github.com> (cherry picked from commit ac5b3241b16e3e75ef6f50e95a11abebf29fb7f3) --- util/gitutil/gitutil.go | 6 +++++- .../gitutil/{gitpath_unix.go => path_unix.go} | 17 +++++++++++++++++ util/gitutil/path_unix_test.go | 19 +++++++++++++++++++ .../{gitpath_windows.go => path_windows.go} | 5 +++++ util/gitutil/path_windows_test.go | 11 +++++++++++ 5 files changed, 57 insertions(+), 1 deletion(-) rename util/gitutil/{gitpath_unix.go => path_unix.go} (60%) create mode 100644 util/gitutil/path_unix_test.go rename util/gitutil/{gitpath_windows.go => path_windows.go} (52%) create mode 100644 util/gitutil/path_windows_test.go diff --git a/util/gitutil/gitutil.go b/util/gitutil/gitutil.go index 22aa72ee0094..b7383f00a74b 100644 --- a/util/gitutil/gitutil.go +++ b/util/gitutil/gitutil.go @@ -66,7 +66,11 @@ func (c *Git) IsDirty() bool { } func (c *Git) RootDir() (string, error) { - return c.clean(c.run("rev-parse", "--show-toplevel")) + root, err := c.clean(c.run("rev-parse", "--show-toplevel")) + if err != nil { + return "", err + } + return sanitizePath(root), nil } func (c *Git) GitDir() (string, error) { diff --git a/util/gitutil/gitpath_unix.go b/util/gitutil/path_unix.go similarity index 60% rename from util/gitutil/gitpath_unix.go rename to util/gitutil/path_unix.go index 898cb654dd0d..41b4bd61d425 100644 --- a/util/gitutil/gitpath_unix.go +++ b/util/gitutil/path_unix.go @@ -7,6 +7,8 @@ import ( "os" "os/exec" "path/filepath" + "regexp" + "strings" "github.com/moby/sys/mountinfo" ) @@ -40,3 +42,18 @@ func gitPath(wd string) (string, error) { } return exec.LookPath("git") } + +var windowsPathRegex = regexp.MustCompile(`^[A-Za-z]:[\\/].*$`) + +func sanitizePath(path string) string { + // If we're running in WSL, we need to convert Windows paths to Unix paths. + // This is because the git binary can be invoked through `git.exe` and + // therefore returns Windows paths. + if os.Getenv("WSL_DISTRO_NAME") != "" && windowsPathRegex.MatchString(path) { + unixPath := strings.ReplaceAll(path, "\\", "/") + drive := strings.ToLower(string(unixPath[0])) + rest := filepath.Clean(unixPath[3:]) + return filepath.Join("/mnt", drive, rest) + } + return filepath.Clean(path) +} diff --git a/util/gitutil/path_unix_test.go b/util/gitutil/path_unix_test.go new file mode 100644 index 000000000000..591d5fcd9d5b --- /dev/null +++ b/util/gitutil/path_unix_test.go @@ -0,0 +1,19 @@ +//go:build !windows +// +build !windows + +package gitutil + +import ( + "testing" + + "github.com/stretchr/testify/assert" +) + +func TestSanitizePathUnix(t *testing.T) { + assert.Equal(t, "/home/foobar", sanitizePath("/home/foobar")) +} + +func TestSanitizePathWSL(t *testing.T) { + t.Setenv("WSL_DISTRO_NAME", "Ubuntu") + assert.Equal(t, "/mnt/c/Users/foobar", sanitizePath("C:\\Users\\foobar")) +} diff --git a/util/gitutil/gitpath_windows.go b/util/gitutil/path_windows.go similarity index 52% rename from util/gitutil/gitpath_windows.go rename to util/gitutil/path_windows.go index a1a9153846ce..050895f4506b 100644 --- a/util/gitutil/gitpath_windows.go +++ b/util/gitutil/path_windows.go @@ -2,8 +2,13 @@ package gitutil import ( "os/exec" + "path/filepath" ) func gitPath(wd string) (string, error) { return exec.LookPath("git.exe") } + +func sanitizePath(path string) string { + return filepath.ToSlash(filepath.Clean(path)) +} diff --git a/util/gitutil/path_windows_test.go b/util/gitutil/path_windows_test.go new file mode 100644 index 000000000000..5326e305e0fa --- /dev/null +++ b/util/gitutil/path_windows_test.go @@ -0,0 +1,11 @@ +package gitutil + +import ( + "testing" + + "github.com/stretchr/testify/assert" +) + +func TestSanitizePathWindows(t *testing.T) { + assert.Equal(t, "C:\\Users\\foobar", sanitizePath("C:/Users/foobar")) +} From db5084eeade3b71d4b54d88adf32a6467f9e1cfa Mon Sep 17 00:00:00 2001 From: CrazyMax <1951866+crazy-max@users.noreply.github.com> Date: Thu, 25 Jan 2024 10:52:10 +0100 Subject: [PATCH 05/13] ci: test-unit job matrix for win/macos/ubuntu Signed-off-by: CrazyMax <1951866+crazy-max@users.noreply.github.com> (cherry picked from commit eabbee797b54cba1a23c07a70e64b012566d067c) --- .github/workflows/build.yml | 94 ++++++++++++++++++++++++++++++++----- 1 file changed, 82 insertions(+), 12 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 7c0f59227ff6..ae1218d1812f 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -24,9 +24,13 @@ env: REPO_SLUG: "docker/buildx-bin" DESTDIR: "./bin" TEST_CACHE_SCOPE: "test" + TESTFLAGS: "-v --parallel=6 --timeout=30m" + GOTESTSUM_FORMAT: "standard-verbose" + GO_VERSION: "1.21.6" + GOTESTSUM_VERSION: "v1.9.0" # same as one in Dockerfile jobs: - prepare-test: + prepare-test-integration: runs-on: ubuntu-22.04 steps: - @@ -51,14 +55,12 @@ jobs: *.cache-from=type=gha,scope=${{ env.TEST_CACHE_SCOPE }} *.cache-to=type=gha,scope=${{ env.TEST_CACHE_SCOPE }} - test: + test-integration: runs-on: ubuntu-22.04 needs: - - prepare-test + - prepare-test-integration env: - TESTFLAGS: "-v --parallel=6 --timeout=30m" TESTFLAGS_DOCKER: "-v --parallel=1 --timeout=30m" - GOTESTSUM_FORMAT: "standard-verbose" TEST_IMAGE_BUILD: "0" TEST_IMAGE_ID: "buildx-tests" strategy: @@ -71,9 +73,6 @@ jobs: - remote pkg: - ./tests - include: - - pkg: ./... - skip-integration-tests: 1 steps: - name: Checkout @@ -101,19 +100,19 @@ jobs: - name: Test run: | - export TEST_REPORT_SUFFIX=-${{ github.job }}-$(echo "${{ matrix.pkg }}-${{ matrix.skip-integration-tests }}-${{ matrix.worker }}" | tr -dc '[:alnum:]-\n\r' | tr '[:upper:]' '[:lower:]') + export TEST_REPORT_SUFFIX=-${{ github.job }}-$(echo "${{ matrix.pkg }}-${{ matrix.worker }}" | tr -dc '[:alnum:]-\n\r' | tr '[:upper:]' '[:lower:]') ./hack/test env: TEST_DOCKERD: "${{ startsWith(matrix.worker, 'docker') && '1' || '0' }}" TESTFLAGS: "${{ (matrix.worker == 'docker' || matrix.worker == 'docker\\+containerd') && env.TESTFLAGS_DOCKER || env.TESTFLAGS }} --run=//worker=${{ matrix.worker }}$" TESTPKGS: "${{ matrix.pkg }}" - SKIP_INTEGRATION_TESTS: "${{ matrix.skip-integration-tests }}" - name: Send to Codecov if: always() uses: codecov/codecov-action@v3 with: directory: ./bin/testreports + flags: integration - name: Generate annotations if: always() @@ -128,6 +127,75 @@ jobs: name: test-reports path: ./bin/testreports + test-unit: + runs-on: ${{ matrix.os }} + strategy: + fail-fast: false + matrix: + os: + - ubuntu-22.04 + - macos-12 + - windows-2022 + env: + SKIP_INTEGRATION_TESTS: 1 + steps: + - + name: Checkout + uses: actions/checkout@v4 + - + name: Set up Go + uses: actions/setup-go@v4 + with: + go-version: "${{ env.GO_VERSION }}" + - + name: Prepare + run: | + testreportsBaseDir=./bin/testreports + testreportsDir=$testreportsBaseDir/unit-${{ matrix.os }} + echo "TESTREPORTS_BASEDIR=$testreportsBaseDir" >> $GITHUB_ENV + echo "TESTREPORTS_DIR=$testreportsDir" >> $GITHUB_ENV + mkdir -p $testreportsDir + shell: bash + - + name: Install gotestsum + run: | + go install gotest.tools/gotestsum@${{ env.GOTESTSUM_VERSION }} + - + name: Test + env: + TMPDIR: ${{ runner.temp }} + run: | + gotestsum \ + --jsonfile="${{ env.TESTREPORTS_DIR }}/go-test-report.json" \ + --junitfile="${{ env.TESTREPORTS_DIR }}/junit-report.xml" \ + --packages="./..." \ + -- \ + "-mod=vendor" \ + "-coverprofile" "${{ env.TESTREPORTS_DIR }}/coverage.txt" \ + "-covermode" "atomic" ${{ env.TESTFLAGS }} + shell: bash + - + name: Send to Codecov + if: always() + uses: codecov/codecov-action@v3 + with: + directory: ${{ env.TESTREPORTS_DIR }} + env_vars: RUNNER_OS + flags: unit + - + name: Generate annotations + if: always() + uses: crazy-max/.github/.github/actions/gotest-annotations@1a64ea6d01db9a48aa61954cb20e265782c167d9 + with: + directory: ${{ env.TESTREPORTS_DIR }} + - + name: Upload test reports + if: always() + uses: actions/upload-artifact@v3 + with: + name: test-reports + path: ${{ env.TESTREPORTS_BASEDIR }} + prepare-binaries: runs-on: ubuntu-22.04 outputs: @@ -192,7 +260,8 @@ jobs: bin-image: runs-on: ubuntu-22.04 needs: - - test + - test-integration + - test-unit if: ${{ github.event_name != 'pull_request' && github.repository == 'docker/buildx' }} steps: - @@ -244,7 +313,8 @@ jobs: release: runs-on: ubuntu-22.04 needs: - - test + - test-integration + - test-unit - binaries steps: - From 4b3229ffa49f21d4c36baaec35a79b5b89726a12 Mon Sep 17 00:00:00 2001 From: CrazyMax Date: Thu, 25 Jan 2024 11:58:47 +0100 Subject: [PATCH 06/13] build: resolve 8.3 filename format to long one on Windows Signed-off-by: CrazyMax <1951866+crazy-max@users.noreply.github.com> (cherry picked from commit fb2c62a038d951e1e4737328872b298e6e14fb4c) --- build/git.go | 15 +++++++++++---- build/git_unix.go | 9 +++++++++ build/git_windows.go | 26 ++++++++++++++++++++++++++ go.mod | 2 +- util/gitutil/gitutil.go | 2 +- util/gitutil/{path_unix.go => path.go} | 2 +- util/gitutil/path_unix_test.go | 4 ++-- util/gitutil/path_windows.go | 2 +- util/gitutil/path_windows_test.go | 2 +- 9 files changed, 53 insertions(+), 11 deletions(-) create mode 100644 build/git_unix.go create mode 100644 build/git_windows.go rename util/gitutil/{path_unix.go => path.go} (97%) diff --git a/build/git.go b/build/git.go index 1e0a284de59b..8cba17dc63a3 100644 --- a/build/git.go +++ b/build/git.go @@ -45,9 +45,9 @@ func getGitAttributes(ctx context.Context, contextPath string, dockerfilePath st if filepath.IsAbs(contextPath) { wd = contextPath } else { - cwd, _ := os.Getwd() - wd, _ = filepath.Abs(filepath.Join(cwd, contextPath)) + wd, _ = filepath.Abs(filepath.Join(getWd(), contextPath)) } + wd = gitutil.SanitizePath(wd) gitc, err := gitutil.New(gitutil.WithContext(ctx), gitutil.WithWorkingDir(wd)) if err != nil { @@ -101,8 +101,7 @@ func getGitAttributes(ctx context.Context, contextPath string, dockerfilePath st dockerfilePath = filepath.Join(wd, "Dockerfile") } if !filepath.IsAbs(dockerfilePath) { - cwd, _ := os.Getwd() - dockerfilePath = filepath.Join(cwd, dockerfilePath) + dockerfilePath = filepath.Join(getWd(), dockerfilePath) } dockerfilePath, _ = filepath.Rel(root, dockerfilePath) if !strings.HasPrefix(dockerfilePath, "..") { @@ -113,3 +112,11 @@ func getGitAttributes(ctx context.Context, contextPath string, dockerfilePath st return } + +func getWd() string { + wd, _ := os.Getwd() + if lp, err := getLongPathName(wd); err == nil { + return lp + } + return wd +} diff --git a/build/git_unix.go b/build/git_unix.go new file mode 100644 index 000000000000..5bd8e4d9f282 --- /dev/null +++ b/build/git_unix.go @@ -0,0 +1,9 @@ +//go:build !windows +// +build !windows + +package build + +// getLongPathName is a no-op on non-Windows platforms. +func getLongPathName(path string) (string, error) { + return path, nil +} diff --git a/build/git_windows.go b/build/git_windows.go new file mode 100644 index 000000000000..b3ec71540aa4 --- /dev/null +++ b/build/git_windows.go @@ -0,0 +1,26 @@ +package build + +import "golang.org/x/sys/windows" + +// getLongPathName converts Windows short pathnames to full pathnames. +// For example C:\Users\ADMIN~1 --> C:\Users\Administrator. +func getLongPathName(path string) (string, error) { + // See https://groups.google.com/forum/#!topic/golang-dev/1tufzkruoTg + p, err := windows.UTF16FromString(path) + if err != nil { + return "", err + } + b := p // GetLongPathName says we can reuse buffer + n, err := windows.GetLongPathName(&p[0], &b[0], uint32(len(b))) + if err != nil { + return "", err + } + if n > uint32(len(b)) { + b = make([]uint16, n) + _, err = windows.GetLongPathName(&p[0], &b[0], uint32(len(b))) + if err != nil { + return "", err + } + } + return windows.UTF16ToString(b), nil +} diff --git a/go.mod b/go.mod index 9903a6f3109c..87d1a6fd846a 100644 --- a/go.mod +++ b/go.mod @@ -42,6 +42,7 @@ require ( go.opentelemetry.io/otel/trace v1.14.0 golang.org/x/mod v0.11.0 golang.org/x/sync v0.3.0 + golang.org/x/sys v0.13.0 golang.org/x/term v0.13.0 google.golang.org/grpc v1.53.0 gopkg.in/yaml.v3 v3.0.1 @@ -146,7 +147,6 @@ require ( golang.org/x/exp v0.0.0-20230713183714-613f0c0eb8a1 // indirect golang.org/x/net v0.17.0 // indirect golang.org/x/oauth2 v0.5.0 // indirect - golang.org/x/sys v0.13.0 // indirect golang.org/x/text v0.13.0 // indirect golang.org/x/time v0.3.0 // indirect golang.org/x/tools v0.7.0 // indirect diff --git a/util/gitutil/gitutil.go b/util/gitutil/gitutil.go index b7383f00a74b..90151e11d05e 100644 --- a/util/gitutil/gitutil.go +++ b/util/gitutil/gitutil.go @@ -70,7 +70,7 @@ func (c *Git) RootDir() (string, error) { if err != nil { return "", err } - return sanitizePath(root), nil + return SanitizePath(root), nil } func (c *Git) GitDir() (string, error) { diff --git a/util/gitutil/path_unix.go b/util/gitutil/path.go similarity index 97% rename from util/gitutil/path_unix.go rename to util/gitutil/path.go index 41b4bd61d425..9c6c693ef975 100644 --- a/util/gitutil/path_unix.go +++ b/util/gitutil/path.go @@ -45,7 +45,7 @@ func gitPath(wd string) (string, error) { var windowsPathRegex = regexp.MustCompile(`^[A-Za-z]:[\\/].*$`) -func sanitizePath(path string) string { +func SanitizePath(path string) string { // If we're running in WSL, we need to convert Windows paths to Unix paths. // This is because the git binary can be invoked through `git.exe` and // therefore returns Windows paths. diff --git a/util/gitutil/path_unix_test.go b/util/gitutil/path_unix_test.go index 591d5fcd9d5b..ef95e6c55c87 100644 --- a/util/gitutil/path_unix_test.go +++ b/util/gitutil/path_unix_test.go @@ -10,10 +10,10 @@ import ( ) func TestSanitizePathUnix(t *testing.T) { - assert.Equal(t, "/home/foobar", sanitizePath("/home/foobar")) + assert.Equal(t, "/home/foobar", SanitizePath("/home/foobar")) } func TestSanitizePathWSL(t *testing.T) { t.Setenv("WSL_DISTRO_NAME", "Ubuntu") - assert.Equal(t, "/mnt/c/Users/foobar", sanitizePath("C:\\Users\\foobar")) + assert.Equal(t, "/mnt/c/Users/foobar", SanitizePath("C:\\Users\\foobar")) } diff --git a/util/gitutil/path_windows.go b/util/gitutil/path_windows.go index 050895f4506b..6ec5ea128427 100644 --- a/util/gitutil/path_windows.go +++ b/util/gitutil/path_windows.go @@ -9,6 +9,6 @@ func gitPath(wd string) (string, error) { return exec.LookPath("git.exe") } -func sanitizePath(path string) string { +func SanitizePath(path string) string { return filepath.ToSlash(filepath.Clean(path)) } diff --git a/util/gitutil/path_windows_test.go b/util/gitutil/path_windows_test.go index 5326e305e0fa..ee2e452de286 100644 --- a/util/gitutil/path_windows_test.go +++ b/util/gitutil/path_windows_test.go @@ -7,5 +7,5 @@ import ( ) func TestSanitizePathWindows(t *testing.T) { - assert.Equal(t, "C:\\Users\\foobar", sanitizePath("C:/Users/foobar")) + assert.Equal(t, "C:\\Users\\foobar", SanitizePath("C:/Users/foobar")) } From 222c6c7051aeaf6b3991a3b4b129b1d68e8528ab Mon Sep 17 00:00:00 2001 From: CrazyMax <1951866+crazy-max@users.noreply.github.com> Date: Thu, 25 Jan 2024 14:46:14 +0100 Subject: [PATCH 07/13] gitutil: check git bash env when testing Signed-off-by: CrazyMax <1951866+crazy-max@users.noreply.github.com> (cherry picked from commit 703c765ec81155aafbd1c333869c0fd6d32a17b6) --- util/gitutil/path_windows_test.go | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/util/gitutil/path_windows_test.go b/util/gitutil/path_windows_test.go index ee2e452de286..0ea32db3b482 100644 --- a/util/gitutil/path_windows_test.go +++ b/util/gitutil/path_windows_test.go @@ -1,11 +1,28 @@ package gitutil import ( + "os" "testing" "github.com/stretchr/testify/assert" ) func TestSanitizePathWindows(t *testing.T) { - assert.Equal(t, "C:\\Users\\foobar", SanitizePath("C:/Users/foobar")) + expected := "C:\\Users\\foobar" + if isGitBash() { + expected = "C:/Users/foobar" + } + assert.Equal(t, expected, SanitizePath("C:/Users/foobar")) +} + +func isGitBash() bool { + // The MSYSTEM environment variable is used in MSYS2 environments, + // including Git Bash, to select the active environment. This variable + // dictates the environment in which the shell operates, influencing + // factors like the path prefixes, default compilers, and system libraries + // used: https://www.msys2.org/docs/environments/ + if _, ok := os.LookupEnv("MSYSTEM"); ok { + return true + } + return false } From a94512c109decaac6deac1cb763b6e0394ae8576 Mon Sep 17 00:00:00 2001 From: Justin Chadwell Date: Wed, 31 Jan 2024 14:44:10 +0000 Subject: [PATCH 08/13] fix: avoid modifying source during resolver.Copy Signed-off-by: Justin Chadwell (cherry picked from commit 95bdecc145b272e09c3fa9d12a097b6f055b38a5) --- util/imagetools/create.go | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/util/imagetools/create.go b/util/imagetools/create.go index 1b55f0833573..d1e8dfaadc8d 100644 --- a/util/imagetools/create.go +++ b/util/imagetools/create.go @@ -4,6 +4,7 @@ import ( "bytes" "context" "encoding/json" + "maps" "net/url" "strings" @@ -230,13 +231,17 @@ func (r *Resolver) Copy(ctx context.Context, src *Source, dest reference.Named) if err != nil { return err } - source, repo := u.Hostname(), strings.TrimPrefix(u.Path, "/") - if src.Desc.Annotations == nil { - src.Desc.Annotations = make(map[string]string) + + desc := src.Desc + desc.Annotations = maps.Clone(desc.Annotations) + if desc.Annotations == nil { + desc.Annotations = make(map[string]string) } - src.Desc.Annotations["containerd.io/distribution.source."+source] = repo - err = contentutil.CopyChain(ctx, contentutil.FromPusher(p), contentutil.FromFetcher(f), src.Desc) + source, repo := u.Hostname(), strings.TrimPrefix(u.Path, "/") + desc.Annotations["containerd.io/distribution.source."+source] = repo + + err = contentutil.CopyChain(ctx, contentutil.FromPusher(p), contentutil.FromFetcher(f), desc) if err != nil { return err } From dbff202748f24460a9b111dddbf89df2c6bc049b Mon Sep 17 00:00:00 2001 From: CrazyMax <1951866+crazy-max@users.noreply.github.com> Date: Thu, 1 Feb 2024 18:50:12 +0100 Subject: [PATCH 09/13] bake: fix definitions merge order Signed-off-by: CrazyMax <1951866+crazy-max@users.noreply.github.com> (cherry picked from commit 052f279de781735e9b9f6991f7b9f808b287eaa7) --- commands/bake.go | 12 ++++++++---- tests/bake.go | 36 ++++++++++++++++++++++++++++++++++++ 2 files changed, 44 insertions(+), 4 deletions(-) diff --git a/commands/bake.go b/commands/bake.go index 77ad7529d086..f5eff0f61491 100644 --- a/commands/bake.go +++ b/commands/bake.go @@ -295,13 +295,17 @@ func saveLocalStateGroup(dockerCli command.Cli, ref string, lsg localstate.State } func readBakeFiles(ctx context.Context, nodes []builder.Node, url string, names []string, stdin io.Reader, pw progress.Writer) (files []bake.File, inp *bake.Input, err error) { - var lnames []string - var rnames []string + var lnames []string // local + var rnames []string // remote + var anames []string // both for _, v := range names { if strings.HasPrefix(v, "cwd://") { - lnames = append(lnames, strings.TrimPrefix(v, "cwd://")) + tname := strings.TrimPrefix(v, "cwd://") + lnames = append(lnames, tname) + anames = append(anames, tname) } else { rnames = append(rnames, v) + anames = append(anames, v) } } @@ -320,7 +324,7 @@ func readBakeFiles(ctx context.Context, nodes []builder.Node, url string, names if url != "" { lfiles, err = bake.ReadLocalFiles(lnames, stdin, sub) } else { - lfiles, err = bake.ReadLocalFiles(append(lnames, rnames...), stdin, sub) + lfiles, err = bake.ReadLocalFiles(anames, stdin, sub) } return nil }) diff --git a/tests/bake.go b/tests/bake.go index be4b27a66012..a2af62cf0f7d 100644 --- a/tests/bake.go +++ b/tests/bake.go @@ -24,6 +24,7 @@ var bakeTests = []func(t *testing.T, sb integration.Sandbox){ testBakeRemote, testBakeRemoteCmdContext, testBakeRemoteLocalOverride, + testBakeLocalCwdOverride, testBakeRemoteCmdContextOverride, testBakeRemoteContextSubdir, testBakeRemoteCmdContextEscapeRoot, @@ -173,6 +174,41 @@ EOT require.FileExists(t, filepath.Join(dirDest, "bar")) } +func testBakeLocalCwdOverride(t *testing.T, sb integration.Sandbox) { + bakeFile := []byte(` +target "default" { + dockerfile-inline = < Date: Mon, 5 Feb 2024 11:27:00 +0100 Subject: [PATCH 10/13] vendor: github.com/containerd/console 8f6c4e4 full diff: https://github.com/containerd/console/compare/v1.0.3...8f6c4e4faef5a326d2cd907097d04c0239ee5e2f Signed-off-by: CrazyMax <1951866+crazy-max@users.noreply.github.com> (cherry picked from commit 6ffb77dcdaa0f0635ba83ec0a4bacde2ec6dddd8) --- go.mod | 2 +- go.sum | 4 +- .../containerd/console/.golangci.yml | 14 +- .../github.com/containerd/console/README.md | 6 +- .../github.com/containerd/console/console.go | 9 +- .../containerd/console/console_linux.go | 1 + .../containerd/console/console_other.go | 36 ++++ .../containerd/console/console_unix.go | 3 +- .../containerd/console/console_windows.go | 25 +-- .../containerd/console/console_zos.go | 163 ------------------ .../containerd/console/pty_freebsd_cgo.go | 1 + .../containerd/console/pty_freebsd_nocgo.go | 1 + .../github.com/containerd/console/pty_unix.go | 3 +- .../github.com/containerd/console/pty_zos.go | 43 +++++ .../containerd/console/tc_freebsd_cgo.go | 1 + .../containerd/console/tc_freebsd_nocgo.go | 1 + .../containerd/console/tc_openbsd_cgo.go | 1 + .../containerd/console/tc_openbsd_nocgo.go | 1 + .../containerd/console/tc_solaris_cgo.go | 51 ------ .../containerd/console/tc_solaris_nocgo.go | 47 ----- .../github.com/containerd/console/tc_unix.go | 5 +- .../github.com/containerd/console/tc_zos.go | 13 ++ vendor/modules.txt | 2 +- 23 files changed, 140 insertions(+), 293 deletions(-) create mode 100644 vendor/github.com/containerd/console/console_other.go delete mode 100644 vendor/github.com/containerd/console/console_zos.go create mode 100644 vendor/github.com/containerd/console/pty_zos.go delete mode 100644 vendor/github.com/containerd/console/tc_solaris_cgo.go delete mode 100644 vendor/github.com/containerd/console/tc_solaris_nocgo.go diff --git a/go.mod b/go.mod index 87d1a6fd846a..369dca5e3d35 100644 --- a/go.mod +++ b/go.mod @@ -6,7 +6,7 @@ require ( github.com/Masterminds/semver/v3 v3.2.1 github.com/aws/aws-sdk-go-v2/config v1.18.16 github.com/compose-spec/compose-go v1.20.0 - github.com/containerd/console v1.0.3 + github.com/containerd/console v1.0.4-0.20230706203907-8f6c4e4faef5 // include https://github.com/containerd/console/pull/66, which is not yet in a release. github.com/containerd/containerd v1.7.7 github.com/containerd/continuity v0.4.2 github.com/containerd/log v0.1.0 diff --git a/go.sum b/go.sum index 372cc4abb99e..dddb214c0b35 100644 --- a/go.sum +++ b/go.sum @@ -127,8 +127,8 @@ github.com/codahale/rfc6979 v0.0.0-20141003034818-6a90f24967eb h1:EDmT6Q9Zs+SbUo github.com/compose-spec/compose-go v1.20.0 h1:h4ZKOst1EF/DwZp7dWkb+wbTVE4nEyT9Lc89to84Ol4= github.com/compose-spec/compose-go v1.20.0/go.mod h1:+MdqXV4RA7wdFsahh/Kb8U0pAJqkg7mr4PM9tFKU8RM= github.com/containerd/cgroups v1.1.0 h1:v8rEWFl6EoqHB+swVNjVoCJE8o3jX7e8nqBGPLaDFBM= -github.com/containerd/console v1.0.3 h1:lIr7SlA5PxZyMV30bDW0MGbiOPXwc63yRuCP0ARubLw= -github.com/containerd/console v1.0.3/go.mod h1:7LqA/THxQ86k76b8c/EMSiaJ3h1eZkMkXar0TQ1gf3U= +github.com/containerd/console v1.0.4-0.20230706203907-8f6c4e4faef5 h1:Ig+OPkE3XQrrl+SKsOqAjlkrBN/zrr+Qpw7rCuDjRCE= +github.com/containerd/console v1.0.4-0.20230706203907-8f6c4e4faef5/go.mod h1:YynlIjWYF8myEu6sdkwKIvGQq+cOckRm6So2avqoYAk= github.com/containerd/containerd v1.7.7 h1:QOC2K4A42RQpcrZyptP6z9EJZnlHfHJUfZrAAHe15q4= github.com/containerd/containerd v1.7.7/go.mod h1:3c4XZv6VeT9qgf9GMTxNTMFxGJrGpI2vz1yk4ye+YY8= github.com/containerd/continuity v0.4.2 h1:v3y/4Yz5jwnvqPKJJ+7Wf93fyWoCB3F5EclWG023MDM= diff --git a/vendor/github.com/containerd/console/.golangci.yml b/vendor/github.com/containerd/console/.golangci.yml index fcba5e885f0a..abe3d84bb164 100644 --- a/vendor/github.com/containerd/console/.golangci.yml +++ b/vendor/github.com/containerd/console/.golangci.yml @@ -1,16 +1,16 @@ linters: enable: - - structcheck - - varcheck - - staticcheck - - unconvert - gofmt - goimports - - golint - ineffassign - - vet - - unused - misspell + - revive + - staticcheck + - structcheck + - unconvert + - unused + - varcheck + - vet disable: - errcheck diff --git a/vendor/github.com/containerd/console/README.md b/vendor/github.com/containerd/console/README.md index 580b461a73db..a849a728f1e5 100644 --- a/vendor/github.com/containerd/console/README.md +++ b/vendor/github.com/containerd/console/README.md @@ -22,8 +22,8 @@ current.Resize(ws) console is a containerd sub-project, licensed under the [Apache 2.0 license](./LICENSE). As a containerd sub-project, you will find the: - * [Project governance](https://github.com/containerd/project/blob/master/GOVERNANCE.md), - * [Maintainers](https://github.com/containerd/project/blob/master/MAINTAINERS), - * and [Contributing guidelines](https://github.com/containerd/project/blob/master/CONTRIBUTING.md) + * [Project governance](https://github.com/containerd/project/blob/main/GOVERNANCE.md), + * [Maintainers](https://github.com/containerd/project/blob/main/MAINTAINERS), + * and [Contributing guidelines](https://github.com/containerd/project/blob/main/CONTRIBUTING.md) information in our [`containerd/project`](https://github.com/containerd/project) repository. diff --git a/vendor/github.com/containerd/console/console.go b/vendor/github.com/containerd/console/console.go index f989d28a41cd..dd587d88e072 100644 --- a/vendor/github.com/containerd/console/console.go +++ b/vendor/github.com/containerd/console/console.go @@ -22,7 +22,10 @@ import ( "os" ) -var ErrNotAConsole = errors.New("provided file is not a console") +var ( + ErrNotAConsole = errors.New("provided file is not a console") + ErrNotImplemented = errors.New("not implemented") +) type File interface { io.ReadWriteCloser @@ -45,7 +48,7 @@ type Console interface { SetRaw() error // DisableEcho disables echo on the console DisableEcho() error - // Reset restores the console to its orignal state + // Reset restores the console to its original state Reset() error // Size returns the window size of the console Size() (WinSize, error) @@ -78,7 +81,7 @@ func Current() (c Console) { } // ConsoleFromFile returns a console using the provided file -// nolint:golint +// nolint:revive func ConsoleFromFile(f File) (Console, error) { if err := checkConsole(f); err != nil { return nil, err diff --git a/vendor/github.com/containerd/console/console_linux.go b/vendor/github.com/containerd/console/console_linux.go index c1c839ee3ae0..28b77b7a3891 100644 --- a/vendor/github.com/containerd/console/console_linux.go +++ b/vendor/github.com/containerd/console/console_linux.go @@ -1,3 +1,4 @@ +//go:build linux // +build linux /* diff --git a/vendor/github.com/containerd/console/console_other.go b/vendor/github.com/containerd/console/console_other.go new file mode 100644 index 000000000000..933dfadddae6 --- /dev/null +++ b/vendor/github.com/containerd/console/console_other.go @@ -0,0 +1,36 @@ +//go:build !darwin && !freebsd && !linux && !netbsd && !openbsd && !solaris && !windows && !zos +// +build !darwin,!freebsd,!linux,!netbsd,!openbsd,!solaris,!windows,!zos + +/* + Copyright The containerd Authors. + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. +*/ + +package console + +// NewPty creates a new pty pair +// The master is returned as the first console and a string +// with the path to the pty slave is returned as the second +func NewPty() (Console, string, error) { + return nil, "", ErrNotImplemented +} + +// checkConsole checks if the provided file is a console +func checkConsole(f File) error { + return ErrNotAConsole +} + +func newMaster(f File) (Console, error) { + return nil, ErrNotImplemented +} diff --git a/vendor/github.com/containerd/console/console_unix.go b/vendor/github.com/containerd/console/console_unix.go index a08117695e32..161f5d126cba 100644 --- a/vendor/github.com/containerd/console/console_unix.go +++ b/vendor/github.com/containerd/console/console_unix.go @@ -1,4 +1,5 @@ -// +build darwin freebsd linux netbsd openbsd solaris +//go:build darwin || freebsd || linux || netbsd || openbsd || zos +// +build darwin freebsd linux netbsd openbsd zos /* Copyright The containerd Authors. diff --git a/vendor/github.com/containerd/console/console_windows.go b/vendor/github.com/containerd/console/console_windows.go index 787c11fe56fd..6896db1825fe 100644 --- a/vendor/github.com/containerd/console/console_windows.go +++ b/vendor/github.com/containerd/console/console_windows.go @@ -24,12 +24,13 @@ import ( "golang.org/x/sys/windows" ) -var ( - vtInputSupported bool - ErrNotImplemented = errors.New("not implemented") -) +var vtInputSupported bool func (m *master) initStdios() { + // Note: We discard console mode warnings, because in/out can be redirected. + // + // TODO: Investigate opening CONOUT$/CONIN$ to handle this correctly + m.in = windows.Handle(os.Stdin.Fd()) if err := windows.GetConsoleMode(m.in, &m.inMode); err == nil { // Validate that windows.ENABLE_VIRTUAL_TERMINAL_INPUT is supported, but do not set it. @@ -39,8 +40,6 @@ func (m *master) initStdios() { // Unconditionally set the console mode back even on failure because SetConsoleMode // remembers invalid bits on input handles. windows.SetConsoleMode(m.in, m.inMode) - } else { - fmt.Printf("failed to get console mode for stdin: %v\n", err) } m.out = windows.Handle(os.Stdout.Fd()) @@ -50,8 +49,6 @@ func (m *master) initStdios() { } else { windows.SetConsoleMode(m.out, m.outMode) } - } else { - fmt.Printf("failed to get console mode for stdout: %v\n", err) } m.err = windows.Handle(os.Stderr.Fd()) @@ -61,8 +58,6 @@ func (m *master) initStdios() { } else { windows.SetConsoleMode(m.err, m.errMode) } - } else { - fmt.Printf("failed to get console mode for stderr: %v\n", err) } } @@ -94,6 +89,8 @@ func (m *master) SetRaw() error { } func (m *master) Reset() error { + var errs []error + for _, s := range []struct { fd windows.Handle mode uint32 @@ -103,10 +100,16 @@ func (m *master) Reset() error { {m.err, m.errMode}, } { if err := windows.SetConsoleMode(s.fd, s.mode); err != nil { - return fmt.Errorf("unable to restore console mode: %w", err) + // we can't just abort on the first error, otherwise we might leave + // the console in an unexpected state. + errs = append(errs, fmt.Errorf("unable to restore console mode: %w", err)) } } + if len(errs) > 0 { + return errs[0] + } + return nil } diff --git a/vendor/github.com/containerd/console/console_zos.go b/vendor/github.com/containerd/console/console_zos.go deleted file mode 100644 index b348a839a03b..000000000000 --- a/vendor/github.com/containerd/console/console_zos.go +++ /dev/null @@ -1,163 +0,0 @@ -// +build zos - -/* - Copyright The containerd Authors. - - Licensed under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. - You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software - distributed under the License is distributed on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - See the License for the specific language governing permissions and - limitations under the License. -*/ - -package console - -import ( - "fmt" - "os" - - "golang.org/x/sys/unix" -) - -// NewPty creates a new pty pair -// The master is returned as the first console and a string -// with the path to the pty slave is returned as the second -func NewPty() (Console, string, error) { - var f File - var err error - var slave string - for i := 0;; i++ { - ptyp := fmt.Sprintf("/dev/ptyp%04d", i) - f, err = os.OpenFile(ptyp, os.O_RDWR, 0600) - if err == nil { - slave = fmt.Sprintf("/dev/ttyp%04d", i) - break - } - if os.IsNotExist(err) { - return nil, "", err - } - // else probably Resource Busy - } - m, err := newMaster(f) - if err != nil { - return nil, "", err - } - return m, slave, nil -} - -type master struct { - f File - original *unix.Termios -} - -func (m *master) Read(b []byte) (int, error) { - return m.f.Read(b) -} - -func (m *master) Write(b []byte) (int, error) { - return m.f.Write(b) -} - -func (m *master) Close() error { - return m.f.Close() -} - -func (m *master) Resize(ws WinSize) error { - return tcswinsz(m.f.Fd(), ws) -} - -func (m *master) ResizeFrom(c Console) error { - ws, err := c.Size() - if err != nil { - return err - } - return m.Resize(ws) -} - -func (m *master) Reset() error { - if m.original == nil { - return nil - } - return tcset(m.f.Fd(), m.original) -} - -func (m *master) getCurrent() (unix.Termios, error) { - var termios unix.Termios - if err := tcget(m.f.Fd(), &termios); err != nil { - return unix.Termios{}, err - } - return termios, nil -} - -func (m *master) SetRaw() error { - rawState, err := m.getCurrent() - if err != nil { - return err - } - rawState = cfmakeraw(rawState) - rawState.Oflag = rawState.Oflag | unix.OPOST - return tcset(m.f.Fd(), &rawState) -} - -func (m *master) DisableEcho() error { - rawState, err := m.getCurrent() - if err != nil { - return err - } - rawState.Lflag = rawState.Lflag &^ unix.ECHO - return tcset(m.f.Fd(), &rawState) -} - -func (m *master) Size() (WinSize, error) { - return tcgwinsz(m.f.Fd()) -} - -func (m *master) Fd() uintptr { - return m.f.Fd() -} - -func (m *master) Name() string { - return m.f.Name() -} - -// checkConsole checks if the provided file is a console -func checkConsole(f File) error { - var termios unix.Termios - if tcget(f.Fd(), &termios) != nil { - return ErrNotAConsole - } - return nil -} - -func newMaster(f File) (Console, error) { - m := &master{ - f: f, - } - t, err := m.getCurrent() - if err != nil { - return nil, err - } - m.original = &t - return m, nil -} - -// ClearONLCR sets the necessary tty_ioctl(4)s to ensure that a pty pair -// created by us acts normally. In particular, a not-very-well-known default of -// Linux unix98 ptys is that they have +onlcr by default. While this isn't a -// problem for terminal emulators, because we relay data from the terminal we -// also relay that funky line discipline. -func ClearONLCR(fd uintptr) error { - return setONLCR(fd, false) -} - -// SetONLCR sets the necessary tty_ioctl(4)s to ensure that a pty pair -// created by us acts as intended for a terminal emulator. -func SetONLCR(fd uintptr) error { - return setONLCR(fd, true) -} diff --git a/vendor/github.com/containerd/console/pty_freebsd_cgo.go b/vendor/github.com/containerd/console/pty_freebsd_cgo.go index cbd3cd7ea43d..22368623aab2 100644 --- a/vendor/github.com/containerd/console/pty_freebsd_cgo.go +++ b/vendor/github.com/containerd/console/pty_freebsd_cgo.go @@ -1,3 +1,4 @@ +//go:build freebsd && cgo // +build freebsd,cgo /* diff --git a/vendor/github.com/containerd/console/pty_freebsd_nocgo.go b/vendor/github.com/containerd/console/pty_freebsd_nocgo.go index b5e43181d4f3..ceb90a47b818 100644 --- a/vendor/github.com/containerd/console/pty_freebsd_nocgo.go +++ b/vendor/github.com/containerd/console/pty_freebsd_nocgo.go @@ -1,3 +1,4 @@ +//go:build freebsd && !cgo // +build freebsd,!cgo /* diff --git a/vendor/github.com/containerd/console/pty_unix.go b/vendor/github.com/containerd/console/pty_unix.go index d5a6bd8ca2e8..f5a5b8058c65 100644 --- a/vendor/github.com/containerd/console/pty_unix.go +++ b/vendor/github.com/containerd/console/pty_unix.go @@ -1,4 +1,5 @@ -// +build darwin linux netbsd openbsd solaris +//go:build darwin || linux || netbsd || openbsd +// +build darwin linux netbsd openbsd /* Copyright The containerd Authors. diff --git a/vendor/github.com/containerd/console/pty_zos.go b/vendor/github.com/containerd/console/pty_zos.go new file mode 100644 index 000000000000..58f59aba58c9 --- /dev/null +++ b/vendor/github.com/containerd/console/pty_zos.go @@ -0,0 +1,43 @@ +//go:build zos +// +build zos + +/* + Copyright The containerd Authors. + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. +*/ + +package console + +import ( + "fmt" + "os" +) + +// openpt allocates a new pseudo-terminal by opening the first available /dev/ptypXX device +func openpt() (*os.File, error) { + var f *os.File + var err error + for i := 0; ; i++ { + ptyp := fmt.Sprintf("/dev/ptyp%04d", i) + f, err = os.OpenFile(ptyp, os.O_RDWR, 0600) + if err == nil { + break + } + if os.IsNotExist(err) { + return nil, err + } + // else probably Resource Busy + } + return f, nil +} diff --git a/vendor/github.com/containerd/console/tc_freebsd_cgo.go b/vendor/github.com/containerd/console/tc_freebsd_cgo.go index 0f3d27273094..33282579411e 100644 --- a/vendor/github.com/containerd/console/tc_freebsd_cgo.go +++ b/vendor/github.com/containerd/console/tc_freebsd_cgo.go @@ -1,3 +1,4 @@ +//go:build freebsd && cgo // +build freebsd,cgo /* diff --git a/vendor/github.com/containerd/console/tc_freebsd_nocgo.go b/vendor/github.com/containerd/console/tc_freebsd_nocgo.go index 087fc158a169..18a9b9cbea97 100644 --- a/vendor/github.com/containerd/console/tc_freebsd_nocgo.go +++ b/vendor/github.com/containerd/console/tc_freebsd_nocgo.go @@ -1,3 +1,4 @@ +//go:build freebsd && !cgo // +build freebsd,!cgo /* diff --git a/vendor/github.com/containerd/console/tc_openbsd_cgo.go b/vendor/github.com/containerd/console/tc_openbsd_cgo.go index f0cec06a72dc..0e76f6cc3e0a 100644 --- a/vendor/github.com/containerd/console/tc_openbsd_cgo.go +++ b/vendor/github.com/containerd/console/tc_openbsd_cgo.go @@ -1,3 +1,4 @@ +//go:build openbsd && cgo // +build openbsd,cgo /* diff --git a/vendor/github.com/containerd/console/tc_openbsd_nocgo.go b/vendor/github.com/containerd/console/tc_openbsd_nocgo.go index daccce20585a..dca92418b0e5 100644 --- a/vendor/github.com/containerd/console/tc_openbsd_nocgo.go +++ b/vendor/github.com/containerd/console/tc_openbsd_nocgo.go @@ -1,3 +1,4 @@ +//go:build openbsd && !cgo // +build openbsd,!cgo /* diff --git a/vendor/github.com/containerd/console/tc_solaris_cgo.go b/vendor/github.com/containerd/console/tc_solaris_cgo.go deleted file mode 100644 index e36a68edd1ed..000000000000 --- a/vendor/github.com/containerd/console/tc_solaris_cgo.go +++ /dev/null @@ -1,51 +0,0 @@ -// +build solaris,cgo - -/* - Copyright The containerd Authors. - - Licensed under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. - You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software - distributed under the License is distributed on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - See the License for the specific language governing permissions and - limitations under the License. -*/ - -package console - -import ( - "os" - - "golang.org/x/sys/unix" -) - -//#include -import "C" - -const ( - cmdTcGet = unix.TCGETS - cmdTcSet = unix.TCSETS -) - -// ptsname retrieves the name of the first available pts for the given master. -func ptsname(f *os.File) (string, error) { - ptspath, err := C.ptsname(C.int(f.Fd())) - if err != nil { - return "", err - } - return C.GoString(ptspath), nil -} - -// unlockpt unlocks the slave pseudoterminal device corresponding to the master pseudoterminal referred to by f. -// unlockpt should be called before opening the slave side of a pty. -func unlockpt(f *os.File) error { - if _, err := C.grantpt(C.int(f.Fd())); err != nil { - return err - } - return nil -} diff --git a/vendor/github.com/containerd/console/tc_solaris_nocgo.go b/vendor/github.com/containerd/console/tc_solaris_nocgo.go deleted file mode 100644 index eb0bd2c36b83..000000000000 --- a/vendor/github.com/containerd/console/tc_solaris_nocgo.go +++ /dev/null @@ -1,47 +0,0 @@ -// +build solaris,!cgo - -/* - Copyright The containerd Authors. - - Licensed under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. - You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software - distributed under the License is distributed on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - See the License for the specific language governing permissions and - limitations under the License. -*/ - -// -// Implementing the functions below requires cgo support. Non-cgo stubs -// versions are defined below to enable cross-compilation of source code -// that depends on these functions, but the resultant cross-compiled -// binaries cannot actually be used. If the stub function(s) below are -// actually invoked they will display an error message and cause the -// calling process to exit. -// - -package console - -import ( - "os" - - "golang.org/x/sys/unix" -) - -const ( - cmdTcGet = unix.TCGETS - cmdTcSet = unix.TCSETS -) - -func ptsname(f *os.File) (string, error) { - panic("ptsname() support requires cgo.") -} - -func unlockpt(f *os.File) error { - panic("unlockpt() support requires cgo.") -} diff --git a/vendor/github.com/containerd/console/tc_unix.go b/vendor/github.com/containerd/console/tc_unix.go index a6bf01e8d1a2..2ecf188fca33 100644 --- a/vendor/github.com/containerd/console/tc_unix.go +++ b/vendor/github.com/containerd/console/tc_unix.go @@ -1,4 +1,5 @@ -// +build darwin freebsd linux netbsd openbsd solaris zos +//go:build darwin || freebsd || linux || netbsd || openbsd || zos +// +build darwin freebsd linux netbsd openbsd zos /* Copyright The containerd Authors. @@ -83,7 +84,7 @@ func cfmakeraw(t unix.Termios) unix.Termios { t.Oflag &^= unix.OPOST t.Lflag &^= (unix.ECHO | unix.ECHONL | unix.ICANON | unix.ISIG | unix.IEXTEN) t.Cflag &^= (unix.CSIZE | unix.PARENB) - t.Cflag &^= unix.CS8 + t.Cflag |= unix.CS8 t.Cc[unix.VMIN] = 1 t.Cc[unix.VTIME] = 0 diff --git a/vendor/github.com/containerd/console/tc_zos.go b/vendor/github.com/containerd/console/tc_zos.go index 4262eaf4cc07..fc90ba5fb86e 100644 --- a/vendor/github.com/containerd/console/tc_zos.go +++ b/vendor/github.com/containerd/console/tc_zos.go @@ -17,6 +17,9 @@ package console import ( + "os" + "strings" + "golang.org/x/sys/unix" ) @@ -24,3 +27,13 @@ const ( cmdTcGet = unix.TCGETS cmdTcSet = unix.TCSETS ) + +// unlockpt is a no-op on zos. +func unlockpt(_ *os.File) error { + return nil +} + +// ptsname retrieves the name of the first available pts for the given master. +func ptsname(f *os.File) (string, error) { + return "/dev/ttyp" + strings.TrimPrefix(f.Name(), "/dev/ptyp"), nil +} diff --git a/vendor/modules.txt b/vendor/modules.txt index 8e499581b6ce..9dd3aa8ef700 100644 --- a/vendor/modules.txt +++ b/vendor/modules.txt @@ -134,7 +134,7 @@ github.com/compose-spec/compose-go/template github.com/compose-spec/compose-go/tree github.com/compose-spec/compose-go/types github.com/compose-spec/compose-go/utils -# github.com/containerd/console v1.0.3 +# github.com/containerd/console v1.0.4-0.20230706203907-8f6c4e4faef5 ## explicit; go 1.13 github.com/containerd/console # github.com/containerd/containerd v1.7.7 From 380588151c6a35a4512eabf631d0834edc513024 Mon Sep 17 00:00:00 2001 From: Sebastiaan van Stijn Date: Mon, 5 Feb 2024 18:24:02 +0100 Subject: [PATCH 11/13] vendor: github.com/containerd/console v1.0.4 no diff; same commit, but tagged: https://github.com/containerd/console/compare/8f6c4e4faef5...v1.0.4 Signed-off-by: Sebastiaan van Stijn (cherry picked from commit b4c81a4d27324e3c585356599f7abfcb4c777002) --- go.mod | 2 +- go.sum | 4 ++-- vendor/modules.txt | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/go.mod b/go.mod index 369dca5e3d35..e7839c55f20e 100644 --- a/go.mod +++ b/go.mod @@ -6,7 +6,7 @@ require ( github.com/Masterminds/semver/v3 v3.2.1 github.com/aws/aws-sdk-go-v2/config v1.18.16 github.com/compose-spec/compose-go v1.20.0 - github.com/containerd/console v1.0.4-0.20230706203907-8f6c4e4faef5 // include https://github.com/containerd/console/pull/66, which is not yet in a release. + github.com/containerd/console v1.0.4 github.com/containerd/containerd v1.7.7 github.com/containerd/continuity v0.4.2 github.com/containerd/log v0.1.0 diff --git a/go.sum b/go.sum index dddb214c0b35..4c91b461aa5b 100644 --- a/go.sum +++ b/go.sum @@ -127,8 +127,8 @@ github.com/codahale/rfc6979 v0.0.0-20141003034818-6a90f24967eb h1:EDmT6Q9Zs+SbUo github.com/compose-spec/compose-go v1.20.0 h1:h4ZKOst1EF/DwZp7dWkb+wbTVE4nEyT9Lc89to84Ol4= github.com/compose-spec/compose-go v1.20.0/go.mod h1:+MdqXV4RA7wdFsahh/Kb8U0pAJqkg7mr4PM9tFKU8RM= github.com/containerd/cgroups v1.1.0 h1:v8rEWFl6EoqHB+swVNjVoCJE8o3jX7e8nqBGPLaDFBM= -github.com/containerd/console v1.0.4-0.20230706203907-8f6c4e4faef5 h1:Ig+OPkE3XQrrl+SKsOqAjlkrBN/zrr+Qpw7rCuDjRCE= -github.com/containerd/console v1.0.4-0.20230706203907-8f6c4e4faef5/go.mod h1:YynlIjWYF8myEu6sdkwKIvGQq+cOckRm6So2avqoYAk= +github.com/containerd/console v1.0.4 h1:F2g4+oChYvBTsASRTz8NP6iIAi97J3TtSAsLbIFn4ro= +github.com/containerd/console v1.0.4/go.mod h1:YynlIjWYF8myEu6sdkwKIvGQq+cOckRm6So2avqoYAk= github.com/containerd/containerd v1.7.7 h1:QOC2K4A42RQpcrZyptP6z9EJZnlHfHJUfZrAAHe15q4= github.com/containerd/containerd v1.7.7/go.mod h1:3c4XZv6VeT9qgf9GMTxNTMFxGJrGpI2vz1yk4ye+YY8= github.com/containerd/continuity v0.4.2 h1:v3y/4Yz5jwnvqPKJJ+7Wf93fyWoCB3F5EclWG023MDM= diff --git a/vendor/modules.txt b/vendor/modules.txt index 9dd3aa8ef700..3fe6c9a9c03b 100644 --- a/vendor/modules.txt +++ b/vendor/modules.txt @@ -134,7 +134,7 @@ github.com/compose-spec/compose-go/template github.com/compose-spec/compose-go/tree github.com/compose-spec/compose-go/types github.com/compose-spec/compose-go/utils -# github.com/containerd/console v1.0.4-0.20230706203907-8f6c4e4faef5 +# github.com/containerd/console v1.0.4 ## explicit; go 1.13 github.com/containerd/console # github.com/containerd/containerd v1.7.7 From c99c9b1b8b4ba4553314eb69b483c10107565cfe Mon Sep 17 00:00:00 2001 From: Nicolas De Loof Date: Fri, 9 Feb 2024 12:37:27 +0100 Subject: [PATCH 12/13] don't print build details when progress is rawjson Signed-off-by: Nicolas De Loof (cherry picked from commit 598bc16e5d20949d7a704728e75fe7ff2925e593) --- commands/bake.go | 2 +- commands/build.go | 11 +++++++---- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/commands/bake.go b/commands/bake.go index f5eff0f61491..431cecfc1a57 100644 --- a/commands/bake.go +++ b/commands/bake.go @@ -141,7 +141,7 @@ func runBake(dockerCli command.Cli, targets []string, in bakeOptions, cFlags com if err == nil { err = err1 } - if err == nil && progressMode != progressui.QuietMode { + if err == nil && progressMode != progressui.QuietMode && progressMode != progressui.RawJSONMode { desktop.PrintBuildDetails(os.Stderr, printer.BuildRefs(), term) } } diff --git a/commands/build.go b/commands/build.go index 41f341676ba7..af8af4723006 100644 --- a/commands/build.go +++ b/commands/build.go @@ -288,10 +288,13 @@ func runBuild(dockerCli command.Cli, options buildOptions) (err error) { return retErr } - if progressMode != progressui.QuietMode { - desktop.PrintBuildDetails(os.Stderr, printer.BuildRefs(), term) - } else { + switch progressMode { + case progressui.RawJSONMode: + // no additional display + case progressui.QuietMode: fmt.Println(getImageID(resp.ExporterResponse)) + default: + desktop.PrintBuildDetails(os.Stderr, printer.BuildRefs(), term) } if options.imageIDFile != "" { if err := os.WriteFile(options.imageIDFile, []byte(getImageID(resp.ExporterResponse)), 0644); err != nil { @@ -749,7 +752,7 @@ func dockerUlimitToControllerUlimit(u *dockeropts.UlimitOpt) *controllerapi.Ulim } func printWarnings(w io.Writer, warnings []client.VertexWarning, mode progressui.DisplayMode) { - if len(warnings) == 0 || mode == progressui.QuietMode { + if len(warnings) == 0 || mode == progressui.QuietMode || mode == progressui.RawJSONMode { return } fmt.Fprintf(w, "\n ") From 9b763d7598753ce69620a650e081099d350fb1f5 Mon Sep 17 00:00:00 2001 From: CrazyMax <1951866+crazy-max@users.noreply.github.com> Date: Thu, 22 Feb 2024 08:16:21 +0100 Subject: [PATCH 13/13] ci: update docs-upstream workflow Signed-off-by: CrazyMax <1951866+crazy-max@users.noreply.github.com> (cherry picked from commit 560eaf0e78a14b920df29963fbe8faa53699faaf) --- .github/workflows/docs-upstream.yml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/docs-upstream.yml b/.github/workflows/docs-upstream.yml index 45cd4932fa33..2182e2f0bac4 100644 --- a/.github/workflows/docs-upstream.yml +++ b/.github/workflows/docs-upstream.yml @@ -45,18 +45,18 @@ jobs: DOCS_FORMATS: yaml - name: Upload reference YAML docs - uses: actions/upload-artifact@v3 + uses: actions/upload-artifact@v4 with: name: docs-yaml path: /tmp/buildx-docs/out/reference retention-days: 1 validate: - uses: docker/docs/.github/workflows/validate-upstream.yml@e864c797e391fa35aecf1ddcecdbdeb683546424 # pin for artifact v3 support + uses: docker/docs/.github/workflows/validate-upstream.yml@6b73b05acb21edf7995cc5b3c6672d8e314cee7a # pin for artifact v4 support: https://github.com/docker/docs/pull/19220 needs: - docs-yaml with: module-name: docker/buildx data-files-id: docs-yaml data-files-folder: buildx - data-files-placeholder-folder: engine/reference/commandline + create-placeholder-stubs: true