github.com/afbjorklund/moby@v20.10.5+incompatible/hack/make.sh (about) 1 #!/usr/bin/env bash 2 set -e 3 4 # This script builds various binary artifacts from a checkout of the docker 5 # source code. 6 # 7 # Requirements: 8 # - The current directory should be a checkout of the docker source code 9 # (https://github.com/docker/docker). Whatever version is checked out 10 # will be built. 11 # - The VERSION file, at the root of the repository, should exist, and 12 # will be used as Docker binary version and package version. 13 # - The hash of the git commit will also be included in the Docker binary, 14 # with the suffix -unsupported if the repository isn't clean. 15 # - The script is intended to be run inside the docker container specified 16 # in the Dockerfile at the root of the source. In other words: 17 # DO NOT CALL THIS SCRIPT DIRECTLY. 18 # - The right way to call this script is to invoke "make" from 19 # your checkout of the Docker repository. 20 # the Makefile will do a "docker build -t docker ." and then 21 # "docker run hack/make.sh" in the resulting image. 22 # 23 24 set -o pipefail 25 26 export DOCKER_PKG='github.com/docker/docker' 27 export SCRIPTDIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" 28 export MAKEDIR="$SCRIPTDIR/make" 29 export PKG_CONFIG=${PKG_CONFIG:-pkg-config} 30 31 echo 32 33 # List of bundles to create when no argument is passed 34 DEFAULT_BUNDLES=( 35 binary-daemon 36 dynbinary 37 test-integration 38 test-docker-py 39 cross 40 ) 41 42 VERSION=${VERSION:-dev} 43 ! BUILDTIME=$(date -u -d "@${SOURCE_DATE_EPOCH:-$(date +%s)}" --rfc-3339 ns 2> /dev/null | sed -e 's/ /T/') 44 if [ "$DOCKER_GITCOMMIT" ]; then 45 GITCOMMIT="$DOCKER_GITCOMMIT" 46 elif command -v git &> /dev/null && [ -e .git ] && git rev-parse &> /dev/null; then 47 GITCOMMIT=$(git rev-parse --short HEAD) 48 if [ -n "$(git status --porcelain --untracked-files=no)" ]; then 49 GITCOMMIT="$GITCOMMIT-unsupported" 50 echo "#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~" 51 echo "# GITCOMMIT = $GITCOMMIT" 52 echo "# The version you are building is listed as unsupported because" 53 echo "# there are some files in the git repository that are in an uncommitted state." 54 echo "# Commit these changes, or add to .gitignore to remove the -unsupported from the version." 55 echo "# Here is the current list:" 56 git status --porcelain --untracked-files=no 57 echo "#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~" 58 fi 59 else 60 echo >&2 'error: .git directory missing and DOCKER_GITCOMMIT not specified' 61 echo >&2 ' Please either build with the .git directory accessible, or specify the' 62 echo >&2 ' exact (--short) commit hash you are building using DOCKER_GITCOMMIT for' 63 echo >&2 ' future accountability in diagnosing build issues. Thanks!' 64 exit 1 65 fi 66 67 if [ "$AUTO_GOPATH" ]; then 68 rm -rf .gopath 69 mkdir -p .gopath/src/"$(dirname "${DOCKER_PKG}")" 70 ln -sf ../../../.. .gopath/src/"${DOCKER_PKG}" 71 export GOPATH="${PWD}/.gopath" 72 fi 73 74 if [ ! "$GOPATH" ]; then 75 echo >&2 'error: missing GOPATH; please see https://golang.org/doc/code.html#GOPATH' 76 echo >&2 ' alternatively, set AUTO_GOPATH=1' 77 exit 1 78 fi 79 80 # Adds $1_$2 to DOCKER_BUILDTAGS unless it already 81 # contains a word starting from $1_ 82 add_buildtag() { 83 [[ " $DOCKER_BUILDTAGS" == *" $1_"* ]] || DOCKER_BUILDTAGS+=" $1_$2" 84 } 85 86 if ${PKG_CONFIG} 'libsystemd >= 209' 2> /dev/null; then 87 DOCKER_BUILDTAGS+=" journald" 88 elif ${PKG_CONFIG} 'libsystemd-journal' 2> /dev/null; then 89 DOCKER_BUILDTAGS+=" journald journald_compat" 90 fi 91 92 # test whether "libdevmapper.h" is new enough to support deferred remove 93 # functionality. We favour libdm_dlsym_deferred_remove over 94 # libdm_no_deferred_remove in dynamic cases because the binary could be shipped 95 # with a newer libdevmapper than the one it was built with. 96 if 97 command -v gcc &> /dev/null \ 98 && ! (echo -e '#include <libdevmapper.h>\nint main() { dm_task_deferred_remove(NULL); }' | gcc -xc - -o /dev/null $(pkg-config --libs devmapper) &> /dev/null) \ 99 ; 100 then 101 add_buildtag libdm dlsym_deferred_remove 102 fi 103 104 # Use these flags when compiling the tests and final binary 105 106 IAMSTATIC='true' 107 if [ -z "$DOCKER_DEBUG" ]; then 108 LDFLAGS='-w' 109 fi 110 111 LDFLAGS_STATIC='' 112 EXTLDFLAGS_STATIC='-static' 113 # ORIG_BUILDFLAGS is necessary for the cross target which cannot always build 114 # with options like -race. 115 ORIG_BUILDFLAGS=(-tags "netgo osusergo static_build $DOCKER_BUILDTAGS" -installsuffix netgo) 116 # see https://github.com/golang/go/issues/9369#issuecomment-69864440 for why -installsuffix is necessary here 117 118 BUILDFLAGS=(${BUILDFLAGS} "${ORIG_BUILDFLAGS[@]}") 119 120 LDFLAGS_STATIC_DOCKER=" 121 $LDFLAGS_STATIC 122 -extldflags \"$EXTLDFLAGS_STATIC\" 123 " 124 125 if [ "$(uname -s)" = 'FreeBSD' ]; then 126 # Tell cgo the compiler is Clang, not GCC 127 # https://code.google.com/p/go/source/browse/src/cmd/cgo/gcc.go?spec=svne77e74371f2340ee08622ce602e9f7b15f29d8d3&r=e6794866ebeba2bf8818b9261b54e2eef1c9e588#752 128 export CC=clang 129 130 # "-extld clang" is a workaround for 131 # https://code.google.com/p/go/issues/detail?id=6845 132 LDFLAGS="$LDFLAGS -extld clang" 133 fi 134 135 bundle() { 136 local bundle="$1" 137 shift 138 echo "---> Making bundle: $(basename "$bundle") (in $DEST)" 139 source "$SCRIPTDIR/make/$bundle" "$@" 140 } 141 142 main() { 143 bundle_dir="bundles" 144 if [ -n "${PREFIX}" ]; then 145 bundle_dir="${PREFIX}/${bundle_dir}" 146 fi 147 148 if [ -z "${KEEPBUNDLE-}" ]; then 149 echo "Removing ${bundle_dir}/" 150 rm -rf "${bundle_dir}"/* 151 echo 152 fi 153 mkdir -p "${bundle_dir}" 154 155 if [ $# -lt 1 ]; then 156 bundles=(${DEFAULT_BUNDLES[@]}) 157 else 158 bundles=($@) 159 fi 160 for bundle in ${bundles[@]}; do 161 export DEST="${bundle_dir}/$(basename "$bundle")" 162 # Cygdrive paths don't play well with go build -o. 163 if [[ "$(uname -s)" == CYGWIN* ]]; then 164 export DEST="$(cygpath -mw "$DEST")" 165 fi 166 mkdir -p "$DEST" 167 ABS_DEST="$(cd "$DEST" && pwd -P)" 168 bundle "$bundle" 169 echo 170 done 171 } 172 173 main "$@"