From d9f4352c2643ee339611094656e14d398fe1636d Mon Sep 17 00:00:00 2001 From: CrazyMax Date: Sun, 26 Sep 2021 18:01:38 +0200 Subject: [PATCH] GitHub Actions cross Signed-off-by: CrazyMax --- .circleci/config.yml | 31 --------------------- .github/workflows/build.yml | 50 ++++++++++++++++++++++++++++++++++ Makefile | 25 +++++++++-------- README.md | 53 +++++++++++++++++++----------------- docker-bake.hcl | 26 +++--------------- docker.Makefile | 21 ++++++++++---- dockerfiles/Dockerfile.cross | 6 ---- 7 files changed, 111 insertions(+), 101 deletions(-) create mode 100644 .github/workflows/build.yml delete mode 100644 dockerfiles/Dockerfile.cross diff --git a/.circleci/config.yml b/.circleci/config.yml index 3e3fa75cdb..1076620916 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -2,36 +2,6 @@ version: 2 jobs: - cross: - working_directory: /work - docker: [{image: 'docker:20.10-git'}] - environment: - DOCKER_BUILDKIT: 1 - BUILDX_VERSION: "v0.6.0" - parallelism: 3 - steps: - - checkout - - setup_remote_docker: - version: 20.10.6 - reusable: true - exclusive: false - - run: - name: "Docker version" - command: docker version - - run: - name: "Docker info" - command: docker info - - run: apk add make curl - - run: mkdir -vp ~/.docker/cli-plugins/ - - run: curl -fsSL --output ~/.docker/cli-plugins/docker-buildx https://github.com/docker/buildx/releases/download/${BUILDX_VERSION}/buildx-${BUILDX_VERSION}.linux-amd64 - - run: chmod a+x ~/.docker/cli-plugins/docker-buildx - - run: docker buildx version - - run: docker context create buildctx - - run: docker buildx create --use buildctx && docker buildx inspect --bootstrap - - run: GROUP_INDEX=$CIRCLE_NODE_INDEX GROUP_TOTAL=$CIRCLE_NODE_TOTAL docker buildx bake cross --progress=plain - - store_artifacts: - path: /work/build - test: working_directory: /work docker: [{image: 'docker:20.10-git'}] @@ -112,6 +82,5 @@ workflows: version: 2 ci: jobs: - - cross - test - validate diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml new file mode 100644 index 0000000000..a2f6278d04 --- /dev/null +++ b/.github/workflows/build.yml @@ -0,0 +1,50 @@ +name: build + +on: + workflow_dispatch: + push: + branches: + - 'master' + - '[0-9]+.[0-9]{2}' + tags: + - 'v*' + pull_request: + +jobs: + build: + runs-on: ubuntu-latest + strategy: + fail-fast: false + matrix: + target: + - cross + - dynbinary-cross + steps: + - + name: Checkout + uses: actions/checkout@v2 + - + name: Set up Docker Buildx + uses: docker/setup-buildx-action@v1 + - + name: Run ${{ matrix.target }} + uses: docker/bake-action@v1 + with: + targets: ${{ matrix.target }} + - + name: Flatten artifacts + working-directory: ./build + run: | + for dir in */; do + base=$(basename "$dir") + echo "Creating ${base}.tar.gz ..." + tar -cvzf "${base}.tar.gz" "$dir" + rm -rf "$dir" + done + - + name: Upload artifacts + uses: actions/upload-artifact@v2 + with: + name: ${{ matrix.target }} + path: ./build/* + if-no-files-found: error diff --git a/Makefile b/Makefile index b6c351120d..e476f21af9 100644 --- a/Makefile +++ b/Makefile @@ -3,7 +3,6 @@ # all: binary - _:=$(shell ./scripts/warn-outside-container $(MAKECMDGOALS)) .PHONY: clean @@ -21,22 +20,30 @@ test: test-unit ## run tests test-coverage: ## run test coverage gotestsum -- -coverprofile=coverage.txt $(shell go list ./... | grep -vE '/vendor/|/e2e/') +.PHONY: lint +lint: ## run all the lint tools + golangci-lint run + +.PHONY: shellcheck +shellcheck: ## run shellcheck validation + find scripts/ contrib/completion/bash -type f | grep -v scripts/winresources | grep -v '.*.ps1' | xargs shellcheck + .PHONY: fmt fmt: go list -f {{.Dir}} ./... | xargs gofmt -w -s -d .PHONY: binary -binary: - docker buildx bake binary +binary: ## build executable for Linux + ./scripts/build/binary + +.PHONY: dynbinary +dynbinary: ## build dynamically linked binary + GO_LINKMODE=dynamic ./scripts/build/binary .PHONY: plugins plugins: ## build example CLI plugins ./scripts/build/plugins -.PHONY: cross -cross: - docker buildx bake cross - .PHONY: plugins-windows plugins-windows: ## build example CLI plugins for Windows ./scripts/build/plugins-windows @@ -45,10 +52,6 @@ plugins-windows: ## build example CLI plugins for Windows plugins-osx: ## build example CLI plugins for macOS ./scripts/build/plugins-osx -.PHONY: dynbinary -dynbinary: ## build dynamically linked binary - USE_GLIBC=1 docker buildx bake dynbinary - 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 770d68c1db..4adf3d14f1 100644 --- a/README.md +++ b/README.md @@ -1,64 +1,67 @@ -[![build status](https://circleci.com/gh/docker/cli.svg?style=shield)](https://circleci.com/gh/docker/cli/tree/master) -[![Build Status](https://ci.docker.com/public/job/cli/job/master/badge/icon)](https://ci.docker.com/public/job/cli/job/master) +# Docker CLI -docker/cli -========== +[![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) + +## About This repository is the home of the cli used in the Docker CE and Docker EE products. -Development -=========== +## Development `docker/cli` is developed using Docker. Build CLI from source: -``` -$ docker buildx bake +```shell +docker buildx bake ``` Build binaries for all supported platforms: -``` -$ docker buildx bake cross +```shell +docker buildx bake cross ``` Build for a specific platform: -``` -$ docker buildx bake --set binary.platform=linux/arm64 +```shell +docker buildx bake --set binary.platform=linux/arm64 ``` Build dynamic binary for glibc or musl: +```shell +USE_GLIBC=1 docker buildx bake dynbinary ``` -$ USE_GLIBC=1 docker buildx bake dynbinary -``` - Run all linting: -``` -$ make -f docker.Makefile lint +```shell +docker buildx bake lint shellcheck ``` List all the available targets: -``` -$ make help +```shell +make help ``` ### In-container development environment Start an interactive development environment: -``` -$ make -f docker.Makefile shell +```shell +make -f docker.Makefile shell ``` -Legal -===== +## Legal + *Brought to you courtesy of our legal counsel. For more context, please see the [NOTICE](https://github.com/docker/cli/blob/master/NOTICE) document in this repo.* @@ -70,8 +73,8 @@ violate applicable laws. For more information, please see https://www.bis.doc.gov -Licensing -========= +## Licensing + docker/cli is licensed under the Apache License, Version 2.0. See [LICENSE](https://github.com/docker/docker/blob/master/LICENSE) for the full license text. diff --git a/docker-bake.hcl b/docker-bake.hcl index 08662a4c31..59598dfe69 100644 --- a/docker-bake.hcl +++ b/docker-bake.hcl @@ -32,34 +32,16 @@ target "dynbinary" { } } -variable "GROUP_TOTAL" { - default = "1" -} - -variable "GROUP_INDEX" { - default = "0" -} - -function "platforms" { - params = [USE_GLIBC] - result = 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"]) -} - -function "glen" { - params = [platforms, GROUP_TOTAL] - result = ceil(length(platforms)/GROUP_TOTAL) -} - -target "_all_platforms" { - platforms = slice(platforms(USE_GLIBC), GROUP_INDEX*glen(platforms(USE_GLIBC), GROUP_TOTAL),min(length(platforms(USE_GLIBC)), (GROUP_INDEX+1)*glen(platforms(USE_GLIBC), GROUP_TOTAL))) +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"]) } target "cross" { - inherits = ["binary", "_all_platforms"] + inherits = ["binary", "platforms"] } target "dynbinary-cross" { - inherits = ["dynbinary", "_all_platforms"] + inherits = ["dynbinary", "platforms"] } target "lint" { diff --git a/docker.Makefile b/docker.Makefile index 324f788d92..11b675a603 100644 --- a/docker.Makefile +++ b/docker.Makefile @@ -42,8 +42,9 @@ build_e2e_image: 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) -binary: build_binary_native_image ## build the CLI - $(DOCKER_RUN) $(BINARY_NATIVE_IMAGE_NAME) +.PHONY: binary +binary: + docker buildx bake binary build: binary ## alias for binary @@ -62,6 +63,10 @@ test-unit: build_docker_image ## run unit tests (using go test) .PHONY: test ## run unit and e2e tests test: test-unit test-e2e +.PHONY: cross +cross: + 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 $@ @@ -70,6 +75,10 @@ plugins-windows: build_cross_image ## build the example CLI plugins for Windows 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 docker buildx bake dynbinary + .PHONY: dev dev: build_docker_image ## start a build container in interactive mode for in-container development $(DOCKER_RUN) -it \ @@ -82,6 +91,10 @@ shell: dev ## alias for dev lint: ## run linters docker buildx bake lint +.PHONY: shellcheck +shellcheck: ## run shellcheck validation + docker buildx bake shellcheck + .PHONY: fmt fmt: ## run gofmt $(DOCKER_RUN) $(DEV_DOCKER_IMAGE_NAME) make fmt @@ -102,10 +115,6 @@ 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: shellcheck -shellcheck: ## run shellcheck validation - docker buildx bake shellcheck - .PHONY: test-e2e test-e2e: test-e2e-non-experimental test-e2e-experimental test-e2e-connhelper-ssh ## run all e2e tests diff --git a/dockerfiles/Dockerfile.cross b/dockerfiles/Dockerfile.cross deleted file mode 100644 index 8596a886d5..0000000000 --- a/dockerfiles/Dockerfile.cross +++ /dev/null @@ -1,6 +0,0 @@ -ARG GO_VERSION=1.13.15 - -FROM dockercore/golang-cross:${GO_VERSION} -ENV DISABLE_WARN_OUTSIDE_CONTAINER=1 -WORKDIR /go/src/github.com/docker/cli -COPY . .