hack: add binaries target

Signed-off-by: Tonis Tiigi <tonistiigi@gmail.com>
This commit is contained in:
Tonis Tiigi 2019-03-22 17:21:05 -07:00
parent 0487cc3ab7
commit 57857f09e1
5 changed files with 84 additions and 2 deletions

1
.gitignore vendored Normal file
View File

@ -0,0 +1 @@
bin

View File

@ -38,6 +38,17 @@ WORKDIR /go/src/github.com/docker/cli
RUN git clone git://$REPO . && git checkout $BRANCH RUN git clone git://$REPO . && git checkout $BRANCH
RUN ./scripts/build/binary RUN ./scripts/build/binary
FROM scratch AS binaries-unix
COPY --from=buildx-build /usr/bin/buildx /
FROM binaries-unix AS binaries-darwin
FROM binaries-unix AS binaries-linux
FROM scratch AS binaries-windows
COPY --from=buildx-build /usr/bin/buildx /buildx.exe
FROM binaries-$TARGETOS AS binaries
FROM alpine AS demo-env FROM alpine AS demo-env
RUN apk add --no-cache iptables tmux RUN apk add --no-cache iptables tmux
RUN mkdir -p /usr/local/lib/docker/cli-plugins && ln -s /usr/local/bin/buildx /usr/local/lib/docker/cli-plugins/docker-buildx RUN mkdir -p /usr/local/lib/docker/cli-plugins && ln -s /usr/local/bin/buildx /usr/local/lib/docker/cli-plugins/docker-buildx
@ -45,6 +56,6 @@ COPY ./hack/demo-env/entrypoint.sh /usr/local/bin
COPY ./hack/demo-env/tmux.conf /root/.tmux.conf COPY ./hack/demo-env/tmux.conf /root/.tmux.conf
COPY --from=dockerd-release /usr/local/bin /usr/local/bin COPY --from=dockerd-release /usr/local/bin /usr/local/bin
COPY --from=docker-cli-build /go/src/github.com/docker/cli/build/docker /usr/local/bin COPY --from=docker-cli-build /go/src/github.com/docker/cli/build/docker /usr/local/bin
COPY --from=buildx-build /usr/bin/buildx /usr/local/bin/ COPY --from=binaries / /usr/local/bin/
VOLUME /var/lib/docker VOLUME /var/lib/docker
ENTRYPOINT ["entrypoint.sh"] ENTRYPOINT ["entrypoint.sh"]

View File

@ -1,10 +1,13 @@
shell: shell:
./hack/shell ./hack/shell
binaries:
./hack/binaries
lint: lint:
./hack/lint ./hack/lint
vendor: vendor:
./hack/update-vendor ./hack/update-vendor
.PHONY: vendor lint shell .PHONY: vendor lint shell binaries

56
hack/binaries Executable file
View File

@ -0,0 +1,56 @@
#!/usr/bin/env bash
. $(dirname $0)/util
: ${TARGETPLATFORM=$CLI_PLATFORM}
: ${CONTINUOUS_INTEGRATION=}
set -ex
progressFlag=""
if [ "$CONTINUOUS_INTEGRATION" == "true" ]; then progressFlag="--progress=plain"; fi
binariesDocker() {
mkdir -p bin/tmp
export DOCKER_BUILDKIT=1
iidfile=$(mktemp -t docker-iidfile.XXXXXXXXXX)
platformFlag=""
if [ -n "$TARGETPLATFORM" ]; then
platformFlag="--build-arg=TARGETPLATFORM=$TARGETPLATFORM"
fi
docker build $platformFlag --target=binaries --iidfile $iidfile --force-rm .
iid=$(cat $iidfile)
containerID=$(docker create $iid copy)
docker cp $containerID:/ bin/tmp
mv bin/tmp/build* bin/
rm -rf bin/tmp
docker rm $containerID
docker rmi -f $iid
rm -f $iidfile
}
binaries() {
platformFlag=""
if [ ! -z "$TARGETPLATFORM" ]; then
platformFlag="--frontend-opt=platform=$TARGETPLATFORM"
fi
buildctl build $progressFlag --frontend=dockerfile.v0 \
--local context=. --local dockerfile=. \
--frontend-opt target=binaries $platformFlag \
--output type=local,dest=./bin/
}
case $buildmode in
"buildkit")
binaries
;;
"docker-buildkit")
binariesDocker
;;
*)
echo "buildctl or docker with buildkit support is required"
exit 1
;;
esac

View File

@ -2,6 +2,7 @@
: ${PREFER_BUILDCTL=} : ${PREFER_BUILDCTL=}
: ${PREFER_LEGACY=} : ${PREFER_LEGACY=}
: ${CLI_PLATFORM=}
newerEqualThan() { # $1=minimum wanted version $2=actual-version newerEqualThan() { # $1=minimum wanted version $2=actual-version
[ "$1" = "$(printf "$1\n$2" | sort -V | head -n 1)" ] [ "$1" = "$(printf "$1\n$2" | sort -V | head -n 1)" ]
@ -19,3 +20,13 @@ else
buildmode="docker-buildkit"; buildmode="docker-buildkit";
fi fi
fi fi
if [ -z "$CLI_PLATFORM" ]; then
rawos=$(uname -s)
if [ "$rawos" = "Darwin" ]; then
CLI_PLATFORM="darwin/amd64"
elif uname -s | grep MINGW 2>&1 >/dev/null ; then
CLI_PLATFORM="windows/amd64"
fi
fi