From 0487cc3ab79c7bf4fc13ee397201ee42f798aa56 Mon Sep 17 00:00:00 2001 From: Tonis Tiigi Date: Fri, 22 Mar 2019 16:23:09 -0700 Subject: [PATCH] hack: add Dockerfile and shell target Signed-off-by: Tonis Tiigi --- Dockerfile | 51 ++++++++++++++++++++++++++++++++++++- Makefile | 10 ++++++++ hack/demo-env/entrypoint.sh | 8 ++++++ hack/demo-env/tmux.conf | 1 + hack/shell | 12 +++++++++ 5 files changed, 81 insertions(+), 1 deletion(-) create mode 100644 Makefile create mode 100755 hack/demo-env/entrypoint.sh create mode 100644 hack/demo-env/tmux.conf create mode 100755 hack/shell diff --git a/Dockerfile b/Dockerfile index c3c78df4..ea356dc7 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1 +1,50 @@ -FROM alpine \ No newline at end of file +# syntax=docker/dockerfile:1.0-experimental + +ARG DOCKERD_VERSION=18.09 +ARG CLI_VERSION=19.03 + +FROM docker:$DOCKERD_VERSION AS dockerd-release + +# xgo is a helper for golang cross-compilation +FROM --platform=$BUILDPLATFORM tonistiigi/xx:golang@sha256:6f7d999551dd471b58f70716754290495690efa8421e0a1fcf18eb11d0c0a537 AS xgo + +FROM --platform=$BUILDPLATFORM golang:1.12-alpine AS gobase +COPY --from=xgo / / +RUN apk add --no-cache file +ENV GOFLAGS=-mod=vendor +WORKDIR /src + +FROM gobase AS buildx-version +RUN --mount=target=. \ + PKG=github.com/tonistiigi/buildx VERSION=$(git describe --match 'v[0-9]*' --dirty='.m' --always --tags) REVISION=$(git rev-parse HEAD)$(if ! git diff --no-ext-diff --quiet --exit-code; then echo .m; fi); \ + echo "-X ${PKG}/version.Version=${VERSION} -X ${PKG}/version.Revision=${REVISION} -X ${PKG}/version.Package=${PKG}" | tee /tmp/.ldflags; \ + echo -n "${VERSION}" | tee /tmp/.version; + +FROM gobase AS buildx-build +ENV CGO_ENABLED=0 +ARG TARGETPLATFORM +RUN --mount=target=. --mount=target=/root/.cache,type=cache \ + --mount=target=/go/pkg/mod,type=cache \ + --mount=source=/tmp/.ldflags,target=/tmp/.ldflags,from=buildx-version \ + set -x; go build -ldflags "$(cat /tmp/.ldflags)" -o /usr/bin/buildx ./cmd/buildx && \ + file /usr/bin/buildx && file /usr/bin/buildx | egrep "statically linked|Mach-O|Windows" + +FROM golang:1.12-alpine AS docker-cli-build +RUN apk add -U git bash coreutils gcc musl-dev +ENV CGO_ENABLED=0 +ARG REPO=github.com/docker/cli +ARG CLI_VERSION +WORKDIR /go/src/github.com/docker/cli +RUN git clone git://$REPO . && git checkout $BRANCH +RUN ./scripts/build/binary + +FROM alpine AS demo-env +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 +COPY ./hack/demo-env/entrypoint.sh /usr/local/bin +COPY ./hack/demo-env/tmux.conf /root/.tmux.conf +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=buildx-build /usr/bin/buildx /usr/local/bin/ +VOLUME /var/lib/docker +ENTRYPOINT ["entrypoint.sh"] diff --git a/Makefile b/Makefile new file mode 100644 index 00000000..303ddf36 --- /dev/null +++ b/Makefile @@ -0,0 +1,10 @@ +shell: + ./hack/shell + +lint: + ./hack/lint + +vendor: + ./hack/update-vendor + +.PHONY: vendor lint shell \ No newline at end of file diff --git a/hack/demo-env/entrypoint.sh b/hack/demo-env/entrypoint.sh new file mode 100755 index 00000000..e2effa50 --- /dev/null +++ b/hack/demo-env/entrypoint.sh @@ -0,0 +1,8 @@ +#!/bin/sh + +tmux new -s demo -d +tmux new-window 'dockerd -s overlay2 -D' +tmux new-window +tmux a -t demo + + diff --git a/hack/demo-env/tmux.conf b/hack/demo-env/tmux.conf new file mode 100644 index 00000000..c8a06058 --- /dev/null +++ b/hack/demo-env/tmux.conf @@ -0,0 +1 @@ +set -g mouse on \ No newline at end of file diff --git a/hack/shell b/hack/shell new file mode 100755 index 00000000..5fcd0bfa --- /dev/null +++ b/hack/shell @@ -0,0 +1,12 @@ +#!/usr/bin/env bash + +set -e + +function clean { + docker rmi $(cat $iidfile) +} + +iidfile=$(mktemp -t docker-iidfile.XXXXXXXXXX) +docker build --iidfile $iidfile --target demo-env . +trap clean EXIT +docker run -it --privileged --rm $(cat $iidfile) \ No newline at end of file