Merge pull request #40180 from cpuguy83/no_more_dev_tools
Build binaries with minimal deps and remove autogen code
This commit is contained in:
commit
550d5f9d43
6 changed files with 61 additions and 71 deletions
|
@ -1,6 +1,8 @@
|
|||
bundles
|
||||
.gopath
|
||||
vendor/pkg
|
||||
.go-pkg-cache
|
||||
.dockerignore
|
||||
.git
|
||||
.go-pkg-cache
|
||||
.gopath
|
||||
bundles
|
||||
Dockerfile
|
||||
vendor/pkg
|
||||
|
||||
|
|
2
.gitignore
vendored
2
.gitignore
vendored
|
@ -17,8 +17,6 @@ autogen/
|
|||
bundles/
|
||||
cmd/dockerd/dockerd
|
||||
contrib/builder/rpm/*/changelog
|
||||
dockerversion/version_autogen.go
|
||||
dockerversion/version_autogen_unix.go
|
||||
vendor/pkg/
|
||||
go-test-report.json
|
||||
profile.out
|
||||
|
|
56
Dockerfile
56
Dockerfile
|
@ -4,6 +4,7 @@ ARG CROSS="false"
|
|||
ARG GO_VERSION=1.13.4
|
||||
ARG DEBIAN_FRONTEND=noninteractive
|
||||
ARG VPNKIT_DIGEST=e508a17cfacc8fd39261d5b4e397df2b953690da577e2c987a47630cd0c42f8e
|
||||
ARG DOCKER_BUILDTAGS="apparmor seccomp selinux"
|
||||
|
||||
FROM golang:${GO_VERSION}-stretch AS base
|
||||
RUN echo 'Binary::apt::APT::Keep-Downloaded-Packages "true";' > /etc/apt/apt.conf.d/keep-cache
|
||||
|
@ -111,10 +112,16 @@ ARG DEBIAN_FRONTEND
|
|||
RUN --mount=type=cache,sharing=locked,id=moby-cross-false-aptlib,target=/var/lib/apt \
|
||||
--mount=type=cache,sharing=locked,id=moby-cross-false-aptcache,target=/var/cache/apt \
|
||||
apt-get update && apt-get install -y --no-install-recommends \
|
||||
binutils-mingw-w64 \
|
||||
btrfs-tools \
|
||||
g++-mingw-w64-x86-64 \
|
||||
libapparmor-dev \
|
||||
libseccomp-dev
|
||||
libdevmapper-dev \
|
||||
libseccomp-dev \
|
||||
libsystemd-dev \
|
||||
libudev-dev
|
||||
|
||||
FROM --platform=linux/amd64 cross-true AS runtime-dev-cross-true
|
||||
FROM --platform=linux/amd64 runtime-dev-cross-false AS runtime-dev-cross-true
|
||||
ARG DEBIAN_FRONTEND
|
||||
# These crossbuild packages rely on gcc-<arch>, but this doesn't want to install
|
||||
# on non-amd64 systems.
|
||||
|
@ -128,11 +135,7 @@ RUN --mount=type=cache,sharing=locked,id=moby-cross-true-aptlib,target=/var/lib/
|
|||
libapparmor-dev:armhf \
|
||||
libseccomp-dev:arm64 \
|
||||
libseccomp-dev:armel \
|
||||
libseccomp-dev:armhf \
|
||||
# install this arches seccomp here due to compat issues with the v0 builder
|
||||
# This is as opposed to inheriting from runtime-dev-cross-false
|
||||
libapparmor-dev \
|
||||
libseccomp-dev
|
||||
libseccomp-dev:armhf
|
||||
|
||||
FROM runtime-dev-cross-${CROSS} AS runtime-dev
|
||||
|
||||
|
@ -261,19 +264,13 @@ RUN --mount=type=cache,sharing=locked,id=moby-dev-aptlib,target=/var/lib/apt \
|
|||
apparmor \
|
||||
aufs-tools \
|
||||
bash-completion \
|
||||
binutils-mingw-w64 \
|
||||
btrfs-tools \
|
||||
bzip2 \
|
||||
g++-mingw-w64-x86-64 \
|
||||
iptables \
|
||||
jq \
|
||||
libcap2-bin \
|
||||
libdevmapper-dev \
|
||||
libnet1 \
|
||||
libnl-3-200 \
|
||||
libprotobuf-c1 \
|
||||
libsystemd-dev \
|
||||
libudev-dev \
|
||||
net-tools \
|
||||
pigz \
|
||||
python3-pip \
|
||||
|
@ -304,18 +301,15 @@ COPY --from=containerd /build/ /usr/local/bin/
|
|||
COPY --from=rootlesskit /build/ /usr/local/bin/
|
||||
COPY --from=vpnkit /vpnkit /usr/local/bin/vpnkit.x86_64
|
||||
COPY --from=proxy /build/ /usr/local/bin/
|
||||
|
||||
ENV PATH=/usr/local/cli:$PATH
|
||||
ENV DOCKER_BUILDTAGS apparmor seccomp selinux
|
||||
ARG DOCKER_BUILDTAGS
|
||||
ENV DOCKER_BUILDTAGS="${DOCKER_BUILDTAGS}"
|
||||
WORKDIR /go/src/github.com/docker/docker
|
||||
VOLUME /var/lib/docker
|
||||
# Wrap all commands in the "docker-in-docker" script to allow nested containers
|
||||
ENTRYPOINT ["hack/dind"]
|
||||
|
||||
FROM dev AS src
|
||||
COPY . /go/src/github.com/docker/docker
|
||||
|
||||
FROM src AS binary-base
|
||||
FROM runtime-dev AS binary-base
|
||||
ARG DOCKER_GITCOMMIT=HEAD
|
||||
ENV DOCKER_GITCOMMIT=${DOCKER_GITCOMMIT}
|
||||
ARG VERSION
|
||||
|
@ -326,27 +320,43 @@ ARG PRODUCT
|
|||
ENV PRODUCT=${PRODUCT}
|
||||
ARG DEFAULT_PRODUCT_LICENSE
|
||||
ENV DEFAULT_PRODUCT_LICENSE=${DEFAULT_PRODUCT_LICENSE}
|
||||
ARG DOCKER_BUILDTAGS
|
||||
ENV DOCKER_BUILDTAGS="${DOCKER_BUILDTAGS}"
|
||||
ENV PREFIX=/build
|
||||
# TODO: This is here because hack/make.sh binary copies these extras binaries
|
||||
# from $PATH into the bundles dir.
|
||||
# It would be nice to handle this in a different way.
|
||||
COPY --from=tini /build/ /usr/local/bin/
|
||||
COPY --from=runc /build/ /usr/local/bin/
|
||||
COPY --from=containerd /build/ /usr/local/bin/
|
||||
COPY --from=rootlesskit /build/ /usr/local/bin/
|
||||
COPY --from=proxy /build/ /usr/local/bin/
|
||||
WORKDIR /go/src/github.com/docker/docker
|
||||
|
||||
FROM binary-base AS build-binary
|
||||
RUN --mount=type=cache,target=/root/.cache/go-build \
|
||||
--mount=type=bind,target=/go/src/github.com/docker/docker \
|
||||
hack/make.sh binary
|
||||
|
||||
FROM binary-base AS build-dynbinary
|
||||
RUN --mount=type=cache,target=/root/.cache/go-build \
|
||||
--mount=type=bind,target=/go/src/github.com/docker/docker \
|
||||
hack/make.sh dynbinary
|
||||
|
||||
FROM binary-base AS build-cross
|
||||
ARG DOCKER_CROSSPLATFORMS
|
||||
RUN --mount=type=cache,target=/root/.cache/go-build \
|
||||
--mount=type=bind,target=/go/src/github.com/docker/docker \
|
||||
hack/make.sh cross
|
||||
|
||||
FROM scratch AS binary
|
||||
COPY --from=build-binary /go/src/github.com/docker/docker/bundles/ /
|
||||
COPY --from=build-binary /build/bundles/ /
|
||||
|
||||
FROM scratch AS dynbinary
|
||||
COPY --from=build-dynbinary /go/src/github.com/docker/docker/bundles/ /
|
||||
COPY --from=build-dynbinary /build/ /
|
||||
|
||||
FROM scratch AS cross
|
||||
COPY --from=build-cross /go/src/github.com/docker/docker/bundles/ /
|
||||
COPY --from=build-cross /build/ /
|
||||
|
||||
FROM src AS final
|
||||
FROM dev AS final
|
||||
COPY . /go/src/github.com/docker/docker
|
||||
|
|
|
@ -4,8 +4,8 @@
|
|||
package dockerversion // import "github.com/docker/docker/dockerversion"
|
||||
|
||||
// Default build-time variable for library-import.
|
||||
// This file is overridden on build with build-time information.
|
||||
const (
|
||||
// These variables are overridden on build with build-time information.
|
||||
var (
|
||||
GitCommit = "library-import"
|
||||
Version = "library-import"
|
||||
BuildTime = "library-import"
|
||||
|
|
15
hack/make.sh
15
hack/make.sh
|
@ -113,7 +113,7 @@ LDFLAGS_STATIC=''
|
|||
EXTLDFLAGS_STATIC='-static'
|
||||
# ORIG_BUILDFLAGS is necessary for the cross target which cannot always build
|
||||
# with options like -race.
|
||||
ORIG_BUILDFLAGS=( -tags "autogen netgo osusergo static_build $DOCKER_BUILDTAGS" -installsuffix netgo )
|
||||
ORIG_BUILDFLAGS=( -tags "netgo osusergo static_build $DOCKER_BUILDTAGS" -installsuffix netgo )
|
||||
# see https://github.com/golang/go/issues/9369#issuecomment-69864440 for why -installsuffix is necessary here
|
||||
|
||||
BUILDFLAGS=( ${BUILDFLAGS} "${ORIG_BUILDFLAGS[@]}" )
|
||||
|
@ -140,12 +140,17 @@ bundle() {
|
|||
}
|
||||
|
||||
main() {
|
||||
bundle_dir="bundles"
|
||||
if [ -n "${PREFIX}" ]; then
|
||||
bundle_dir="${PREFIX}/${bundle_dir}"
|
||||
fi
|
||||
|
||||
if [ -z "${KEEPBUNDLE-}" ]; then
|
||||
echo "Removing bundles/"
|
||||
rm -rf bundles/*
|
||||
echo "Removing ${bundle_dir}/"
|
||||
rm -rf "${bundle_dir}"/*
|
||||
echo
|
||||
fi
|
||||
mkdir -p bundles
|
||||
mkdir -p "${bundle_dir}"
|
||||
|
||||
if [ $# -lt 1 ]; then
|
||||
bundles=(${DEFAULT_BUNDLES[@]})
|
||||
|
@ -153,7 +158,7 @@ main() {
|
|||
bundles=($@)
|
||||
fi
|
||||
for bundle in ${bundles[@]}; do
|
||||
export DEST="bundles/$(basename "$bundle")"
|
||||
export DEST="${bundle_dir}/$(basename "$bundle")"
|
||||
# Cygdrive paths don't play well with go build -o.
|
||||
if [[ "$(uname -s)" == CYGWIN* ]]; then
|
||||
export DEST="$(cygpath -mw "$DEST")"
|
||||
|
|
|
@ -6,41 +6,16 @@ source hack/dockerfile/install/runc.installer
|
|||
source hack/dockerfile/install/tini.installer
|
||||
source hack/dockerfile/install/containerd.installer
|
||||
|
||||
cat > dockerversion/version_autogen.go <<DVEOF
|
||||
// +build autogen
|
||||
|
||||
// Package dockerversion is auto-generated at build-time
|
||||
package dockerversion
|
||||
|
||||
// Default build-time variable for library-import.
|
||||
// This file is overridden on build with build-time information.
|
||||
const (
|
||||
GitCommit string = "$GITCOMMIT"
|
||||
Version string = "$VERSION"
|
||||
BuildTime string = "$BUILDTIME"
|
||||
IAmStatic string = "${IAMSTATIC:-true}"
|
||||
PlatformName string = "${PLATFORM}"
|
||||
ProductName string = "${PRODUCT}"
|
||||
DefaultProductLicense string = "${DEFAULT_PRODUCT_LICENSE}"
|
||||
)
|
||||
|
||||
// Code generated by hack/make/.go-autogen. DO NOT EDIT.
|
||||
DVEOF
|
||||
|
||||
cat > dockerversion/version_autogen_unix.go <<DVEOF
|
||||
// +build autogen,!windows
|
||||
|
||||
// Package dockerversion is auto-generated at build-time
|
||||
package dockerversion
|
||||
|
||||
// Default build-time variable for library-import.
|
||||
// This file is overridden on build with build-time information.
|
||||
const (
|
||||
InitCommitID string = "${TINI_COMMIT}"
|
||||
)
|
||||
|
||||
// Code generated by hack/make/.go-autogen. DO NOT EDIT.
|
||||
DVEOF
|
||||
LDFLAGS="${LDFALGS} \
|
||||
-X github.com/docker/docker/dockerversion.Version=${VERSION} \
|
||||
-X github.com/docker/docker/dockerversion.GitCommit=${GITCOMMIT} \
|
||||
-X github.com/docker/docker/dockerversion.BuildTime=${BUILDTIME} \
|
||||
-X github.com/docker/docker/dockerversion.IAmStatic=${IAMSTATIC:-true} \
|
||||
-X github.com/docker/docker/dockerversion.PlatformName=${PLATFORM} \
|
||||
-X github.com/docker/docker/dockerversion.ProductName=${PRODUCT} \
|
||||
-X github.com/docker/docker/dockerversion.DefaultProductLicense=${DEFAULT_PRODUCT_LICENSE} \
|
||||
-X github.com/docker/docker/dockerversion.InitCommitID=${TINI_COMMIT} \
|
||||
"
|
||||
|
||||
# Compile the Windows resources into the sources
|
||||
if [ "$(go env GOOS)" = "windows" ]; then
|
||||
|
|
Loading…
Reference in a new issue