From 1eb66d60bd8a76236b3f431ae7dacb128e53c1e8 Mon Sep 17 00:00:00 2001 From: Daniel Nephin Date: Thu, 15 Jun 2017 15:00:36 -0700 Subject: [PATCH] Add parallelism to cross build Reusable docker engine Signed-off-by: Daniel Nephin --- circle.yml | 49 +++++++++++++++++++++++++----------- dockerfiles/Dockerfile.cross | 18 +------------ dockerfiles/osx-cross.sh | 29 --------------------- scripts/build/cross | 21 +++++++++++++--- 4 files changed, 54 insertions(+), 63 deletions(-) delete mode 100755 dockerfiles/osx-cross.sh diff --git a/circle.yml b/circle.yml index 2035a25f54..4552ee6dd9 100644 --- a/circle.yml +++ b/circle.yml @@ -7,7 +7,9 @@ jobs: docker: [{image: 'docker:17.05-git'}] steps: - checkout - - setup_remote_docker + - setup_remote_docker: + reusable: true + exclusive: false - run: command: docker version - run: @@ -15,23 +17,32 @@ jobs: command: | dockerfile=dockerfiles/Dockerfile.lint echo "COPY . ." >> $dockerfile - docker build -f $dockerfile --tag cli-linter . - docker run cli-linter + docker build -f $dockerfile --tag cli-linter:$CIRCLE_BUILD_NUM . + docker run --rm cli-linter:$CIRCLE_BUILD_NUM cross: working_directory: /work docker: [{image: 'docker:17.05-git'}] + parallelism: 3 steps: - checkout - - setup_remote_docker + - setup_remote_docker: + reusable: true + exclusive: false - run: name: "Cross" command: | dockerfile=dockerfiles/Dockerfile.cross echo "COPY . ." >> $dockerfile - docker build -f $dockerfile --tag cli-builder . - docker run --name cross cli-builder make cross - docker cp cross:/go/src/github.com/docker/cli/build /work/build + docker build -f $dockerfile --tag cli-builder:$CIRCLE_BUILD_NUM . + name=cross-$CIRCLE_BUILD_NUM-$CIRCLE_NODE_INDEX + docker run \ + -e CROSS_GROUP=$CIRCLE_NODE_INDEX \ + --name $name cli-builder:$CIRCLE_BUILD_NUM \ + make cross + docker cp \ + $name:/go/src/github.com/docker/cli/build \ + /work/build - store_artifacts: path: /work/build @@ -40,19 +51,25 @@ jobs: docker: [{image: 'docker:17.05-git'}] steps: - checkout - - setup_remote_docker + - setup_remote_docker: + reusable: true + exclusive: false - run: name: "Unit Test with Coverage" command: | dockerfile=dockerfiles/Dockerfile.dev echo "COPY . ." >> $dockerfile - docker build -f $dockerfile --tag cli-builder . - docker run --name test cli-builder make test-coverage + docker build -f $dockerfile --tag cli-builder:$CIRCLE_BUILD_NUM . + docker run --name \ + test-$CIRCLE_BUILD_NUM cli-builder:$CIRCLE_BUILD_NUM \ + make test-coverage - run: name: "Upload to Codecov" command: | - docker cp test:/go/src/github.com/docker/cli/coverage.txt coverage.txt + docker cp \ + test-$CIRCLE_BUILD_NUM:/go/src/github.com/docker/cli/coverage.txt \ + coverage.txt apk add -U bash curl curl -s https://codecov.io/bash | bash @@ -60,16 +77,20 @@ jobs: working_directory: /work docker: [{image: 'docker:17.05-git'}] steps: + - run: apk add -U git openssh - checkout - - setup_remote_docker + - setup_remote_docker: + reusable: true + exclusive: false - 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 . - docker run cli-builder make -B vendor compose-jsonschema manpages yamldocs + docker build -f $dockerfile --tag cli-builder-with-git:$CIRCLE_BUILD_NUM . + docker run --rm cli-builder-with-git:$CIRCLE_BUILD_NUM \ + make -B vendor compose-jsonschema manpages yamldocs workflows: version: 2 diff --git a/dockerfiles/Dockerfile.cross b/dockerfiles/Dockerfile.cross index 19907ced49..60487dca90 100644 --- a/dockerfiles/Dockerfile.cross +++ b/dockerfiles/Dockerfile.cross @@ -1,18 +1,2 @@ - -FROM golang:1.8.3 - -# allow replacing httpredir or deb mirror -ARG APT_MIRROR=deb.debian.org -RUN sed -ri "s/(httpredir|deb).debian.org/$APT_MIRROR/g" /etc/apt/sources.list - -RUN apt-get update -qq && apt-get install -y -q \ - libltdl-dev \ - gcc-mingw-w64 \ - parallel \ - ; - -COPY dockerfiles/osx-cross.sh /tmp/ -RUN /tmp/osx-cross.sh -ENV PATH /osxcross/target/bin:$PATH - +FROM dockercore/golang-cross@sha256:d24e7affa3a85d460d2303c2549f03fc866f2b97d771ccf07b0e6e2b411dd207 WORKDIR /go/src/github.com/docker/cli diff --git a/dockerfiles/osx-cross.sh b/dockerfiles/osx-cross.sh deleted file mode 100755 index 840334a135..0000000000 --- a/dockerfiles/osx-cross.sh +++ /dev/null @@ -1,29 +0,0 @@ -#!/usr/bin/env bash -# -# Install dependencies required to cross compile osx, then cleanup -# -# TODO: this should be a separate build stage when CI supports it - - -set -eu -o pipefail - -PKG_DEPS="patch xz-utils clang" - -apt-get update -qq -apt-get install -y -q $PKG_DEPS - -OSX_SDK=MacOSX10.11.sdk -OSX_CROSS_COMMIT=a9317c18a3a457ca0a657f08cc4d0d43c6cf8953 -OSXCROSS_PATH="/osxcross" - -echo "Cloning osxcross" -time git clone https://github.com/tpoechtrager/osxcross.git $OSXCROSS_PATH -cd $OSXCROSS_PATH -git checkout -q $OSX_CROSS_COMMIT - -echo "Downloading OSX SDK" -time curl -sSL https://s3.dockerproject.org/darwin/v2/${OSX_SDK}.tar.xz \ - -o "${OSXCROSS_PATH}/tarballs/${OSX_SDK}.tar.xz" - -echo "Building osxcross" -UNATTENDED=yes OSX_VERSION_MIN=10.6 ${OSXCROSS_PATH}/build.sh > /dev/null diff --git a/scripts/build/cross b/scripts/build/cross index 9e7bfb35b8..39dcee4162 100755 --- a/scripts/build/cross +++ b/scripts/build/cross @@ -6,13 +6,28 @@ set -eu -o pipefail BUILDDIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" +export SHELL=bash -echo "Building binaries for all platforms" -SHELL=/bin/bash parallel ::: \ +jobs=( "$BUILDDIR/windows" \ "$BUILDDIR/osx" \ "GOOS=linux GOARCH=amd64 $BUILDDIR/binary" \ "GOOS=linux GOARCH=arm $BUILDDIR/binary" \ "GOOS=linux GOARCH=ppc64le $BUILDDIR/binary" \ "GOOS=linux GOARCH=s390x $BUILDDIR/binary" \ - ; +) + +# Outside of circleCI run all at once. On circleCI run two at a time because +# each continer has access to two cores. +group=${CROSS_GROUP-"all"} + +if [ "$group" == "all" ]; then + + echo "Building binaries for all platforms" + parallel ::: "${jobs[@]}" + exit 0 + +fi + +declare -i start=$group*2 +parallel ::: "${jobs[@]:$start:2}"