github.com/duglin/docker@v1.13.1/hack/make/tgz (about)

     1  #!/bin/bash
     2  
     3  CROSS="$DEST/../cross"
     4  
     5  set -e
     6  
     7  arch=$(go env GOHOSTARCH)
     8  if [ ! -d "$CROSS/linux/${arch}" ]; then
     9  	echo >&2 'error: binary and cross must be run before tgz'
    10  	false
    11  fi
    12  
    13  (
    14  for d in "$CROSS/"*/*; do
    15  	export GOARCH="$(basename "$d")"
    16  	export GOOS="$(basename "$(dirname "$d")")"
    17  
    18  	source "${MAKEDIR}/.binary-setup"
    19  
    20  	BINARY_NAME="${DOCKER_CLIENT_BINARY_NAME}-$VERSION"
    21  	DAEMON_BINARY_NAME="${DOCKER_DAEMON_BINARY_NAME}-$VERSION"
    22  	PROXY_BINARY_NAME="${DOCKER_PROXY_BINARY_NAME}-$VERSION"
    23  	BINARY_EXTENSION="$(export GOOS && binary_extension)"
    24  	if [ "$GOOS" = 'windows' ]; then
    25  		# if windows use a zip, not tgz
    26  		BUNDLE_EXTENSION=".zip"
    27  		IS_TAR="false"
    28  	elif [ "$GOOS" == "solaris" ]; then
    29  		# Solaris bypasses cross due to CGO issues.
    30  		continue
    31  	else
    32  		BUNDLE_EXTENSION=".tgz"
    33  		IS_TAR="true"
    34  	fi
    35  	BINARY_FULLNAME="$BINARY_NAME$BINARY_EXTENSION"
    36  	DAEMON_BINARY_FULLNAME="$DAEMON_BINARY_NAME$BINARY_EXTENSION"
    37  	PROXY_BINARY_FULLNAME="$PROXY_BINARY_NAME$BINARY_EXTENSION"
    38  	mkdir -p "$DEST/$GOOS/$GOARCH"
    39  	TGZ="$DEST/$GOOS/$GOARCH/$BINARY_NAME$BUNDLE_EXTENSION"
    40  
    41  	# The staging directory for the files in the tgz
    42  	BUILD_PATH="$DEST/build"
    43  
    44  	# The directory that is at the root of the tar file
    45  	TAR_BASE_DIRECTORY="docker"
    46  
    47  	# $DEST/build/docker
    48  	TAR_PATH="$BUILD_PATH/$TAR_BASE_DIRECTORY"
    49  
    50  	# Copy the correct docker binary
    51  	mkdir -p $TAR_PATH
    52  	cp -L "$d/$BINARY_FULLNAME" "$TAR_PATH/${DOCKER_CLIENT_BINARY_NAME}${BINARY_EXTENSION}"
    53  	if [ -f "$d/$DAEMON_BINARY_FULLNAME" ]; then
    54  		cp -L "$d/$DAEMON_BINARY_FULLNAME" "$TAR_PATH/${DOCKER_DAEMON_BINARY_NAME}${BINARY_EXTENSION}"
    55  	fi
    56  	if [ -f "$d/$PROXY_BINARY_FULLNAME" ]; then
    57  		cp -L "$d/$PROXY_BINARY_FULLNAME" "$TAR_PATH/${DOCKER_PROXY_BINARY_NAME}${BINARY_EXTENSION}"
    58  	fi
    59  
    60  	# copy over all the extra binaries
    61  	copy_binaries $TAR_PATH
    62  
    63  	# add completions
    64  	for s in bash fish zsh; do
    65  		mkdir -p $TAR_PATH/completion/$s
    66  		cp -L contrib/completion/$s/*docker* $TAR_PATH/completion/$s/
    67  	done
    68  
    69  	if [ "$IS_TAR" == "true" ]; then
    70  		echo "Creating tgz from $BUILD_PATH and naming it $TGZ"
    71  		tar --numeric-owner --owner 0 -C "$BUILD_PATH" -czf "$TGZ" $TAR_BASE_DIRECTORY
    72  	else
    73  		# ZIP needs to full absolute dir path, not the absolute path
    74  		ZIP=`pwd`"/$TGZ"
    75  		# keep track of where we are, for later.
    76  		pushd .
    77  		# go into the BUILD_PATH since zip does not have a -C equivalent.
    78  		cd $BUILD_PATH
    79  		echo "Creating zip from $BUILD_PATH and naming it $ZIP"
    80  		zip -q -r $ZIP $TAR_BASE_DIRECTORY
    81  		# go back to where we started
    82  		popd
    83  	fi
    84  
    85  	hash_files "$TGZ"
    86  
    87  	# cleanup after ourselves
    88  	rm -rf "$BUILD_PATH"
    89  
    90  	echo "Created tgz: $TGZ"
    91  done
    92  )