github.com/olljanat/moby@v1.13.1/hack/make/build-deb (about)

     1  #!/bin/bash
     2  set -e
     3  
     4  # subshell so that we can export PATH and TZ without breaking other things
     5  (
     6  	export TZ=UTC # make sure our "date" variables are UTC-based
     7  	bundle .integration-daemon-start
     8  	bundle .detect-daemon-osarch
     9  
    10  	# TODO consider using frozen images for the dockercore/builder-deb tags
    11  
    12  	tilde='~' # ouch Bash 4.2 vs 4.3, you keel me
    13  	debVersion="${VERSION//-/$tilde}" # using \~ or '~' here works in 4.3, but not 4.2; just ~ causes $HOME to be inserted, hence the $tilde
    14  	# if we have a "-dev" suffix or have change in Git, let's make this package version more complex so it works better
    15  	if [[ "$VERSION" == *-dev ]] || [ -n "$(git status --porcelain)" ]; then
    16  		gitUnix="$(git log -1 --pretty='%at')"
    17  		gitDate="$(date --date "@$gitUnix" +'%Y%m%d.%H%M%S')"
    18  		gitCommit="$(git log -1 --pretty='%h')"
    19  		gitVersion="git${gitDate}.0.${gitCommit}"
    20  		# gitVersion is now something like 'git20150128.112847.0.17e840a'
    21  		debVersion="$debVersion~$gitVersion"
    22  
    23  		# $ dpkg --compare-versions 1.5.0 gt 1.5.0~rc1 && echo true || echo false
    24  		# true
    25  		# $ dpkg --compare-versions 1.5.0~rc1 gt 1.5.0~git20150128.112847.17e840a && echo true || echo false
    26  		# true
    27  		# $ dpkg --compare-versions 1.5.0~git20150128.112847.17e840a gt 1.5.0~dev~git20150128.112847.17e840a && echo true || echo false
    28  		# true
    29  
    30  		# ie, 1.5.0 > 1.5.0~rc1 > 1.5.0~git20150128.112847.17e840a > 1.5.0~dev~git20150128.112847.17e840a
    31  	fi
    32  
    33  	debSource="$(awk -F ': ' '$1 == "Source" { print $2; exit }' hack/make/.build-deb/control)"
    34  	debMaintainer="$(awk -F ': ' '$1 == "Maintainer" { print $2; exit }' hack/make/.build-deb/control)"
    35  	debDate="$(date --rfc-2822)"
    36  
    37  	# if go-md2man is available, pre-generate the man pages
    38  	make manpages
    39  
    40  	builderDir="contrib/builder/deb/${PACKAGE_ARCH}"
    41  	pkgs=( $(find "${builderDir}/"*/ -type d) )
    42  	if [ ! -z "$DOCKER_BUILD_PKGS" ]; then
    43  		pkgs=()
    44  		for p in $DOCKER_BUILD_PKGS; do
    45  			pkgs+=( "$builderDir/$p" )
    46  		done
    47  	fi
    48  	for dir in "${pkgs[@]}"; do
    49  		[ -d "$dir" ] || { echo >&2 "skipping nonexistent $dir"; continue; }
    50  		version="$(basename "$dir")"
    51  		suite="${version##*-}"
    52  
    53  		image="dockercore/builder-deb:$version"
    54  		if ! docker inspect "$image" &> /dev/null; then
    55  			(
    56  				# Add the APT_MIRROR args only if the consuming Dockerfile uses it
    57  				# Otherwise this will cause the build to fail
    58  				if [ "$(grep 'ARG APT_MIRROR=' $dir/Dockerfile)" ] && [ "$BUILD_APT_MIRROR" ]; then
    59  					DOCKER_BUILD_ARGS="$DOCKER_BUILD_ARGS $BUILD_APT_MIRROR"
    60  				fi
    61  				set -x && docker build ${DOCKER_BUILD_ARGS} -t "$image" "$dir"
    62  			)
    63  		fi
    64  
    65  		mkdir -p "$DEST/$version"
    66  		cat > "$DEST/$version/Dockerfile.build" <<-EOF
    67  			FROM $image
    68  			WORKDIR /usr/src/docker
    69  			COPY . /usr/src/docker
    70  			ENV DOCKER_GITCOMMIT $GITCOMMIT
    71  			RUN mkdir -p /go/src/github.com/docker && mkdir -p /go/src/github.com/opencontainers \
    72  				&& ln -snf /usr/src/docker /go/src/github.com/docker/docker
    73  		EOF
    74  
    75  		cat >> "$DEST/$version/Dockerfile.build" <<-EOF
    76  			# Install runc, containerd, proxy and tini
    77  			RUN ./hack/dockerfile/install-binaries.sh runc-dynamic containerd-dynamic proxy-dynamic tini
    78  		EOF
    79  		cat >> "$DEST/$version/Dockerfile.build" <<-EOF
    80  			RUN cp -aL hack/make/.build-deb debian
    81  			RUN { echo '$debSource (${debVersion}-0~${version}) $suite; urgency=low'; echo; echo '  * Version: $VERSION'; echo; echo " -- $debMaintainer  $debDate"; } > debian/changelog && cat >&2 debian/changelog
    82  			RUN dpkg-buildpackage -uc -us -I.git
    83  		EOF
    84  		tempImage="docker-temp/build-deb:$version"
    85  		( set -x && docker build -t "$tempImage" -f "$DEST/$version/Dockerfile.build" . )
    86  		docker run --rm "$tempImage" bash -c 'cd .. && tar -c *_*' | tar -xvC "$DEST/$version"
    87  		docker rmi "$tempImage"
    88  	done
    89  
    90  	bundle .integration-daemon-stop
    91  ) 2>&1 | tee -a "$DEST/test.log"