github.com/shiroyuki/docker@v1.9.0/hack/make/build-rpm (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  
     8  	source "$(dirname "$BASH_SOURCE")/.integration-daemon-start"
     9  
    10  	# TODO consider using frozen images for the dockercore/builder-rpm tags
    11  
    12  	rpmName=docker-engine
    13  	rpmVersion="${VERSION%%-*}"
    14  	rpmRelease=1
    15  
    16  	# rpmRelease versioning is as follows
    17  	# Docker 1.7.0:  version=1.7.0, release=1
    18  	# Docker 1.7.0-rc1: version=1.7.0, release=0.1.rc1
    19  	# Docker 1.7.0-dev nightly: version=1.7.0, release=0.0.YYYYMMDD.HHMMSS.gitHASH
    20  
    21  	# if we have a "-rc*" suffix, set appropriate release
    22  	if [[ "$VERSION" == *-rc* ]]; then
    23  		rcVersion=${VERSION#*-rc}
    24  		rpmRelease="0.${rcVersion}.rc${rcVersion}"
    25  	fi
    26  
    27  	DOCKER_GITCOMMIT=$(git rev-parse --short HEAD)
    28  	if [ -n "$(git status --porcelain --untracked-files=no)" ]; then
    29  		DOCKER_GITCOMMIT="$DOCKER_GITCOMMIT-dirty"
    30  	fi
    31  
    32  	# if we have a "-dev" suffix or have change in Git, let's make this package version more complex so it works better
    33  	if [[ "$VERSION" == *-dev ]] || [ -n "$(git status --porcelain)" ]; then
    34  		gitUnix="$(git log -1 --pretty='%at')"
    35  		gitDate="$(date --date "@$gitUnix" +'%Y%m%d.%H%M%S')"
    36  		gitCommit="$(git log -1 --pretty='%h')"
    37  		gitVersion="${gitDate}.git${gitCommit}"
    38  		# gitVersion is now something like '20150128.112847.17e840a'
    39  		rpmRelease="0.0.$gitVersion"
    40  	fi
    41  
    42  	rpmPackager="$(awk -F ': ' '$1 == "Packager" { print $2; exit }' hack/make/.build-rpm/${rpmName}.spec)"
    43  	rpmDate="$(date +'%a %b %d %Y')"
    44  
    45  	# if go-md2man is available, pre-generate the man pages
    46  	./man/md2man-all.sh -q || true
    47  	# TODO decide if it's worth getting go-md2man in _each_ builder environment to avoid this
    48  
    49  	# TODO add a configurable knob for _which_ rpms to build so we don't have to modify the file or build all of them every time we need to test
    50  	for dir in contrib/builder/rpm/*/; do
    51  		version="$(basename "$dir")"
    52  		suite="${version##*-}"
    53  
    54  		image="dockercore/builder-rpm:$version"
    55  		if ! docker inspect "$image" &> /dev/null; then
    56  			( set -x && docker build -t "$image" "$dir" )
    57  		fi
    58  
    59  		mkdir -p "$DEST/$version"
    60  		cat > "$DEST/$version/Dockerfile.build" <<-EOF
    61  			FROM $image
    62  			COPY . /usr/src/${rpmName}
    63  		EOF
    64  		if [ "$DOCKER_EXPERIMENTAL" ]; then
    65  			echo 'ENV DOCKER_EXPERIMENTAL 1' >> "$DEST/$version/Dockerfile.build"
    66  		fi
    67  		cat >> "$DEST/$version/Dockerfile.build" <<-EOF
    68  			RUN mkdir -p /root/rpmbuild/SOURCES \
    69  				&& echo '%_topdir /root/rpmbuild' > /root/.rpmmacros
    70  			WORKDIR /root/rpmbuild
    71  			RUN ln -sfv /usr/src/${rpmName}/hack/make/.build-rpm SPECS
    72  			WORKDIR /root/rpmbuild/SPECS
    73  			RUN tar -cz -C /usr/src -f /root/rpmbuild/SOURCES/${rpmName}.tar.gz ${rpmName}
    74  			RUN { echo '* $rpmDate $rpmPackager $rpmVersion-$rpmRelease'; echo '* Version: $VERSION'; } >> ${rpmName}.spec && tail >&2 ${rpmName}.spec
    75  			RUN rpmbuild -ba --define '_release $rpmRelease' --define '_version $rpmVersion' --define '_origversion $VERSION' ${rpmName}.spec
    76  		EOF
    77  		# selinux policy referencing systemd things won't work on non-systemd versions
    78  		# of centos or rhel, which we don't support anyways
    79  		if [ "${suite%.*}" -gt 6 ] && [[ "$version" != opensuse* ]]; then
    80  			cat >> "$DEST/$version/Dockerfile.build" <<-EOF
    81  				RUN tar -cz -C /usr/src/${rpmName}/contrib -f /root/rpmbuild/SOURCES/${rpmName}-selinux.tar.gz ${rpmName}-selinux
    82  				RUN { echo '* $rpmDate $rpmPackager $rpmVersion-$rpmRelease'; echo '* Version: $VERSION'; } >> ${rpmName}-selinux.spec && tail >&2 ${rpmName}-selinux.spec
    83  				RUN rpmbuild -ba --define '_gitcommit $DOCKER_GITCOMMIT' --define '_release $rpmRelease' --define '_version $rpmVersion' --define '_origversion $VERSION' ${rpmName}-selinux.spec
    84  			EOF
    85  		fi
    86  		tempImage="docker-temp/build-rpm:$version"
    87  		( set -x && docker build -t "$tempImage" -f $DEST/$version/Dockerfile.build . )
    88  		docker run --rm "$tempImage" bash -c 'cd /root/rpmbuild && tar -c *RPMS' | tar -xvC "$DEST/$version"
    89  		docker rmi "$tempImage"
    90  	done
    91  
    92  	source "$(dirname "$BASH_SOURCE")/.integration-daemon-stop"
    93  ) 2>&1 | tee -a $DEST/test.log