osx cross

Fix CI build

Signed-off-by: Daniel Nephin <dnephin@docker.com>
This commit is contained in:
Daniel Nephin 2017-05-12 12:07:57 -04:00
parent 84a77889c3
commit a408fb0a61
10 changed files with 77 additions and 43 deletions

View File

@ -15,26 +15,34 @@ jobs:
name: "Lint"
command: |
if [ "$CIRCLE_NODE_INDEX" != "0" ]; then exit; fi
docker build -f dockerfiles/Dockerfile.lint --tag cli-linter .
dockerfile=dockerfiles/Dockerfile.lint
echo "COPY . ." >> $dockerfile
docker build -f $dockerfile --tag cli-linter .
docker run cli-linter
- run:
name: "Cross"
command: |
if [ "$CIRCLE_NODE_INDEX" != "1" ]; then exit; fi
docker build -f dockerfiles/Dockerfile.ci --tag cli-builder .
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
- run:
name: "Unit Test"
command: |
if [ "$CIRCLE_NODE_INDEX" != "2" ]; then exit; fi
docker build -f dockerfiles/Dockerfile.ci --tag cli-builder .
dockerfile=dockerfiles/Dockerfile.dev
echo "COPY . ." >> $dockerfile
docker build -f $dockerfile --tag cli-builder .
docker run cli-builder make test
- run:
name: "Validate Vendor and Code Generation"
command: |
if [ "$CIRCLE_NODE_INDEX" != "3" ]; then exit; fi
docker build -f dockerfiles/Dockerfile.ci --tag cli-builder .
dockerfile=dockerfiles/Dockerfile.dev
echo "COPY . ." >> $dockerfile
docker build -f $dockerfile --tag cli-builder .
docker run cli-builder make -B vendor compose-jsonschema
- store_artifacts:

View File

@ -12,7 +12,7 @@ MOUNTS = -v `pwd`:/go/src/github.com/docker/cli
# build docker image (dockerfiles/Dockerfile.build)
.PHONY: build_docker_image
build_docker_image:
@docker build -q -t $(DEV_DOCKER_IMAGE_NAME) -f ./dockerfiles/Dockerfile.build .
@docker build -q -t $(DEV_DOCKER_IMAGE_NAME) -f ./dockerfiles/Dockerfile.dev .
# build docker image having the linting tools (dockerfiles/Dockerfile.lint)
.PHONY: build_linter_image
@ -25,10 +25,11 @@ build_cross_image:
# build executable using a container
.PHONY: build
build: build_docker_image
binary: build_docker_image
@echo "WARNING: this will drop a Linux executable on your host (not a macOS or Windows one)"
@docker run --rm $(MOUNTS) $(DEV_DOCKER_IMAGE_NAME) make build
@docker run --rm $(MOUNTS) $(DEV_DOCKER_IMAGE_NAME) make binary
build: binary
# clean build artifacts using a container
.PHONY: clean
@ -43,7 +44,7 @@ test: build_docker_image
# build the CLI for multiple architectures using a container
.PHONY: cross
cross: build_docker_image
@docker run --rm $(MOUNTS) $(DEV_DOCKER_IMAGE_NAME) make cross
@docker run --rm $(MOUNTS) $(CROSS_IMAGE_NAME) make cross
# start container in interactive mode for in-container development
.PHONY: dev

View File

@ -1,29 +0,0 @@
#
# This Dockerfile makes the docker builder run the tests.
# It means that if this Dockerfile can be built successfully,
# the tests passed.
#
# From the repo root dir:
# $ docker build -f dockerfiles/Dockerfile.ci .
#
FROM golang:1.8-alpine
RUN apk add -U git make
RUN go get github.com/LK4D4/vndr && \
cp /go/bin/vndr /usr/bin && \
rm -rf /go/src/* /go/pkg/* /go/bin/*
RUN go get github.com/mitchellh/gox && \
cp /go/bin/gox /usr/bin && \
rm -rf /go/src/* /go/pkg/* /go/bin/*
RUN go get github.com/jteeuwen/go-bindata/go-bindata && \
cp /go/bin/go-bindata /usr/bin && \
rm -rf /go/src/* /go/pkg/* /go/bin/*
COPY . /go/src/github.com/docker/cli
ENV CGO_ENABLED=0
WORKDIR /go/src/github.com/docker/cli

View File

@ -5,7 +5,7 @@ FROM golang:1.8.1
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 && apt-get install -y \
RUN apt-get update -qq && apt-get install -y -q \
libltdl-dev \
gcc-mingw-w64 \
parallel \
@ -15,4 +15,8 @@ RUN go get github.com/mitchellh/gox && \
cp /go/bin/gox /usr/bin && \
rm -rf /go/src/* /go/pkg/* /go/bin/*
COPY dockerfiles/osx-cross.sh /tmp/
RUN /tmp/osx-cross.sh
ENV PATH /osxcross/target/bin:$PATH
WORKDIR /go/src/github.com/docker/cli

View File

@ -1,7 +1,7 @@
FROM golang:1.8-alpine
RUN apk add -U git make bash
RUN apk add -U git make bash coreutils
RUN go get github.com/LK4D4/vndr && \
cp /go/bin/vndr /usr/bin && \

View File

@ -7,6 +7,5 @@ RUN go get -u gopkg.in/alecthomas/gometalinter.v1 && \
gometalinter --install
WORKDIR /go/src/github.com/docker/cli
COPY . .
ENTRYPOINT ["/usr/local/bin/gometalinter"]
CMD ["--config=gometalinter.json", "./..."]

29
dockerfiles/osx-cross.sh Executable file
View File

@ -0,0 +1,29 @@
#!/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 "Buidling osxcross"
UNATTENDED=yes OSX_VERSION_MIN=10.6 ${OSXCROSS_PATH}/build.sh > /dev/null

View File

@ -6,4 +6,6 @@ export BUILDDIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
SHELL=/bin/bash parallel ::: \
"$BUILDDIR/linux-cross" \
"$BUILDDIR/windows"
"$BUILDDIR/windows" \
"$BUILDDIR/osx" \
;

20
scripts/build/osx Executable file
View File

@ -0,0 +1,20 @@
#!/usr/bin/env bash
#
# Build an osx binary from linux
#
set -eu -o pipefail
source ./scripts/build/.variables
export CGO_ENABLED=1
export GOOS=darwin
export GOARCH=amd64
export CC=o64-clang
export LDFLAGS='-linkmode external -s'
export LDFLAGS_STATIC_DOCKER='-extld='${CC}
# Override TARGET
export TARGET="build/docker-$GOOS-$GOARCH"
go build -o "${TARGET}" -tags pkcs11 --ldflags "${LDFLAGS}" "${SOURCE}"

View File

@ -13,7 +13,7 @@ export GOOS=windows
export GOARCH=amd64
# Override TARGET
export TARGET="build/docker-windows-amd64"
export TARGET="build/docker-$GOOS-$GOARCH"
# TODO: -tags pkcs11
go build -o "${TARGET}" --ldflags "${LDFLAGS}" "${SOURCE}"