github.com/skf/moby@v1.13.1/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 source "$(dirname "$BASH_SOURCE")/.detect-daemon-osarch" 10 11 # TODO consider using frozen images for the dockercore/builder-rpm tags 12 13 rpmName=docker-engine 14 rpmVersion="$VERSION" 15 rpmRelease=1 16 17 # rpmRelease versioning is as follows 18 # Docker 1.7.0: version=1.7.0, release=1 19 # Docker 1.7.0-rc1: version=1.7.0, release=0.1.rc1 20 # Docker 1.7.0-cs1: version=1.7.0.cs1, release=1 21 # Docker 1.7.0-cs1-rc1: version=1.7.0.cs1, release=0.1.rc1 22 # Docker 1.7.0-dev nightly: version=1.7.0, release=0.0.YYYYMMDD.HHMMSS.gitHASH 23 24 # if we have a "-rc*" suffix, set appropriate release 25 if [[ "$rpmVersion" =~ .*-rc[0-9]+$ ]] ; then 26 rcVersion=${rpmVersion#*-rc} 27 rpmVersion=${rpmVersion%-rc*} 28 rpmRelease="0.${rcVersion}.rc${rcVersion}" 29 fi 30 31 DOCKER_GITCOMMIT=$(git rev-parse --short HEAD) 32 if [ -n "$(git status --porcelain --untracked-files=no)" ]; then 33 DOCKER_GITCOMMIT="$DOCKER_GITCOMMIT-unsupported" 34 fi 35 36 # if we have a "-dev" suffix or have change in Git, let's make this package version more complex so it works better 37 if [[ "$rpmVersion" == *-dev ]] || [ -n "$(git status --porcelain)" ]; then 38 gitUnix="$(git log -1 --pretty='%at')" 39 gitDate="$(date --date "@$gitUnix" +'%Y%m%d.%H%M%S')" 40 gitCommit="$(git log -1 --pretty='%h')" 41 gitVersion="${gitDate}.git${gitCommit}" 42 # gitVersion is now something like '20150128.112847.17e840a' 43 rpmVersion="${rpmVersion%-dev}" 44 rpmRelease="0.0.$gitVersion" 45 fi 46 47 # Replace any other dashes with periods 48 rpmVersion="${rpmVersion/-/.}" 49 50 rpmPackager="$(awk -F ': ' '$1 == "Packager" { print $2; exit }' hack/make/.build-rpm/${rpmName}.spec)" 51 rpmDate="$(date +'%a %b %d %Y')" 52 53 # if go-md2man is available, pre-generate the man pages 54 make manpages 55 56 # Convert the CHANGELOG.md file into RPM changelog format 57 VERSION_REGEX="^\W\W (.*) \((.*)\)$" 58 ENTRY_REGEX="^[-+*] (.*)$" 59 while read -r line || [[ -n "$line" ]]; do 60 if [ -z "$line" ]; then continue; fi 61 if [[ "$line" =~ $VERSION_REGEX ]]; then 62 echo >> contrib/builder/rpm/${PACKAGE_ARCH}/changelog 63 echo "* `date -d ${BASH_REMATCH[2]} '+%a %b %d %Y'` ${rpmPackager} - ${BASH_REMATCH[1]}" >> contrib/builder/rpm/${PACKAGE_ARCH}/changelog 64 fi 65 if [[ "$line" =~ $ENTRY_REGEX ]]; then 66 echo "- ${BASH_REMATCH[1]//\`}" >> contrib/builder/rpm/${PACKAGE_ARCH}/changelog 67 fi 68 done < CHANGELOG.md 69 70 builderDir="contrib/builder/rpm/${PACKAGE_ARCH}" 71 pkgs=( $(find "${builderDir}/"*/ -type d) ) 72 if [ ! -z "$DOCKER_BUILD_PKGS" ]; then 73 pkgs=() 74 for p in $DOCKER_BUILD_PKGS; do 75 pkgs+=( "$builderDir/$p" ) 76 done 77 fi 78 for dir in "${pkgs[@]}"; do 79 [ -d "$dir" ] || { echo >&2 "skipping nonexistent $dir"; continue; } 80 version="$(basename "$dir")" 81 suite="${version##*-}" 82 83 image="dockercore/builder-rpm:$version" 84 if ! docker inspect "$image" &> /dev/null; then 85 ( set -x && docker build ${DOCKER_BUILD_ARGS} -t "$image" "$dir" ) 86 fi 87 88 mkdir -p "$DEST/$version" 89 cat > "$DEST/$version/Dockerfile.build" <<-EOF 90 FROM $image 91 COPY . /usr/src/${rpmName} 92 WORKDIR /usr/src/${rpmName} 93 RUN mkdir -p /go/src/github.com/docker && mkdir -p /go/src/github.com/opencontainers 94 EOF 95 96 cat >> "$DEST/$version/Dockerfile.build" <<-EOF 97 # Install runc, containerd, proxy and tini 98 RUN TMP_GOPATH="/go" ./hack/dockerfile/install-binaries.sh runc-dynamic containerd-dynamic proxy-dynamic tini 99 EOF 100 if [[ "$VERSION" == *-dev ]] || [ -n "$(git status --porcelain)" ]; then 101 echo 'ENV DOCKER_EXPERIMENTAL 1' >> "$DEST/$version/Dockerfile.build" 102 fi 103 cat >> "$DEST/$version/Dockerfile.build" <<-EOF 104 RUN mkdir -p /root/rpmbuild/SOURCES \ 105 && echo '%_topdir /root/rpmbuild' > /root/.rpmmacros 106 WORKDIR /root/rpmbuild 107 RUN ln -sfv /usr/src/${rpmName}/hack/make/.build-rpm SPECS 108 WORKDIR /root/rpmbuild/SPECS 109 RUN tar --exclude .git -r -C /usr/src -f /root/rpmbuild/SOURCES/${rpmName}.tar ${rpmName} 110 RUN tar --exclude .git -r -C /go/src/github.com/docker -f /root/rpmbuild/SOURCES/${rpmName}.tar containerd 111 RUN tar --exclude .git -r -C /go/src/github.com/docker/libnetwork/cmd -f /root/rpmbuild/SOURCES/${rpmName}.tar proxy 112 RUN tar --exclude .git -r -C /go/src/github.com/opencontainers -f /root/rpmbuild/SOURCES/${rpmName}.tar runc 113 RUN tar --exclude .git -r -C /go/ -f /root/rpmbuild/SOURCES/${rpmName}.tar tini 114 RUN gzip /root/rpmbuild/SOURCES/${rpmName}.tar 115 RUN { cat /usr/src/${rpmName}/contrib/builder/rpm/${PACKAGE_ARCH}/changelog; } >> ${rpmName}.spec && tail >&2 ${rpmName}.spec 116 RUN rpmbuild -ba \ 117 --define '_gitcommit $DOCKER_GITCOMMIT' \ 118 --define '_release $rpmRelease' \ 119 --define '_version $rpmVersion' \ 120 --define '_origversion $VERSION' \ 121 --define '_experimental ${DOCKER_EXPERIMENTAL:-0}' \ 122 ${rpmName}.spec 123 EOF 124 # selinux policy referencing systemd things won't work on non-systemd versions 125 # of centos or rhel, which we don't support anyways 126 if [ "${suite%.*}" -gt 6 ] && [[ "$version" != opensuse* ]]; then 127 selinuxDir="selinux" 128 if [ -d "./contrib/selinux-$version" ]; then 129 selinuxDir="selinux-${version}" 130 fi 131 cat >> "$DEST/$version/Dockerfile.build" <<-EOF 132 RUN tar -cz -C /usr/src/${rpmName}/contrib/${selinuxDir} -f /root/rpmbuild/SOURCES/${rpmName}-selinux.tar.gz ${rpmName}-selinux 133 RUN rpmbuild -ba \ 134 --define '_gitcommit $DOCKER_GITCOMMIT' \ 135 --define '_release $rpmRelease' \ 136 --define '_version $rpmVersion' \ 137 --define '_origversion $VERSION' \ 138 ${rpmName}-selinux.spec 139 EOF 140 fi 141 tempImage="docker-temp/build-rpm:$version" 142 ( set -x && docker build -t "$tempImage" -f $DEST/$version/Dockerfile.build . ) 143 docker run --rm "$tempImage" bash -c 'cd /root/rpmbuild && tar -c *RPMS' | tar -xvC "$DEST/$version" 144 docker rmi "$tempImage" 145 done 146 147 source "$(dirname "$BASH_SOURCE")/.integration-daemon-stop" 148 ) 2>&1 | tee -a $DEST/test.log