From 62ea2bf1aa5699095111953e3a401d3299fe07e9 Mon Sep 17 00:00:00 2001 From: CrazyMax Date: Wed, 17 Nov 2021 17:18:15 +0100 Subject: [PATCH] GitHub Actions e2e tests Signed-off-by: CrazyMax --- .github/workflows/build.yml | 15 ++++++ .github/workflows/e2e.yml | 54 ++++++++++++++++++++ Dockerfile | 49 ++++++++++++++++-- Jenkinsfile | 47 ------------------ Makefile | 8 --- README.md | 1 - docker-bake.hcl | 30 ++++++++++- docker.Makefile | 42 ++++++---------- dockerfiles/Dockerfile.binary-native | 10 ---- dockerfiles/Dockerfile.e2e | 45 ----------------- scripts/build/.variables | 74 +++++++++++++++++++++------- scripts/build/binary | 47 +----------------- scripts/build/plugins | 12 ++--- scripts/build/plugins-osx | 18 ------- scripts/build/plugins-windows | 14 ------ 15 files changed, 222 insertions(+), 244 deletions(-) create mode 100644 .github/workflows/e2e.yml delete mode 100644 Jenkinsfile delete mode 100644 dockerfiles/Dockerfile.binary-native delete mode 100644 dockerfiles/Dockerfile.e2e delete mode 100755 scripts/build/plugins-osx delete mode 100755 scripts/build/plugins-windows diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 0807d5d839..0be191b6d6 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -50,3 +50,18 @@ jobs: name: ${{ matrix.target }} path: ./build/* if-no-files-found: error + + plugins: + runs-on: ubuntu-latest + steps: + - + name: Checkout + uses: actions/checkout@v2 + - + name: Set up Docker Buildx + uses: docker/setup-buildx-action@v1 + - + name: Build plugins + uses: docker/bake-action@v1 + with: + targets: plugins-cross diff --git a/.github/workflows/e2e.yml b/.github/workflows/e2e.yml new file mode 100644 index 0000000000..a43924c65d --- /dev/null +++ b/.github/workflows/e2e.yml @@ -0,0 +1,54 @@ +name: e2e + +on: + workflow_dispatch: + push: + branches: + - 'master' + - '[0-9]+.[0-9]{2}' + tags: + - 'v*' + pull_request: + +jobs: + e2e: + runs-on: ubuntu-latest + strategy: + fail-fast: false + matrix: + target: + - non-experimental + - experimental + - connhelper-ssh + base: + - alpine + - buster + engine-version: +# - 20.10-dind # FIXME: Fails on 20.10 + - stable-dind # TODO: Use 20.10-dind, stable-dind is deprecated + include: + - target: non-experimental + engine-version: 19.03-dind + steps: + - + name: Checkout + uses: actions/checkout@v2 + - + name: Update daemon.json + run: | + sudo jq '.experimental = true' < /etc/docker/daemon.json > /tmp/docker.json + sudo mv /tmp/docker.json /etc/docker/daemon.json + sudo cat /etc/docker/daemon.json + sudo service docker restart + docker version + docker info + - + name: Set up Docker Buildx + uses: docker/setup-buildx-action@v1 + - + name: Run ${{ matrix.target }} + run: | + make -f docker.Makefile test-e2e-${{ matrix.target }} + env: + BASE_VARIANT: ${{ matrix.base }} + E2E_ENGINE_VERSION: ${{ matrix.engine-version }} diff --git a/Dockerfile b/Dockerfile index 83523e2d19..8b7510d2ac 100644 --- a/Dockerfile +++ b/Dockerfile @@ -20,7 +20,7 @@ FROM --platform=$BUILDPLATFORM tonistiigi/xx:${XX_VERSION} AS xx FROM go-${TARGETOS} AS build-base-alpine COPY --from=xx / / -RUN apk add --no-cache clang lld llvm file git +RUN apk add --no-cache bash clang lld llvm file git WORKDIR /go/src/github.com/docker/cli FROM build-base-alpine AS build-alpine @@ -30,7 +30,7 @@ RUN xx-apk add --no-cache musl-dev gcc FROM go-${TARGETOS} AS build-base-buster COPY --from=xx / / -RUN apt-get update && apt-get install --no-install-recommends -y clang lld file +RUN apt-get update && apt-get install --no-install-recommends -y bash clang lld file WORKDIR /go/src/github.com/docker/cli FROM build-base-buster AS build-buster @@ -65,8 +65,51 @@ RUN --mount=type=bind,target=.,ro \ TARGET=/out ./scripts/build/binary && \ xx-verify $([ "$GO_LINKMODE" = "static" ] && echo "--static") /out/docker -FROM build-base-${BASE_VARIANT} AS dev +FROM build-${BASE_VARIANT} AS build-plugins +ARG GO_LINKMODE=static +ARG GO_BUILDTAGS +ARG GO_STRIP +ARG CGO_ENABLED +ARG VERSION +RUN --mount=ro --mount=type=cache,target=/root/.cache \ + --mount=from=dockercore/golang-cross:xx-sdk-extras,target=/xx-sdk,src=/xx-sdk \ + xx-go --wrap && \ + TARGET=/out ./scripts/build/plugins e2e/cli-plugins/plugins/* + +FROM build-base-alpine AS e2e-base-alpine +RUN apk add --no-cache build-base curl docker-compose openssl openssh-client + +FROM build-base-buster AS e2e-base-buster +RUN apt-get update && apt-get install -y build-essential curl openssl openssh-client +ARG COMPOSE_VERSION=1.29.2 +RUN curl -fsSL https://github.com/docker/compose/releases/download/${COMPOSE_VERSION}/docker-compose-$(uname -s)-$(uname -m) -o /usr/local/bin/docker-compose && \ + chmod +x /usr/local/bin/docker-compose + +FROM build-${BASE_VARIANT} AS gotestsum +ARG GOTESTSUM_VERSION=v1.7.0 +RUN --mount=type=cache,target=/root/.cache/go-build \ + --mount=type=cache,target=/go/pkg/mod \ + GOBIN=/out GO111MODULE=on go install "gotest.tools/gotestsum@${GOTESTSUM_VERSION}" \ + && /out/gotestsum --version + +FROM e2e-base-${BASE_VARIANT} AS e2e +ARG NOTARY_VERSION=v0.6.1 +ADD --chmod=0755 https://github.com/theupdateframework/notary/releases/download/${NOTARY_VERSION}/notary-Linux-amd64 /usr/local/bin/notary +COPY e2e/testdata/notary/root-ca.cert /usr/share/ca-certificates/notary.cert +RUN echo 'notary.cert' >> /etc/ca-certificates.conf && update-ca-certificates +COPY --from=gotestsum /out/gotestsum /usr/bin/gotestsum +COPY --from=build /out ./build/ +COPY --from=build-plugins /out ./build/ +COPY . . +ENV DOCKER_BUILDKIT=1 +ENV PATH=/go/src/github.com/docker/cli/build:$PATH +CMD ./scripts/test/e2e/entry + +FROM build-base-${BASE_VARIANT} AS dev COPY . . FROM scratch AS binary COPY --from=build /out . + +FROM scratch AS plugins +COPY --from=build-plugins /out . diff --git a/Jenkinsfile b/Jenkinsfile deleted file mode 100644 index 1e0850257b..0000000000 --- a/Jenkinsfile +++ /dev/null @@ -1,47 +0,0 @@ -pipeline { - agent { - label "amd64 && ubuntu-1804 && overlay2" - } - - options { - timeout(time: 60, unit: 'MINUTES') - } - - stages { - stage("Docker info") { - steps { - sh "docker version" - sh "docker info" - } - } - stage("e2e (non-experimental) - stable engine") { - steps { - sh "E2E_UNIQUE_ID=clie2e${BUILD_NUMBER} \ - IMAGE_TAG=clie2e${BUILD_NUMBER} \ - make -f docker.Makefile test-e2e-non-experimental" - } - } - stage("e2e (non-experimental) - 19.03 engine") { - steps { - sh "E2E_ENGINE_VERSION=19.03-dind \ - E2E_UNIQUE_ID=clie2e${BUILD_NUMBER} \ - IMAGE_TAG=clie2e${BUILD_NUMBER} \ - make -f docker.Makefile test-e2e-non-experimental" - } - } - stage("e2e (experimental)") { - steps { - sh "E2E_UNIQUE_ID=clie2e${BUILD_NUMBER} \ - IMAGE_TAG=clie2e${BUILD_NUMBER} \ - make -f docker.Makefile test-e2e-experimental" - } - } - stage("e2e (ssh connhelper)") { - steps { - sh "E2E_UNIQUE_ID=clie2e${BUILD_NUMBER} \ - IMAGE_TAG=clie2e${BUILD_NUMBER} \ - make -f docker.Makefile test-e2e-connhelper-ssh" - } - } - } -} diff --git a/Makefile b/Makefile index b478b14ef6..a41aca8ba7 100644 --- a/Makefile +++ b/Makefile @@ -48,14 +48,6 @@ dynbinary: ## build dynamically linked binary plugins: ## build example CLI plugins ./scripts/build/plugins -.PHONY: plugins-windows -plugins-windows: ## build example CLI plugins for Windows - ./scripts/build/plugins-windows - -.PHONY: plugins-osx -plugins-osx: ## build example CLI plugins for macOS - ./scripts/build/plugins-osx - vendor: vendor.conf ## check that vendor matches vendor.conf rm -rf vendor bash -c 'vndr |& grep -v -i clone | tee ./vndr.log' diff --git a/README.md b/README.md index 4adf3d14f1..d04bfd0843 100644 --- a/README.md +++ b/README.md @@ -3,7 +3,6 @@ [![PkgGoDev](https://img.shields.io/badge/go.dev-docs-007d9c?logo=go&logoColor=white)](https://pkg.go.dev/github.com/docker/cli) [![Build Status](https://img.shields.io/github/workflow/status/docker/cli/build?logo=github)](https://github.com/docker/cli/actions?query=workflow%3Abuild) [![CircleCI Status](https://img.shields.io/circleci/build/github/docker/cli/master?logo=circleci)](https://circleci.com/gh/docker/cli/tree/master) -[![Jenkins Status](https://img.shields.io/jenkins/build?jobUrl=https%3A%2F%2Fci.docker.com%2Fpublic%2Fjob%2Fcli%2Fjob%2Fmaster&logo=jenkins)](https://ci.docker.com/public/job/cli/job/master) [![Go Report Card](https://goreportcard.com/badge/github.com/docker/cli)](https://goreportcard.com/report/github.com/docker/cli) [![Codecov](https://codecov.io/gh/docker/cli/branch/master/graph/badge.svg)](https://codecov.io/gh/docker/cli) diff --git a/docker-bake.hcl b/docker-bake.hcl index 90978c7fb3..38ea5300de 100644 --- a/docker-bake.hcl +++ b/docker-bake.hcl @@ -1,14 +1,15 @@ variable "VERSION" { default = "" } - variable "USE_GLIBC" { default = "" } - variable "STRIP_TARGET" { default = "" } +variable "IMAGE_NAME" { + default = "docker-cli" +} # Sets the name of the company that produced the windows binary. variable "COMPANY_NAME" { @@ -38,6 +39,17 @@ target "dynbinary" { } } +target "plugins" { + target = "plugins" + platforms = ["local"] + output = ["build"] + args = { + BASE_VARIANT = USE_GLIBC != "" ? "buster" : "alpine" + VERSION = VERSION + GO_STRIP = STRIP_TARGET + } +} + target "platforms" { platforms = concat(["linux/amd64", "linux/386", "linux/arm64", "linux/arm", "linux/ppc64le", "linux/s390x", "darwin/amd64", "darwin/arm64", "windows/amd64", "windows/arm", "windows/386"], USE_GLIBC!=""?[]:["windows/arm64"]) } @@ -50,6 +62,10 @@ target "dynbinary-cross" { inherits = ["dynbinary", "platforms"] } +target "plugins-cross" { + inherits = ["plugins", "platforms"] +} + target "lint" { dockerfile = "./dockerfiles/Dockerfile.lint" target = "lint" @@ -61,3 +77,13 @@ target "shellcheck" { target = "shellcheck" output = ["type=cacheonly"] } + +target "e2e-image" { + target = "e2e" + output = ["type=docker"] + tags = ["${IMAGE_NAME}"] + args = { + BASE_VARIANT = USE_GLIBC != "" ? "buster" : "alpine" + VERSION = VERSION + } +} diff --git a/docker.Makefile b/docker.Makefile index 9310d33c3f..8af66bf80e 100644 --- a/docker.Makefile +++ b/docker.Makefile @@ -13,9 +13,7 @@ DOCKER_CLI_GO_BUILD_CACHE ?= y COMPANY_NAME ?= DEV_DOCKER_IMAGE_NAME = docker-cli-dev$(IMAGE_TAG) -BINARY_NATIVE_IMAGE_NAME = docker-cli-native$(IMAGE_TAG) -CROSS_IMAGE_NAME = docker-cli-cross$(IMAGE_TAG) -E2E_IMAGE_NAME = docker-cli-e2e$(IMAGE_TAG) +E2E_IMAGE_NAME = docker-cli-e2e E2E_ENGINE_VERSION ?= CACHE_VOLUME_NAME := docker-cli-dev-cache ifeq ($(DOCKER_CLI_GO_BUILD_CACHE),y) @@ -33,15 +31,6 @@ build_docker_image: # 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} --build-arg=GO_VERSION -t $(DEV_DOCKER_IMAGE_NAME) - -.PHONY: build_binary_native_image -build_binary_native_image: - # 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 --build-arg=GO_VERSION -t $(BINARY_NATIVE_IMAGE_NAME) - - -.PHONY: build_e2e_image -build_e2e_image: - docker build -t $(E2E_IMAGE_NAME) --build-arg=GO_VERSION --build-arg VERSION=$(VERSION) --build-arg GITCOMMIT=$(GITCOMMIT) -f ./dockerfiles/Dockerfile.e2e . - DOCKER_RUN_NAME_OPTION := $(if $(DOCKER_CLI_CONTAINER_NAME),--name $(DOCKER_CLI_CONTAINER_NAME),) DOCKER_RUN := docker run --rm $(ENVVARS) $(DOCKER_CLI_MOUNTS) $(DOCKER_RUN_NAME_OPTION) @@ -51,8 +40,11 @@ binary: build: binary ## alias for binary -plugins: build_binary_native_image ## build the CLI plugin examples - $(DOCKER_RUN) $(BINARY_NATIVE_IMAGE_NAME) ./scripts/build/plugins +plugins: ## build the CLI plugin examples + docker buildx bake plugins + +plugins-cross: ## build the CLI plugin examples for all platforms + docker buildx bake plugins-cross .PHONY: clean clean: build_docker_image ## clean build artifacts @@ -70,14 +62,6 @@ test: test-unit test-e2e cross: COMPANY_NAME=$(COMPANY_NAME) docker buildx bake cross -.PHONY: plugins-windows -plugins-windows: build_cross_image ## build the example CLI plugins for Windows - $(DOCKER_RUN) $(CROSS_IMAGE_NAME) make $@ - -.PHONY: plugins-osx -plugins-osx: build_cross_image ## build the example CLI plugins for macOS - $(DOCKER_RUN) $(CROSS_IMAGE_NAME) make $@ - .PHONY: dynbinary dynbinary: ## build dynamically linked binary USE_GLIBC=1 COMPANY_NAME=$(COMPANY_NAME) docker buildx bake dynbinary @@ -118,20 +102,24 @@ manpages: build_docker_image ## generate man pages from go source and markdown yamldocs: build_docker_image ## generate documentation YAML files consumed by docs repo $(DOCKER_RUN) -it $(DEV_DOCKER_IMAGE_NAME) make yamldocs +.PHONY: build-e2e-image +build-e2e-image: + IMAGE_NAME=$(E2E_IMAGE_NAME) VERSION=$(VERSION) docker buildx bake e2e-image + .PHONY: test-e2e test-e2e: test-e2e-non-experimental test-e2e-experimental test-e2e-connhelper-ssh ## run all e2e tests .PHONY: test-e2e-experimental -test-e2e-experimental: build_e2e_image # run experimental e2e tests - docker run --rm --mount type=bind,src=/var/run/docker.sock,dst=/var/run/docker.sock $(ENVVARS) -e DOCKERD_EXPERIMENTAL=1 $(E2E_IMAGE_NAME) +test-e2e-experimental: build-e2e-image # run experimental e2e tests + docker run --rm --mount type=bind,src=/var/run/docker.sock,dst=/var/run/docker.sock $(ENVVARS) -e DOCKERD_EXPERIMENTAL=1 -e TEST_ENGINE_VERSION=$(E2E_ENGINE_VERSION) $(E2E_IMAGE_NAME) .PHONY: test-e2e-non-experimental -test-e2e-non-experimental: build_e2e_image # run non-experimental e2e tests +test-e2e-non-experimental: build-e2e-image # run non-experimental e2e tests docker run --rm --mount type=bind,src=/var/run/docker.sock,dst=/var/run/docker.sock $(ENVVARS) -e TEST_ENGINE_VERSION=$(E2E_ENGINE_VERSION) $(E2E_IMAGE_NAME) .PHONY: test-e2e-connhelper-ssh -test-e2e-connhelper-ssh: build_e2e_image # run experimental SSH-connection helper e2e tests - docker run --rm --mount type=bind,src=/var/run/docker.sock,dst=/var/run/docker.sock $(ENVVARS) -e DOCKERD_EXPERIMENTAL=1 -e TEST_CONNHELPER=ssh $(E2E_IMAGE_NAME) +test-e2e-connhelper-ssh: build-e2e-image # run experimental SSH-connection helper e2e tests + docker run --rm --mount type=bind,src=/var/run/docker.sock,dst=/var/run/docker.sock $(ENVVARS) -e DOCKERD_EXPERIMENTAL=1 -e TEST_ENGINE_VERSION=$(E2E_ENGINE_VERSION) -e TEST_CONNHELPER=ssh $(E2E_IMAGE_NAME) .PHONY: help help: ## print this help diff --git a/dockerfiles/Dockerfile.binary-native b/dockerfiles/Dockerfile.binary-native deleted file mode 100644 index 9d47a91102..0000000000 --- a/dockerfiles/Dockerfile.binary-native +++ /dev/null @@ -1,10 +0,0 @@ -ARG GO_VERSION=1.16.10 - -FROM golang:${GO_VERSION}-alpine - -RUN apk add -U git bash coreutils gcc musl-dev - -ENV CGO_ENABLED=0 \ - DISABLE_WARN_OUTSIDE_CONTAINER=1 -WORKDIR /go/src/github.com/docker/cli -CMD ./scripts/build/binary diff --git a/dockerfiles/Dockerfile.e2e b/dockerfiles/Dockerfile.e2e deleted file mode 100644 index df7964c724..0000000000 --- a/dockerfiles/Dockerfile.e2e +++ /dev/null @@ -1,45 +0,0 @@ -ARG GO_VERSION=1.16.10 - -# Use Debian based image as docker-compose requires glibc. -FROM golang:${GO_VERSION}-buster - -RUN apt-get update && apt-get install -y \ - build-essential \ - curl \ - openssl \ - openssh-client \ - && rm -rf /var/lib/apt/lists/* - -ARG COMPOSE_VERSION=1.29.2 -RUN curl -fsSL https://github.com/docker/compose/releases/download/${COMPOSE_VERSION}/docker-compose-`uname -s`-`uname -m` -o /usr/local/bin/docker-compose \ - && chmod +x /usr/local/bin/docker-compose - -ARG NOTARY_VERSION=v0.6.1 -RUN curl -fsSL https://github.com/theupdateframework/notary/releases/download/${NOTARY_VERSION}/notary-Linux-amd64 -o /usr/local/bin/notary \ - && chmod +x /usr/local/bin/notary - -ARG GOTESTSUM_VERSION=1.7.0 -RUN curl -fsSL https://github.com/gotestyourself/gotestsum/releases/download/v${GOTESTSUM_VERSION}/gotestsum_${GOTESTSUM_VERSION}_linux_amd64.tar.gz -o gotestsum.tar.gz \ - && tar -xf gotestsum.tar.gz gotestsum \ - && mv gotestsum /usr/local/bin/gotestsum \ - && rm gotestsum.tar.gz - -ENV CGO_ENABLED=0 \ - DISABLE_WARN_OUTSIDE_CONTAINER=1 \ - PATH=/go/src/github.com/docker/cli/build:$PATH -WORKDIR /go/src/github.com/docker/cli - -# Trust notary CA cert. -COPY e2e/testdata/notary/root-ca.cert /usr/share/ca-certificates/notary.cert -RUN echo 'notary.cert' >> /etc/ca-certificates.conf && update-ca-certificates - -COPY . . -ARG VERSION -ARG GITCOMMIT -ENV VERSION=${VERSION} -ENV GITCOMMIT=${GITCOMMIT} -ENV DOCKER_BUILDKIT=1 -RUN ./scripts/build/binary -RUN ./scripts/build/plugins e2e/cli-plugins/plugins/* - -CMD ./scripts/test/e2e/entry diff --git a/scripts/build/.variables b/scripts/build/.variables index 9b7cad828b..abc28f906a 100755 --- a/scripts/build/.variables +++ b/scripts/build/.variables @@ -1,6 +1,12 @@ #!/usr/bin/env sh set -eu +: "${CGO_ENABLED=}" +: "${GO_LINKMODE=static}" +: "${GO_BUILDMODE=}" +: "${GO_BUILDTAGS=}" +: "${GO_STRIP=}" + TARGET=${TARGET:-"build"} PLATFORM=${PLATFORM:-} @@ -8,34 +14,68 @@ VERSION=${VERSION:-$(git describe --match 'v[0-9]*' --dirty='.m' --always --tags GITCOMMIT=${GITCOMMIT:-$(git rev-parse --short HEAD 2> /dev/null || true)} BUILDTIME=${BUILDTIME:-$(date -u --date="@${SOURCE_DATE_EPOCH:-$(date +%s)}" +"%Y-%m-%dT%H:%M:%SZ")} -PLATFORM_LDFLAGS= -if test -n "${PLATFORM}"; then - PLATFORM_LDFLAGS="-X \"github.com/docker/cli/cli/version.PlatformName=${PLATFORM}\"" -fi - -export LDFLAGS="\ - -w \ - ${PLATFORM_LDFLAGS} \ - -X \"github.com/docker/cli/cli/version.GitCommit=${GITCOMMIT}\" \ - -X \"github.com/docker/cli/cli/version.BuildTime=${BUILDTIME}\" \ - -X \"github.com/docker/cli/cli/version.Version=${VERSION}\" \ - ${LDFLAGS:-} \ -" - GOOS="$(go env GOOS)" GOARCH="$(go env GOARCH)" if [ "${GOARCH}" = "arm" ]; then - GOARM="$(go env GOARM)" + GOARM="$(go env GOARM)" fi TARGET="$TARGET/docker-${GOOS}-${GOARCH}" if [ "${GOARCH}" = "arm" ] && [ -n "${GOARM}" ]; then TARGET="${TARGET}-v${GOARM}" fi - if [ "${GOOS}" = "windows" ]; then - TARGET="${TARGET}.exe" + TARGET="${TARGET}.exe" fi export TARGET +if [ -z "$CGO_ENABLED" ]; then + case "$(go env GOOS)" in + linux) + case "$(go env GOARCH)" in + amd64|arm64|arm|s390x) + CGO_ENABLED=1 + ;; + *) + CGO_ENABLED=0 + ;; + esac + ;; + darwin|windows) + CGO_ENABLED=1 + ;; + *) + CGO_ENABLED=0 + ;; + esac +fi +export CGO_ENABLED + +if [ "$CGO_ENABLED" = "1" ] && [ "$(go env GOOS)" != "windows" ]; then + case "$(go env GOARCH)" in + mips*|ppc64) + # pie build mode is not supported on mips architectures + ;; + *) + GO_BUILDMODE="-buildmode=pie" + ;; + esac +fi +export GO_BUILDMODE + +LDFLAGS="${LDFLAGS:-} -w" +LDFLAGS="$LDFLAGS -X \"github.com/docker/cli/cli/version.GitCommit=${GITCOMMIT}\"" +LDFLAGS="$LDFLAGS -X \"github.com/docker/cli/cli/version.BuildTime=${BUILDTIME}\"" +LDFLAGS="$LDFLAGS -X \"github.com/docker/cli/cli/version.Version=${VERSION}\"" +if test -n "${PLATFORM}"; then + LDFLAGS="$LDFLAGS -X \"github.com/docker/cli/cli/version.PlatformName=${PLATFORM}\"" +fi +if [ "$CGO_ENABLED" = "1" ] && [ "$GO_LINKMODE" = "static" ] && [ "$(go env GOOS)" = "linux" ]; then + LDFLAGS="$LDFLAGS -extldflags -static" +fi +if [ -n "$GO_STRIP" ]; then + LDFLAGS="$LDFLAGS -s" +fi +export LDFLAGS="$LDFLAGS" # https://github.com/koalaman/shellcheck/issues/2064 + export SOURCE="github.com/docker/cli/cmd/docker" diff --git a/scripts/build/binary b/scripts/build/binary index e807878b67..8e3324cf2c 100755 --- a/scripts/build/binary +++ b/scripts/build/binary @@ -5,53 +5,10 @@ set -eu -: "${CGO_ENABLED=}" -: "${GO_LINKMODE=static}" -: "${GO_BUILDMODE=}" -: "${GO_BUILDTAGS=}" -: "${GO_STRIP=}" - . ./scripts/build/.variables -if [ -z "$CGO_ENABLED" ]; then - case "$(go env GOOS)" in - linux) - case "$(go env GOARCH)" in - amd64|arm64|arm|s390x) - CGO_ENABLED=1 - ;; - *) - CGO_ENABLED=0 - ;; - esac - ;; - darwin|windows) - CGO_ENABLED=1 - ;; - *) - CGO_ENABLED=0 - ;; - esac -fi -export CGO_ENABLED if [ "$CGO_ENABLED" = "1" ] && [ "$(go env GOOS)" != "windows" ]; then - case "$(go env GOARCH)" in - mips*|ppc64) - # pie build mode is not supported on mips architectures - ;; - *) - GO_BUILDMODE="-buildmode=pie" - ;; - esac - GO_BUILDTAGS="$GO_BUILDTAGS pkcs11" -fi - -if [ "$CGO_ENABLED" = "1" ] && [ "$GO_LINKMODE" = "static" ] && [ "$(go env GOOS)" = "linux" ]; then - LDFLAGS="$LDFLAGS -extldflags -static" -fi - -if [ -n "$GO_STRIP" ]; then - LDFLAGS="$LDFLAGS -s -w" + GO_BUILDTAGS="$GO_BUILDTAGS pkcs11" fi echo "Building $GO_LINKMODE $(basename "${TARGET}")" @@ -67,6 +24,6 @@ if [ "$(go env GOOS)" = "windows" ]; then fi fi -(set -x ; go build -o "${TARGET}" -tags "${GO_BUILDTAGS}" --ldflags "${LDFLAGS}" ${GO_BUILDMODE} "${SOURCE}") +(set -x ; go build -o "${TARGET}" -tags "${GO_BUILDTAGS}" -ldflags "${LDFLAGS}" ${GO_BUILDMODE} "${SOURCE}") ln -sf "$(basename "${TARGET}")" "$(dirname "${TARGET}")/docker" diff --git a/scripts/build/plugins b/scripts/build/plugins index f4e9c74600..10268f54ec 100755 --- a/scripts/build/plugins +++ b/scripts/build/plugins @@ -1,21 +1,19 @@ #!/usr/bin/env bash # -# Build a static binary for the host OS/ARCH +# Build plugins examples for the host OS/ARCH # set -eu -o pipefail source ./scripts/build/.variables -mkdir -p "build/plugins-${GOOS}-${GOARCH}" for p in cli-plugins/examples/* "$@" ; do [ -d "$p" ] || continue n=$(basename "$p") + TARGET_PLUGIN="$(dirname "${TARGET}")/plugins-${GOOS}-${GOARCH}/docker-${n}" + mkdir -p "$(dirname "${TARGET_PLUGIN}")" - TARGET="build/plugins-${GOOS}-${GOARCH}/docker-${n}" - - echo "Building statically linked $TARGET" - export CGO_ENABLED=0 - GO111MODULE=auto go build -o "${TARGET}" --ldflags "${LDFLAGS}" "github.com/docker/cli/${p}" + echo "Building $GO_LINKMODE $(basename "${TARGET_PLUGIN}")" + (set -x ; CGO_ENABLED=0 GO111MODULE=auto go build -o "${TARGET_PLUGIN}" -tags "${GO_BUILDTAGS}" -ldflags "${LDFLAGS}" ${GO_BUILDMODE} "github.com/docker/cli/${p}") done diff --git a/scripts/build/plugins-osx b/scripts/build/plugins-osx deleted file mode 100755 index 8e870f4f05..0000000000 --- a/scripts/build/plugins-osx +++ /dev/null @@ -1,18 +0,0 @@ -#!/usr/bin/env bash -# -# Build a static binary for the host OS/ARCH -# - -set -eu -o pipefail - -source ./scripts/build/.variables - -export CGO_ENABLED=1 -export GOOS=darwin -export GOARCH=amd64 -export CC=o64-clang -export CXX=o64-clang++ -export LDFLAGS="$LDFLAGS -linkmode external -s" -export LDFLAGS_STATIC_DOCKER='-extld='${CC} - -source ./scripts/build/plugins diff --git a/scripts/build/plugins-windows b/scripts/build/plugins-windows deleted file mode 100755 index 607ad6dc12..0000000000 --- a/scripts/build/plugins-windows +++ /dev/null @@ -1,14 +0,0 @@ -#!/usr/bin/env bash -# -# Build a static binary for the host OS/ARCH -# - -set -eu -o pipefail - -source ./scripts/build/.variables -export CC=x86_64-w64-mingw32-gcc -export CGO_ENABLED=1 -export GOOS=windows -export GOARCH=amd64 - -source ./scripts/build/plugins