From e4b5243fcde6de59c4392381b260f3db890aca81 Mon Sep 17 00:00:00 2001 From: Arash Deshmeh Date: Tue, 18 Sep 2018 12:29:56 -0400 Subject: [PATCH 1/5] moved integration test TestExportContainerWithOutputAndImportImage from moby/moby to docker/cli. The integration test TestExportContainerWithOutputAndImportImage in moby/moby is the same as TestExportContainerAndImportImage, except for the output file option. Adding a unit test to cover the output file option of the export command here allows the removal of the redundant integration test TestExportContainerWithOutputAndImportImage. Signed-off-by: Arash Deshmeh (cherry picked from commit fc1e11d46ad7a1d2c090919afc3319d881c4a286) Signed-off-by: Sebastiaan van Stijn Upstream-commit: 079adf3f23c3c075dbfdfcee0bd965d1f46f11f1 Component: cli --- .../cli/cli/command/container/client_test.go | 8 +++++ .../cli/cli/command/container/export_test.go | 33 +++++++++++++++++++ 2 files changed, 41 insertions(+) create mode 100644 components/cli/cli/command/container/export_test.go diff --git a/components/cli/cli/command/container/client_test.go b/components/cli/cli/command/container/client_test.go index a2c39bc6ff..3ff1792d51 100644 --- a/components/cli/cli/command/container/client_test.go +++ b/components/cli/cli/command/container/client_test.go @@ -24,6 +24,7 @@ type fakeClient struct { logFunc func(string, types.ContainerLogsOptions) (io.ReadCloser, error) waitFunc func(string) (<-chan container.ContainerWaitOKBody, <-chan error) containerListFunc func(types.ContainerListOptions) ([]types.Container, error) + containerExportFunc func(string) (io.ReadCloser, error) Version string } @@ -124,3 +125,10 @@ func (f *fakeClient) ContainerStart(_ context.Context, container string, options } return nil } + +func (f *fakeClient) ContainerExport(_ context.Context, container string) (io.ReadCloser, error) { + if f.containerExportFunc != nil { + return f.containerExportFunc(container) + } + return nil, nil +} diff --git a/components/cli/cli/command/container/export_test.go b/components/cli/cli/command/container/export_test.go new file mode 100644 index 0000000000..b961ec7630 --- /dev/null +++ b/components/cli/cli/command/container/export_test.go @@ -0,0 +1,33 @@ +package container + +import ( + "io" + "io/ioutil" + "strings" + "testing" + + "github.com/docker/cli/internal/test" + "gotest.tools/assert" + "gotest.tools/fs" +) + +func TestContainerExportOutputToFile(t *testing.T) { + dir := fs.NewDir(t, "export-test") + defer dir.Remove() + + cli := test.NewFakeCli(&fakeClient{ + containerExportFunc: func(container string) (io.ReadCloser, error) { + return ioutil.NopCloser(strings.NewReader("bar")), nil + }, + }) + cmd := NewExportCommand(cli) + cmd.SetOutput(ioutil.Discard) + cmd.SetArgs([]string{"-o", dir.Join("foo"), "container"}) + assert.NilError(t, cmd.Execute()) + + expected := fs.Expected(t, + fs.WithFile("foo", "bar", fs.MatchAnyFileMode), + ) + + assert.Assert(t, fs.Equal(dir.Path(), expected)) +} From 5978d67dd6045c3c4f3747fa6c32da02ce47a8e4 Mon Sep 17 00:00:00 2001 From: Lifubang Date: Wed, 21 Nov 2018 21:41:51 +0800 Subject: [PATCH 2/5] tty initial size error Signed-off-by: Lifubang Signed-off-by: lifubang (cherry picked from commit 3fbffc682b5f8ebd8a361cd35b78d1423b3e380b) Signed-off-by: Sebastiaan van Stijn Upstream-commit: bcae2c440825c1f7863a6caa97248a87574759b5 Component: cli --- .../cli/cli/command/container/client_test.go | 39 +++++++++------ components/cli/cli/command/container/tty.go | 47 ++++++++++++++----- .../cli/cli/command/container/tty_test.go | 30 ++++++++++++ 3 files changed, 90 insertions(+), 26 deletions(-) create mode 100644 components/cli/cli/command/container/tty_test.go diff --git a/components/cli/cli/command/container/client_test.go b/components/cli/cli/command/container/client_test.go index 3ff1792d51..b883ad1db1 100644 --- a/components/cli/cli/command/container/client_test.go +++ b/components/cli/cli/command/container/client_test.go @@ -12,20 +12,24 @@ import ( type fakeClient struct { client.Client - inspectFunc func(string) (types.ContainerJSON, error) - execInspectFunc func(execID string) (types.ContainerExecInspect, error) - execCreateFunc func(container string, config types.ExecConfig) (types.IDResponse, error) - createContainerFunc func(config *container.Config, hostConfig *container.HostConfig, networkingConfig *network.NetworkingConfig, containerName string) (container.ContainerCreateCreatedBody, error) - containerStartFunc func(container string, options types.ContainerStartOptions) error - imageCreateFunc func(parentReference string, options types.ImageCreateOptions) (io.ReadCloser, error) - infoFunc func() (types.Info, error) - containerStatPathFunc func(container, path string) (types.ContainerPathStat, error) - containerCopyFromFunc func(container, srcPath string) (io.ReadCloser, types.ContainerPathStat, error) - logFunc func(string, types.ContainerLogsOptions) (io.ReadCloser, error) - waitFunc func(string) (<-chan container.ContainerWaitOKBody, <-chan error) - containerListFunc func(types.ContainerListOptions) ([]types.Container, error) - containerExportFunc func(string) (io.ReadCloser, error) - Version string + inspectFunc func(string) (types.ContainerJSON, error) + execInspectFunc func(execID string) (types.ContainerExecInspect, error) + execCreateFunc func(container string, config types.ExecConfig) (types.IDResponse, error) + createContainerFunc func(config *container.Config, + hostConfig *container.HostConfig, + networkingConfig *network.NetworkingConfig, + containerName string) (container.ContainerCreateCreatedBody, error) + containerStartFunc func(container string, options types.ContainerStartOptions) error + imageCreateFunc func(parentReference string, options types.ImageCreateOptions) (io.ReadCloser, error) + infoFunc func() (types.Info, error) + containerStatPathFunc func(container, path string) (types.ContainerPathStat, error) + containerCopyFromFunc func(container, srcPath string) (io.ReadCloser, types.ContainerPathStat, error) + logFunc func(string, types.ContainerLogsOptions) (io.ReadCloser, error) + waitFunc func(string) (<-chan container.ContainerWaitOKBody, <-chan error) + containerListFunc func(types.ContainerListOptions) ([]types.Container, error) + containerExportFunc func(string) (io.ReadCloser, error) + containerExecResizeFunc func(id string, options types.ResizeOptions) error + Version string } func (f *fakeClient) ContainerList(_ context.Context, options types.ContainerListOptions) ([]types.Container, error) { @@ -132,3 +136,10 @@ func (f *fakeClient) ContainerExport(_ context.Context, container string) (io.Re } return nil, nil } + +func (f *fakeClient) ContainerExecResize(_ context.Context, id string, options types.ResizeOptions) error { + if f.containerExecResizeFunc != nil { + return f.containerExecResizeFunc(id, options) + } + return nil +} diff --git a/components/cli/cli/command/container/tty.go b/components/cli/cli/command/container/tty.go index cb49ded8ef..b7003f1a04 100644 --- a/components/cli/cli/command/container/tty.go +++ b/components/cli/cli/command/container/tty.go @@ -16,9 +16,9 @@ import ( ) // resizeTtyTo resizes tty to specific height and width -func resizeTtyTo(ctx context.Context, client client.ContainerAPIClient, id string, height, width uint, isExec bool) { +func resizeTtyTo(ctx context.Context, client client.ContainerAPIClient, id string, height, width uint, isExec bool) error { if height == 0 && width == 0 { - return + return nil } options := types.ResizeOptions{ @@ -34,19 +34,42 @@ func resizeTtyTo(ctx context.Context, client client.ContainerAPIClient, id strin } if err != nil { - logrus.Debugf("Error resize: %s", err) + logrus.Debugf("Error resize: %s\r", err) + } + return err +} + +// resizeTty is to resize the tty with cli out's tty size +func resizeTty(ctx context.Context, cli command.Cli, id string, isExec bool) error { + height, width := cli.Out().GetTtySize() + return resizeTtyTo(ctx, cli.Client(), id, height, width, isExec) +} + +// initTtySize is to init the tty's size to the same as the window, if there is an error, it will retry 5 times. +func initTtySize(ctx context.Context, cli command.Cli, id string, isExec bool, resizeTtyFunc func(ctx context.Context, cli command.Cli, id string, isExec bool) error) { + rttyFunc := resizeTtyFunc + if rttyFunc == nil { + rttyFunc = resizeTty + } + if err := rttyFunc(ctx, cli, id, isExec); err != nil { + go func() { + var err error + for retry := 0; retry < 5; retry++ { + time.Sleep(10 * time.Millisecond) + if err = rttyFunc(ctx, cli, id, isExec); err == nil { + break + } + } + if err != nil { + fmt.Fprintln(cli.Err(), "failed to resize tty, using default size") + } + }() } } // MonitorTtySize updates the container tty size when the terminal tty changes size func MonitorTtySize(ctx context.Context, cli command.Cli, id string, isExec bool) error { - resizeTty := func() { - height, width := cli.Out().GetTtySize() - resizeTtyTo(ctx, cli.Client(), id, height, width, isExec) - } - - resizeTty() - + initTtySize(ctx, cli, id, isExec, resizeTty) if runtime.GOOS == "windows" { go func() { prevH, prevW := cli.Out().GetTtySize() @@ -55,7 +78,7 @@ func MonitorTtySize(ctx context.Context, cli command.Cli, id string, isExec bool h, w := cli.Out().GetTtySize() if prevW != w || prevH != h { - resizeTty() + resizeTty(ctx, cli, id, isExec) } prevH = h prevW = w @@ -66,7 +89,7 @@ func MonitorTtySize(ctx context.Context, cli command.Cli, id string, isExec bool gosignal.Notify(sigchan, signal.SIGWINCH) go func() { for range sigchan { - resizeTty() + resizeTty(ctx, cli, id, isExec) } }() } diff --git a/components/cli/cli/command/container/tty_test.go b/components/cli/cli/command/container/tty_test.go new file mode 100644 index 0000000000..eb2e0bfaab --- /dev/null +++ b/components/cli/cli/command/container/tty_test.go @@ -0,0 +1,30 @@ +package container + +import ( + "context" + "testing" + "time" + + "github.com/docker/cli/cli/command" + "github.com/docker/cli/internal/test" + "github.com/docker/docker/api/types" + "github.com/pkg/errors" + "gotest.tools/assert" + is "gotest.tools/assert/cmp" +) + +func TestInitTtySizeErrors(t *testing.T) { + expectedError := "failed to resize tty, using default size\n" + fakeContainerExecResizeFunc := func(id string, options types.ResizeOptions) error { + return errors.Errorf("Error response from daemon: no such exec") + } + fakeResizeTtyFunc := func(ctx context.Context, cli command.Cli, id string, isExec bool) error { + height, width := uint(1024), uint(768) + return resizeTtyTo(ctx, cli.Client(), id, height, width, isExec) + } + ctx := context.Background() + cli := test.NewFakeCli(&fakeClient{containerExecResizeFunc: fakeContainerExecResizeFunc}) + initTtySize(ctx, cli, "8mm8nn8tt8bb", true, fakeResizeTtyFunc) + time.Sleep(100 * time.Millisecond) + assert.Check(t, is.Equal(expectedError, cli.ErrBuffer().String())) +} From 69d285846043e012e4f6fa5da96416c6b95c058e Mon Sep 17 00:00:00 2001 From: Sebastiaan van Stijn Date: Thu, 29 Nov 2018 01:06:10 +0100 Subject: [PATCH 3/5] Do not patch Dockerfiles in CI When building the Dockerfiles for development, those images are mainly used to create a reproducible build-environment. The source code is bind-mounted into the image at runtime; there is no need to create an image with the actual source code, and copying the source code into the image would lead to a new image being created for each code-change (possibly leading up to many "dangling" images for previous code-changes). However, when building (and using) the development images in CI, bind-mounting is not an option, because the daemon is running remotely. To make this work, the circle-ci script patched the Dockerfiles when CI is run; adding a `COPY` to the respective Dockerfiles. Patching Dockerfiles is not really a "best practice" and, even though the source code does not and up in the image, the source would still be _sent_ to the daemon for each build (unless BuildKit is used). This patch updates the makefiles, circle-ci script, and Dockerfiles; - When building the Dockerfiles locally, pipe the Dockerfile through stdin. Doing so, prevents the build-context from being sent to the daemon. This speeds up the build, and doesn't fill up the Docker "temp" directory with content that's not used - Now that no content is sent, add the COPY instructions to the Dockerfiles, and remove the code in the circle-ci script to "live patch" the Dockerfiles. Before this patch is applied (with cache): ``` $ time make -f docker.Makefile build_shell_validate_image docker build -t docker-cli-shell-validate -f ./dockerfiles/Dockerfile.shellcheck . Sending build context to Docker daemon 41MB Step 1/2 : FROM debian:stretch-slim ... Successfully built 81e14e8ad856 Successfully tagged docker-cli-shell-validate:latest 2.75 real 0.45 user 0.56 sys ``` After this patch is applied (with cache):: ``` $ time make -f docker.Makefile build_shell_validate_image cat ./dockerfiles/Dockerfile.shellcheck | docker build -t docker-cli-shell-validate - Sending build context to Docker daemon 2.048kB Step 1/2 : FROM debian:stretch-slim ... Successfully built 81e14e8ad856 Successfully tagged docker-cli-shell-validate:latest 0.33 real 0.07 user 0.08 sys ``` Signed-off-by: Sebastiaan van Stijn (cherry picked from commit 166856ab1b1681de107b5e064ea89ea4b27154fd) Signed-off-by: Sebastiaan van Stijn Upstream-commit: 8997667aa2ee10bd8dfba7e97efd9e6f7bd63bee Component: cli --- components/cli/circle.yml | 20 +++++-------------- components/cli/docker.Makefile | 15 +++++++++----- components/cli/dockerfiles/Dockerfile.cross | 1 + components/cli/dockerfiles/Dockerfile.dev | 1 + components/cli/dockerfiles/Dockerfile.lint | 1 + .../cli/dockerfiles/Dockerfile.shellcheck | 1 + 6 files changed, 19 insertions(+), 20 deletions(-) diff --git a/components/cli/circle.yml b/components/cli/circle.yml index 073d4cf69e..3b4d9259e9 100644 --- a/components/cli/circle.yml +++ b/components/cli/circle.yml @@ -16,9 +16,7 @@ jobs: - run: name: "Lint" command: | - dockerfile=dockerfiles/Dockerfile.lint - echo "COPY . ." >> $dockerfile - docker build -f $dockerfile --tag cli-linter:$CIRCLE_BUILD_NUM . + docker build -f dockerfiles/Dockerfile.lint --tag cli-linter:$CIRCLE_BUILD_NUM . docker run --rm cli-linter:$CIRCLE_BUILD_NUM cross: @@ -34,9 +32,7 @@ jobs: - run: name: "Cross" command: | - dockerfile=dockerfiles/Dockerfile.cross - echo "COPY . ." >> $dockerfile - docker build -f $dockerfile --tag cli-builder:$CIRCLE_BUILD_NUM . + docker build -f dockerfiles/Dockerfile.cross --tag cli-builder:$CIRCLE_BUILD_NUM . name=cross-$CIRCLE_BUILD_NUM-$CIRCLE_NODE_INDEX docker run \ -e CROSS_GROUP=$CIRCLE_NODE_INDEX \ @@ -60,9 +56,7 @@ jobs: - run: name: "Unit Test with Coverage" command: | - dockerfile=dockerfiles/Dockerfile.dev - echo "COPY . ." >> $dockerfile - docker build -f $dockerfile --tag cli-builder:$CIRCLE_BUILD_NUM . + docker build -f dockerfiles/Dockerfile.dev --tag cli-builder:$CIRCLE_BUILD_NUM . docker run --name \ test-$CIRCLE_BUILD_NUM cli-builder:$CIRCLE_BUILD_NUM \ make test-coverage @@ -89,10 +83,8 @@ jobs: - run: name: "Validate Vendor, Docs, and Code Generation" command: | - dockerfile=dockerfiles/Dockerfile.dev - echo "COPY . ." >> $dockerfile rm -f .dockerignore # include .git - docker build -f $dockerfile --tag cli-builder-with-git:$CIRCLE_BUILD_NUM . + docker build -f dockerfiles/Dockerfile.dev --tag cli-builder-with-git:$CIRCLE_BUILD_NUM . docker run --rm cli-builder-with-git:$CIRCLE_BUILD_NUM \ make ci-validate shellcheck: @@ -107,9 +99,7 @@ jobs: - run: name: "Run shellcheck" command: | - dockerfile=dockerfiles/Dockerfile.shellcheck - echo "COPY . ." >> $dockerfile - docker build -f $dockerfile --tag cli-validator:$CIRCLE_BUILD_NUM . + docker build -f dockerfiles/Dockerfile.shellcheck --tag cli-validator:$CIRCLE_BUILD_NUM . docker run --rm cli-validator:$CIRCLE_BUILD_NUM \ make shellcheck workflows: diff --git a/components/cli/docker.Makefile b/components/cli/docker.Makefile index 2ff2594a7f..628e989fb0 100644 --- a/components/cli/docker.Makefile +++ b/components/cli/docker.Makefile @@ -17,24 +17,29 @@ ENVVARS = -e VERSION=$(VERSION) -e GITCOMMIT -e PLATFORM # build docker image (dockerfiles/Dockerfile.build) .PHONY: build_docker_image build_docker_image: - docker build ${DOCKER_BUILD_ARGS} -t $(DEV_DOCKER_IMAGE_NAME) -f ./dockerfiles/Dockerfile.dev . + # build dockerfile from stdin so that we don't send the build-context; source is bind-mounted in the development environment + cat ./dockerfiles/Dockerfile.dev | docker build ${DOCKER_BUILD_ARGS} -t $(DEV_DOCKER_IMAGE_NAME) - # build docker image having the linting tools (dockerfiles/Dockerfile.lint) .PHONY: build_linter_image build_linter_image: - docker build ${DOCKER_BUILD_ARGS} -t $(LINTER_IMAGE_NAME) -f ./dockerfiles/Dockerfile.lint . + # build dockerfile from stdin so that we don't send the build-context; source is bind-mounted in the development environment + cat ./dockerfiles/Dockerfile.lint | docker build ${DOCKER_BUILD_ARGS} -t $(LINTER_IMAGE_NAME) - .PHONY: build_cross_image build_cross_image: - docker build ${DOCKER_BUILD_ARGS} -t $(CROSS_IMAGE_NAME) -f ./dockerfiles/Dockerfile.cross . + # build dockerfile from stdin so that we don't send the build-context; source is bind-mounted in the development environment + cat ./dockerfiles/Dockerfile.cross | docker build ${DOCKER_BUILD_ARGS} -t $(CROSS_IMAGE_NAME) - .PHONY: build_shell_validate_image build_shell_validate_image: - docker build -t $(VALIDATE_IMAGE_NAME) -f ./dockerfiles/Dockerfile.shellcheck . + # build dockerfile from stdin so that we don't send the build-context; source is bind-mounted in the development environment + cat ./dockerfiles/Dockerfile.shellcheck | docker build -t $(VALIDATE_IMAGE_NAME) - .PHONY: build_binary_native_image build_binary_native_image: - docker build -t $(BINARY_NATIVE_IMAGE_NAME) -f ./dockerfiles/Dockerfile.binary-native . + # build dockerfile from stdin so that we don't send the build-context; source is bind-mounted in the development environment + cat ./dockerfiles/Dockerfile.binary-native | docker build -t $(BINARY_NATIVE_IMAGE_NAME) - .PHONY: build_e2e_image build_e2e_image: diff --git a/components/cli/dockerfiles/Dockerfile.cross b/components/cli/dockerfiles/Dockerfile.cross index 9ee67e4eef..240ff2bfb5 100644 --- a/components/cli/dockerfiles/Dockerfile.cross +++ b/components/cli/dockerfiles/Dockerfile.cross @@ -1,3 +1,4 @@ FROM dockercore/golang-cross:1.10.8@sha256:a93210f55a8137b4aa4b9f033ac7a80b66ab6337e98e7afb62abe93b4ad73cad ENV DISABLE_WARN_OUTSIDE_CONTAINER=1 WORKDIR /go/src/github.com/docker/cli +COPY . . diff --git a/components/cli/dockerfiles/Dockerfile.dev b/components/cli/dockerfiles/Dockerfile.dev index c155587a7b..c8ce67ab06 100644 --- a/components/cli/dockerfiles/Dockerfile.dev +++ b/components/cli/dockerfiles/Dockerfile.dev @@ -22,3 +22,4 @@ ENV CGO_ENABLED=0 \ DISABLE_WARN_OUTSIDE_CONTAINER=1 WORKDIR /go/src/github.com/docker/cli CMD sh +COPY . . diff --git a/components/cli/dockerfiles/Dockerfile.lint b/components/cli/dockerfiles/Dockerfile.lint index 8be2d6114c..2a5354f432 100644 --- a/components/cli/dockerfiles/Dockerfile.lint +++ b/components/cli/dockerfiles/Dockerfile.lint @@ -15,3 +15,4 @@ ENV CGO_ENABLED=0 ENV DISABLE_WARN_OUTSIDE_CONTAINER=1 ENTRYPOINT ["/usr/local/bin/gometalinter"] CMD ["--config=gometalinter.json", "./..."] +COPY . . diff --git a/components/cli/dockerfiles/Dockerfile.shellcheck b/components/cli/dockerfiles/Dockerfile.shellcheck index 43112b314d..4d0ddd3332 100644 --- a/components/cli/dockerfiles/Dockerfile.shellcheck +++ b/components/cli/dockerfiles/Dockerfile.shellcheck @@ -7,3 +7,4 @@ RUN apt-get update && \ WORKDIR /go/src/github.com/docker/cli ENV DISABLE_WARN_OUTSIDE_CONTAINER=1 CMD bash +COPY . . From 6006ae7e52f8ce3baadd33fee5f5748b768d5aab Mon Sep 17 00:00:00 2001 From: Sebastiaan van Stijn Date: Thu, 29 Nov 2018 01:19:18 +0100 Subject: [PATCH 4/5] Use official shellcheck image This patch switches the shellcheck image to use the official image from Docker Hub. Note that this does not yet update shellcheck to the latest version (v0.5.x); Shellcheck v0.4.7 added some new checks, which makes CI currently fail, so will be done in a follow-up PR. Instead, the v0.4.6 version is used in this PR, which is closest to the same version as was installed in the image before this change; ``` docker run --rm docker-cli-shell-validate shellcheck --version ShellCheck - shell script analysis tool version: 0.4.4 license: GNU General Public License, version 3 website: http://www.shellcheck.net ``` Signed-off-by: Sebastiaan van Stijn (cherry picked from commit 388646eab0259c7e7410fe51679d6e4191cd8ab4) Signed-off-by: Sebastiaan van Stijn Upstream-commit: b59752479b72f8b6c7367f48d51e81ba8fef0024 Component: cli --- components/cli/dockerfiles/Dockerfile.shellcheck | 11 ++++------- components/cli/scripts/warn-outside-container | 4 ++-- 2 files changed, 6 insertions(+), 9 deletions(-) diff --git a/components/cli/dockerfiles/Dockerfile.shellcheck b/components/cli/dockerfiles/Dockerfile.shellcheck index 4d0ddd3332..2507062ee9 100644 --- a/components/cli/dockerfiles/Dockerfile.shellcheck +++ b/components/cli/dockerfiles/Dockerfile.shellcheck @@ -1,10 +1,7 @@ -FROM debian:stretch-slim - -RUN apt-get update && \ - apt-get -y install make shellcheck && \ - apt-get clean - +FROM koalaman/shellcheck-alpine:v0.4.6 +RUN apk add --no-cache bash make WORKDIR /go/src/github.com/docker/cli ENV DISABLE_WARN_OUTSIDE_CONTAINER=1 -CMD bash +ENTRYPOINT [""] +CMD ["/bin/sh"] COPY . . diff --git a/components/cli/scripts/warn-outside-container b/components/cli/scripts/warn-outside-container index e937caafeb..ecbecc0ea2 100755 --- a/components/cli/scripts/warn-outside-container +++ b/components/cli/scripts/warn-outside-container @@ -1,9 +1,9 @@ -#!/usr/bin/env bash +#!/usr/bin/env sh set -eu target="${1:-}" -if [[ "$target" != "help" && -z "${DISABLE_WARN_OUTSIDE_CONTAINER:-}" ]]; then +if [ "$target" != "help" ] && [ -z "${DISABLE_WARN_OUTSIDE_CONTAINER:-}" ]; then ( echo echo From 4dba9e73a527eabd9b87c2ef81bc857798119b7d Mon Sep 17 00:00:00 2001 From: Sebastiaan van Stijn Date: Tue, 26 Feb 2019 12:49:44 +0100 Subject: [PATCH 5/5] Update to shellcheck v0.6.0 Signed-off-by: Sebastiaan van Stijn (cherry picked from commit ff107b313a00c1ab8989f380e1ef65529b3f2e37) Signed-off-by: Sebastiaan van Stijn Upstream-commit: 9a5296c8f15e2dc1b83bc22327f70b499a19ab4c Component: cli --- components/cli/contrib/completion/bash/docker | 8 +++++--- components/cli/dockerfiles/Dockerfile.shellcheck | 4 +--- components/cli/scripts/gen/windows-resources | 8 ++++---- components/cli/scripts/test/e2e/run | 2 +- 4 files changed, 11 insertions(+), 11 deletions(-) diff --git a/components/cli/contrib/completion/bash/docker b/components/cli/contrib/completion/bash/docker index 192cdbf526..92d5740861 100644 --- a/components/cli/contrib/completion/bash/docker +++ b/components/cli/contrib/completion/bash/docker @@ -1,12 +1,14 @@ #!/usr/bin/env bash -# shellcheck disable=SC2016,SC2119,SC2155 +# shellcheck disable=SC2016,SC2119,SC2155,SC2206,SC2207 # # Shellcheck ignore list: # - SC2016: Expressions don't expand in single quotes, use double quotes for that. # - SC2119: Use foo "$@" if function's $1 should mean script's $1. # - SC2155: Declare and assign separately to avoid masking return values. -# -# You can find more details for each warning at the following page: +# - SC2206: Quote to prevent word splitting, or split robustly with mapfile or read -a. +# - SC2207: Prefer mapfile or read -a to split command output (or quote to avoid splitting). +# +# You can find more details for each warning at the following page: # https://github.com/koalaman/shellcheck/wiki/ # # bash completion file for core docker commands diff --git a/components/cli/dockerfiles/Dockerfile.shellcheck b/components/cli/dockerfiles/Dockerfile.shellcheck index 2507062ee9..dd3cab79b2 100644 --- a/components/cli/dockerfiles/Dockerfile.shellcheck +++ b/components/cli/dockerfiles/Dockerfile.shellcheck @@ -1,7 +1,5 @@ -FROM koalaman/shellcheck-alpine:v0.4.6 +FROM koalaman/shellcheck-alpine:v0.6.0 RUN apk add --no-cache bash make WORKDIR /go/src/github.com/docker/cli ENV DISABLE_WARN_OUTSIDE_CONTAINER=1 -ENTRYPOINT [""] -CMD ["/bin/sh"] COPY . . diff --git a/components/cli/scripts/gen/windows-resources b/components/cli/scripts/gen/windows-resources index 14b45e08e0..5fdc1b4ade 100755 --- a/components/cli/scripts/gen/windows-resources +++ b/components/cli/scripts/gen/windows-resources @@ -7,7 +7,7 @@ set -eu -o pipefail SCRIPTDIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" # shellcheck source=/go/src/github.com/docker/cli/scripts/build/.variables -source $SCRIPTDIR/../build/.variables +source "$SCRIPTDIR"/../build/.variables RESOURCES=$SCRIPTDIR/../winresources @@ -26,9 +26,9 @@ VERSION_QUAD=$(echo -n "$VERSION" | sed -re 's/^([0-9.]*).*$/\1/' | tr . ,) # Pass version and commit information into the resource compiler defs= -[ ! -z "$VERSION" ] && defs+=( "-D DOCKER_VERSION=\"$VERSION\"") -[ ! -z "$VERSION_QUAD" ] && defs+=( "-D DOCKER_VERSION_QUAD=$VERSION_QUAD") -[ ! -z "$GITCOMMIT" ] && defs+=( "-D DOCKER_COMMIT=\"$GITCOMMIT\"") +[ -n "$VERSION" ] && defs+=( "-D DOCKER_VERSION=\"$VERSION\"") +[ -n "$VERSION_QUAD" ] && defs+=( "-D DOCKER_VERSION_QUAD=$VERSION_QUAD") +[ -n "$GITCOMMIT" ] && defs+=( "-D DOCKER_COMMIT=\"$GITCOMMIT\"") function makeres { "$WINDRES" \ diff --git a/components/cli/scripts/test/e2e/run b/components/cli/scripts/test/e2e/run index 173397a703..b960709701 100755 --- a/components/cli/scripts/test/e2e/run +++ b/components/cli/scripts/test/e2e/run @@ -70,7 +70,7 @@ function runtests { GOPATH="$GOPATH" \ PATH="$PWD/build/:/usr/bin" \ HOME="$HOME" \ - "$(which go)" test -v ./e2e/... ${TESTFLAGS-} + "$(command -v go)" test -v ./e2e/... ${TESTFLAGS-} } export unique_id="${E2E_UNIQUE_ID:-cliendtoendsuite}"