github.com/pdmccormick/importable-docker-buildx@v0.0.0-20240426161518-e47091289030/Dockerfile (about)

     1  # syntax=docker/dockerfile:1
     2  
     3  ARG GO_VERSION=1.21
     4  ARG XX_VERSION=1.4.0
     5  
     6  # for testing
     7  ARG DOCKER_VERSION=26.0.0
     8  ARG GOTESTSUM_VERSION=v1.9.0
     9  ARG REGISTRY_VERSION=2.8.0
    10  ARG BUILDKIT_VERSION=v0.13.1
    11  ARG UNDOCK_VERSION=0.7.0
    12  
    13  FROM --platform=$BUILDPLATFORM tonistiigi/xx:${XX_VERSION} AS xx
    14  FROM --platform=$BUILDPLATFORM golang:${GO_VERSION}-alpine AS golatest
    15  FROM moby/moby-bin:$DOCKER_VERSION AS docker-engine
    16  FROM dockereng/cli-bin:$DOCKER_VERSION AS docker-cli
    17  FROM registry:$REGISTRY_VERSION AS registry
    18  FROM moby/buildkit:$BUILDKIT_VERSION AS buildkit
    19  FROM crazymax/undock:$UNDOCK_VERSION AS undock
    20  
    21  FROM golatest AS gobase
    22  COPY --from=xx / /
    23  RUN apk add --no-cache file git
    24  ENV GOFLAGS=-mod=vendor
    25  ENV CGO_ENABLED=0
    26  WORKDIR /src
    27  
    28  FROM gobase AS gotestsum
    29  ARG GOTESTSUM_VERSION
    30  ENV GOFLAGS=
    31  RUN --mount=target=/root/.cache,type=cache \
    32    GOBIN=/out/ go install "gotest.tools/gotestsum@${GOTESTSUM_VERSION}" && \
    33    /out/gotestsum --version
    34  
    35  FROM gobase AS buildx-version
    36  RUN --mount=type=bind,target=. <<EOT
    37    set -e
    38    mkdir /buildx-version
    39    echo -n "$(./hack/git-meta version)" | tee /buildx-version/version
    40    echo -n "$(./hack/git-meta revision)" | tee /buildx-version/revision
    41  EOT
    42  
    43  FROM gobase AS buildx-build
    44  ARG TARGETPLATFORM
    45  RUN --mount=type=bind,target=. \
    46    --mount=type=cache,target=/root/.cache \
    47    --mount=type=cache,target=/go/pkg/mod \
    48    --mount=type=bind,from=buildx-version,source=/buildx-version,target=/buildx-version <<EOT
    49    set -e
    50    xx-go --wrap
    51    DESTDIR=/usr/bin VERSION=$(cat /buildx-version/version) REVISION=$(cat /buildx-version/revision) GO_EXTRA_LDFLAGS="-s -w" ./hack/build
    52    xx-verify --static /usr/bin/docker-buildx
    53  EOT
    54  
    55  FROM gobase AS test
    56  ENV SKIP_INTEGRATION_TESTS=1
    57  RUN --mount=type=bind,target=. \
    58    --mount=type=cache,target=/root/.cache \
    59    --mount=type=cache,target=/go/pkg/mod \
    60    go test -v -coverprofile=/tmp/coverage.txt -covermode=atomic ./... && \
    61    go tool cover -func=/tmp/coverage.txt
    62  
    63  FROM scratch AS test-coverage
    64  COPY --from=test /tmp/coverage.txt /coverage.txt
    65  
    66  FROM scratch AS binaries-unix
    67  COPY --link --from=buildx-build /usr/bin/docker-buildx /buildx
    68  
    69  FROM binaries-unix AS binaries-darwin
    70  FROM binaries-unix AS binaries-linux
    71  
    72  FROM scratch AS binaries-windows
    73  COPY --link --from=buildx-build /usr/bin/docker-buildx /buildx.exe
    74  
    75  FROM binaries-$TARGETOS AS binaries
    76  # enable scanning for this stage
    77  ARG BUILDKIT_SBOM_SCAN_STAGE=true
    78  
    79  FROM gobase AS integration-test-base
    80  # https://github.com/docker/docker/blob/master/project/PACKAGERS.md#runtime-dependencies
    81  RUN apk add --no-cache \
    82        btrfs-progs \
    83        e2fsprogs \
    84        e2fsprogs-extra \
    85        ip6tables \
    86        iptables \
    87        openssl \
    88        shadow-uidmap \
    89        xfsprogs \
    90        xz
    91  COPY --link --from=gotestsum /out/gotestsum /usr/bin/
    92  COPY --link --from=registry /bin/registry /usr/bin/
    93  COPY --link --from=docker-engine / /usr/bin/
    94  COPY --link --from=docker-cli / /usr/bin/
    95  COPY --link --from=buildkit /usr/bin/buildkitd /usr/bin/
    96  COPY --link --from=buildkit /usr/bin/buildctl /usr/bin/
    97  COPY --link --from=undock /usr/local/bin/undock /usr/bin/
    98  COPY --link --from=binaries /buildx /usr/bin/
    99  
   100  FROM integration-test-base AS integration-test
   101  COPY . .
   102  
   103  # Release
   104  FROM --platform=$BUILDPLATFORM alpine AS releaser
   105  WORKDIR /work
   106  ARG TARGETPLATFORM
   107  RUN --mount=from=binaries \
   108    --mount=type=bind,from=buildx-version,source=/buildx-version,target=/buildx-version <<EOT
   109    set -e
   110    mkdir -p /out
   111    cp buildx* "/out/buildx-$(cat /buildx-version/version).$(echo $TARGETPLATFORM | sed 's/\//-/g')$(ls buildx* | sed -e 's/^buildx//')"
   112  EOT
   113  
   114  FROM scratch AS release
   115  COPY --from=releaser /out/ /
   116  
   117  # Shell
   118  FROM docker:$DOCKER_VERSION AS dockerd-release
   119  FROM alpine AS shell
   120  RUN apk add --no-cache iptables tmux git vim less openssh
   121  RUN mkdir -p /usr/local/lib/docker/cli-plugins && ln -s /usr/local/bin/buildx /usr/local/lib/docker/cli-plugins/docker-buildx
   122  COPY ./hack/demo-env/entrypoint.sh /usr/local/bin
   123  COPY ./hack/demo-env/tmux.conf /root/.tmux.conf
   124  COPY --from=dockerd-release /usr/local/bin /usr/local/bin
   125  WORKDIR /work
   126  COPY ./hack/demo-env/examples .
   127  COPY --from=binaries / /usr/local/bin/
   128  VOLUME /var/lib/docker
   129  ENTRYPOINT ["entrypoint.sh"]
   130  
   131  FROM binaries