github.com/ssdev-go/moby@v17.12.1-ce-rc2+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 # We're a nice, sexy, little shell script, and people might try to run us; 32 # but really, they shouldn't. We want to be in a container! 33 inContainer="AssumeSoInitially" 34 if [ "$(go env GOHOSTOS)" = 'windows' ]; then 35 if [ -z "$FROM_DOCKERFILE" ]; then 36 unset inContainer 37 fi 38 else 39 if [ "$PWD" != "/go/src/$DOCKER_PKG" ]; then 40 unset inContainer 41 fi 42 fi 43 44 if [ -z "$inContainer" ]; then 45 { 46 echo "# WARNING! I don't seem to be running in a Docker container." 47 echo "# The result of this command might be an incorrect build, and will not be" 48 echo "# officially supported." 49 echo "#" 50 echo "# Try this instead: make all" 51 echo "#" 52 } >&2 53 fi 54 55 echo 56 57 # List of bundles to create when no argument is passed 58 DEFAULT_BUNDLES=( 59 binary-daemon 60 dynbinary 61 62 test-integration 63 test-docker-py 64 65 cross 66 ) 67 68 VERSION=${VERSION:-dev} 69 ! BUILDTIME=$(date -u -d "@${SOURCE_DATE_EPOCH:-$(date +%s)}" --rfc-3339 ns 2> /dev/null | sed -e 's/ /T/') 70 if [ "$DOCKER_GITCOMMIT" ]; then 71 GITCOMMIT="$DOCKER_GITCOMMIT" 72 elif command -v git &> /dev/null && [ -e .git ] && git rev-parse &> /dev/null; then 73 GITCOMMIT=$(git rev-parse --short HEAD) 74 if [ -n "$(git status --porcelain --untracked-files=no)" ]; then 75 GITCOMMIT="$GITCOMMIT-unsupported" 76 echo "#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~" 77 echo "# GITCOMMIT = $GITCOMMIT" 78 echo "# The version you are building is listed as unsupported because" 79 echo "# there are some files in the git repository that are in an uncommitted state." 80 echo "# Commit these changes, or add to .gitignore to remove the -unsupported from the version." 81 echo "# Here is the current list:" 82 git status --porcelain --untracked-files=no 83 echo "#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~" 84 fi 85 else 86 echo >&2 'error: .git directory missing and DOCKER_GITCOMMIT not specified' 87 echo >&2 ' Please either build with the .git directory accessible, or specify the' 88 echo >&2 ' exact (--short) commit hash you are building using DOCKER_GITCOMMIT for' 89 echo >&2 ' future accountability in diagnosing build issues. Thanks!' 90 exit 1 91 fi 92 93 if [ "$AUTO_GOPATH" ]; then 94 rm -rf .gopath 95 mkdir -p .gopath/src/"$(dirname "${DOCKER_PKG}")" 96 ln -sf ../../../.. .gopath/src/"${DOCKER_PKG}" 97 export GOPATH="${PWD}/.gopath" 98 fi 99 100 if [ ! "$GOPATH" ]; then 101 echo >&2 'error: missing GOPATH; please see https://golang.org/doc/code.html#GOPATH' 102 echo >&2 ' alternatively, set AUTO_GOPATH=1' 103 exit 1 104 fi 105 106 if ${PKG_CONFIG} 'libsystemd >= 209' 2> /dev/null ; then 107 DOCKER_BUILDTAGS+=" journald" 108 elif ${PKG_CONFIG} 'libsystemd-journal' 2> /dev/null ; then 109 DOCKER_BUILDTAGS+=" journald journald_compat" 110 fi 111 112 # test whether "btrfs/version.h" exists and apply btrfs_noversion appropriately 113 if \ 114 command -v gcc &> /dev/null \ 115 && ! gcc -E - -o /dev/null &> /dev/null <<<'#include <btrfs/version.h>' \ 116 ; then 117 DOCKER_BUILDTAGS+=' btrfs_noversion' 118 fi 119 120 # test whether "libdevmapper.h" is new enough to support deferred remove 121 # functionality. 122 if \ 123 command -v gcc &> /dev/null \ 124 && ! ( echo -e '#include <libdevmapper.h>\nint main() { dm_task_deferred_remove(NULL); }'| gcc -xc - -o /dev/null $(pkg-config --libs devmapper) &> /dev/null ) \ 125 ; then 126 DOCKER_BUILDTAGS+=' libdm_no_deferred_remove' 127 fi 128 129 # Use these flags when compiling the tests and final binary 130 131 IAMSTATIC='true' 132 if [ -z "$DOCKER_DEBUG" ]; then 133 LDFLAGS='-w' 134 fi 135 136 LDFLAGS_STATIC='' 137 EXTLDFLAGS_STATIC='-static' 138 # ORIG_BUILDFLAGS is necessary for the cross target which cannot always build 139 # with options like -race. 140 ORIG_BUILDFLAGS=( -tags "autogen netgo static_build $DOCKER_BUILDTAGS" -installsuffix netgo ) 141 # see https://github.com/golang/go/issues/9369#issuecomment-69864440 for why -installsuffix is necessary here 142 143 # When $DOCKER_INCREMENTAL_BINARY is set in the environment, enable incremental 144 # builds by installing dependent packages to the GOPATH. 145 REBUILD_FLAG="-a" 146 if [ "$DOCKER_INCREMENTAL_BINARY" == "1" ] || [ "$DOCKER_INCREMENTAL_BINARY" == "true" ]; then 147 REBUILD_FLAG="-i" 148 fi 149 ORIG_BUILDFLAGS+=( $REBUILD_FLAG ) 150 151 BUILDFLAGS=( $BUILDFLAGS "${ORIG_BUILDFLAGS[@]}" ) 152 153 # Test timeout. 154 if [ "${DOCKER_ENGINE_GOARCH}" == "arm" ]; then 155 : ${TIMEOUT:=10m} 156 elif [ "${DOCKER_ENGINE_GOARCH}" == "windows" ]; then 157 : ${TIMEOUT:=8m} 158 else 159 : ${TIMEOUT:=5m} 160 fi 161 162 LDFLAGS_STATIC_DOCKER=" 163 $LDFLAGS_STATIC 164 -extldflags \"$EXTLDFLAGS_STATIC\" 165 " 166 167 if [ "$(uname -s)" = 'FreeBSD' ]; then 168 # Tell cgo the compiler is Clang, not GCC 169 # https://code.google.com/p/go/source/browse/src/cmd/cgo/gcc.go?spec=svne77e74371f2340ee08622ce602e9f7b15f29d8d3&r=e6794866ebeba2bf8818b9261b54e2eef1c9e588#752 170 export CC=clang 171 172 # "-extld clang" is a workaround for 173 # https://code.google.com/p/go/issues/detail?id=6845 174 LDFLAGS="$LDFLAGS -extld clang" 175 fi 176 177 bundle() { 178 local bundle="$1"; shift 179 echo "---> Making bundle: $(basename "$bundle") (in $DEST)" 180 source "$SCRIPTDIR/make/$bundle" "$@" 181 } 182 183 main() { 184 if [ -z "${KEEPBUNDLE-}" ]; then 185 echo "Removing bundles/" 186 rm -rf "bundles/*" 187 echo 188 fi 189 mkdir -p bundles 190 191 # Windows and symlinks don't get along well 192 if [ "$(go env GOHOSTOS)" != 'windows' ]; then 193 rm -f bundles/latest 194 # preserve latest symlink for backward compatibility 195 ln -sf . bundles/latest 196 fi 197 198 if [ $# -lt 1 ]; then 199 bundles=(${DEFAULT_BUNDLES[@]}) 200 else 201 bundles=($@) 202 fi 203 for bundle in ${bundles[@]}; do 204 export DEST="bundles/$(basename "$bundle")" 205 # Cygdrive paths don't play well with go build -o. 206 if [[ "$(uname -s)" == CYGWIN* ]]; then 207 export DEST="$(cygpath -mw "$DEST")" 208 fi 209 mkdir -p "$DEST" 210 ABS_DEST="$(cd "$DEST" && pwd -P)" 211 bundle "$bundle" 212 echo 213 done 214 } 215 216 main "$@"