2015-04-30 18:30:42 -04:00
|
|
|
#!/bin/bash
|
|
|
|
set -e
|
|
|
|
|
2015-06-03 12:56:46 -04:00
|
|
|
# subshell so that we can export PATH and TZ without breaking other things
|
2015-04-30 18:30:42 -04:00
|
|
|
(
|
2015-06-03 12:56:46 -04:00
|
|
|
export TZ=UTC # make sure our "date" variables are UTC-based
|
|
|
|
|
2015-04-30 18:30:42 -04:00
|
|
|
source "$(dirname "$BASH_SOURCE")/.integration-daemon-start"
|
2015-11-23 14:00:43 -05:00
|
|
|
source "$(dirname "$BASH_SOURCE")/.detect-daemon-osarch"
|
2015-04-30 18:30:42 -04:00
|
|
|
|
|
|
|
# TODO consider using frozen images for the dockercore/builder-rpm tags
|
|
|
|
|
|
|
|
rpmName=docker-engine
|
2016-01-06 18:44:10 -05:00
|
|
|
rpmVersion="$VERSION"
|
2015-04-30 18:30:42 -04:00
|
|
|
rpmRelease=1
|
|
|
|
|
|
|
|
# rpmRelease versioning is as follows
|
|
|
|
# Docker 1.7.0: version=1.7.0, release=1
|
|
|
|
# Docker 1.7.0-rc1: version=1.7.0, release=0.1.rc1
|
2016-01-06 18:44:10 -05:00
|
|
|
# Docker 1.7.0-cs1: version=1.7.0.cs1, release=1
|
|
|
|
# Docker 1.7.0-cs1-rc1: version=1.7.0.cs1, release=0.1.rc1
|
2015-04-30 18:30:42 -04:00
|
|
|
# Docker 1.7.0-dev nightly: version=1.7.0, release=0.0.YYYYMMDD.HHMMSS.gitHASH
|
|
|
|
|
|
|
|
# if we have a "-rc*" suffix, set appropriate release
|
2016-01-06 18:44:10 -05:00
|
|
|
if [[ "$rpmVersion" =~ .*-rc[0-9]+$ ]] ; then
|
|
|
|
rcVersion=${rpmVersion#*-rc}
|
|
|
|
rpmVersion=${rpmVersion%-rc*}
|
2015-04-30 18:30:42 -04:00
|
|
|
rpmRelease="0.${rcVersion}.rc${rcVersion}"
|
|
|
|
fi
|
|
|
|
|
2015-09-15 16:13:22 -04:00
|
|
|
DOCKER_GITCOMMIT=$(git rev-parse --short HEAD)
|
|
|
|
if [ -n "$(git status --porcelain --untracked-files=no)" ]; then
|
2015-12-24 12:11:49 -05:00
|
|
|
DOCKER_GITCOMMIT="$DOCKER_GITCOMMIT-unsupported"
|
2015-09-15 16:13:22 -04:00
|
|
|
fi
|
|
|
|
|
2015-04-30 18:30:42 -04:00
|
|
|
# if we have a "-dev" suffix or have change in Git, let's make this package version more complex so it works better
|
2016-01-06 18:44:10 -05:00
|
|
|
if [[ "$rpmVersion" == *-dev ]] || [ -n "$(git status --porcelain)" ]; then
|
2015-04-30 18:30:42 -04:00
|
|
|
gitUnix="$(git log -1 --pretty='%at')"
|
|
|
|
gitDate="$(date --date "@$gitUnix" +'%Y%m%d.%H%M%S')"
|
|
|
|
gitCommit="$(git log -1 --pretty='%h')"
|
|
|
|
gitVersion="${gitDate}.git${gitCommit}"
|
|
|
|
# gitVersion is now something like '20150128.112847.17e840a'
|
2016-01-06 18:44:10 -05:00
|
|
|
rpmVersion="${rpmVersion%-dev}"
|
2015-04-30 18:30:42 -04:00
|
|
|
rpmRelease="0.0.$gitVersion"
|
|
|
|
fi
|
|
|
|
|
2016-01-06 18:44:10 -05:00
|
|
|
# Replace any other dashes with periods
|
|
|
|
rpmVersion="${rpmVersion/-/.}"
|
|
|
|
|
2015-04-30 18:30:42 -04:00
|
|
|
rpmPackager="$(awk -F ': ' '$1 == "Packager" { print $2; exit }' hack/make/.build-rpm/${rpmName}.spec)"
|
|
|
|
rpmDate="$(date +'%a %b %d %Y')"
|
|
|
|
|
|
|
|
# if go-md2man is available, pre-generate the man pages
|
2015-06-08 13:48:20 -04:00
|
|
|
./man/md2man-all.sh -q || true
|
2015-04-30 18:30:42 -04:00
|
|
|
# TODO decide if it's worth getting go-md2man in _each_ builder environment to avoid this
|
|
|
|
|
2015-09-25 03:25:00 -04:00
|
|
|
# Convert the CHANGELOG.md file into RPM changelog format
|
|
|
|
VERSION_REGEX="^\W\W (.*) \((.*)\)$"
|
|
|
|
ENTRY_REGEX="^[-+*] (.*)$"
|
|
|
|
while read -r line || [[ -n "$line" ]]; do
|
|
|
|
if [ -z "$line" ]; then continue; fi
|
|
|
|
if [[ "$line" =~ $VERSION_REGEX ]]; then
|
2015-11-23 14:00:43 -05:00
|
|
|
echo >> contrib/builder/rpm/${PACKAGE_ARCH}/changelog
|
|
|
|
echo "* `date -d ${BASH_REMATCH[2]} '+%a %b %d %Y'` ${rpmPackager} - ${BASH_REMATCH[1]}" >> contrib/builder/rpm/${PACKAGE_ARCH}/changelog
|
2015-09-25 03:25:00 -04:00
|
|
|
fi
|
|
|
|
if [[ "$line" =~ $ENTRY_REGEX ]]; then
|
2015-11-23 14:00:43 -05:00
|
|
|
echo "- ${BASH_REMATCH[1]//\`}" >> contrib/builder/rpm/${PACKAGE_ARCH}/changelog
|
2015-09-25 03:25:00 -04:00
|
|
|
fi
|
|
|
|
done < CHANGELOG.md
|
|
|
|
|
2015-11-23 14:00:43 -05:00
|
|
|
builderDir="contrib/builder/rpm/${PACKAGE_ARCH}"
|
2016-01-15 18:37:46 -05:00
|
|
|
pkgs=( $(find "${builderDir}/"*/ -type d) )
|
|
|
|
if [ ! -z "$DOCKER_BUILD_PKGS" ]; then
|
|
|
|
pkgs=( $(echo ${DOCKER_BUILD_PKGS[@]/#/$builderDir\/}) )
|
|
|
|
fi
|
|
|
|
for dir in "${pkgs[@]}"; do
|
|
|
|
[ -d "$dir" ] || { echo >&2 "skipping nonexistent $dir"; continue; }
|
2015-04-30 18:30:42 -04:00
|
|
|
version="$(basename "$dir")"
|
|
|
|
suite="${version##*-}"
|
|
|
|
|
|
|
|
image="dockercore/builder-rpm:$version"
|
|
|
|
if ! docker inspect "$image" &> /dev/null; then
|
2015-12-29 04:09:44 -05:00
|
|
|
( set -x && docker build ${DOCKER_BUILD_ARGS} -t "$image" "$dir" )
|
2015-04-30 18:30:42 -04:00
|
|
|
fi
|
|
|
|
|
|
|
|
mkdir -p "$DEST/$version"
|
|
|
|
cat > "$DEST/$version/Dockerfile.build" <<-EOF
|
|
|
|
FROM $image
|
|
|
|
COPY . /usr/src/${rpmName}
|
2016-03-21 20:37:31 -04:00
|
|
|
RUN mkdir -p /go/src/github.com/docker && mkdir -p /go/src/github.com/opencontainers
|
|
|
|
EOF
|
|
|
|
|
|
|
|
# get the RUNC and CONTAINERD commit from the root Dockerfile, this keeps the commits in sync
|
|
|
|
awk '$1 == "ENV" && $2 == "RUNC_COMMIT" { print; exit }' Dockerfile >> "$DEST/$version/Dockerfile.build"
|
|
|
|
awk '$1 == "ENV" && $2 == "CONTAINERD_COMMIT" { print; exit }' Dockerfile >> "$DEST/$version/Dockerfile.build"
|
|
|
|
|
|
|
|
# add runc and containerd compile and install
|
|
|
|
cat >> "$DEST/$version/Dockerfile.build" <<-EOF
|
|
|
|
# Install runc
|
2016-03-29 03:35:42 -04:00
|
|
|
RUN git clone https://github.com/opencontainers/runc.git "/go/src/github.com/opencontainers/runc" \
|
2016-03-21 20:37:31 -04:00
|
|
|
&& cd "/go/src/github.com/opencontainers/runc" \
|
|
|
|
&& git checkout -q "\$RUNC_COMMIT"
|
|
|
|
RUN set -x && export GOPATH="/go" && cd "/go/src/github.com/opencontainers/runc" \
|
|
|
|
&& make BUILDTAGS="\$RUNC_BUILDTAGS" && make install
|
|
|
|
# Install containerd
|
2016-03-29 03:35:42 -04:00
|
|
|
RUN git clone https://github.com/docker/containerd.git "/go/src/github.com/docker/containerd" \
|
2016-03-21 20:37:31 -04:00
|
|
|
&& cd "/go/src/github.com/docker/containerd" \
|
|
|
|
&& git checkout -q "\$CONTAINERD_COMMIT"
|
|
|
|
RUN set -x && export GOPATH="/go" && cd "/go/src/github.com/docker/containerd" && make && make install
|
2015-07-23 11:49:52 -04:00
|
|
|
EOF
|
|
|
|
if [ "$DOCKER_EXPERIMENTAL" ]; then
|
|
|
|
echo 'ENV DOCKER_EXPERIMENTAL 1' >> "$DEST/$version/Dockerfile.build"
|
|
|
|
fi
|
|
|
|
cat >> "$DEST/$version/Dockerfile.build" <<-EOF
|
2015-09-15 16:13:22 -04:00
|
|
|
RUN mkdir -p /root/rpmbuild/SOURCES \
|
|
|
|
&& echo '%_topdir /root/rpmbuild' > /root/.rpmmacros
|
2015-04-30 18:30:42 -04:00
|
|
|
WORKDIR /root/rpmbuild
|
|
|
|
RUN ln -sfv /usr/src/${rpmName}/hack/make/.build-rpm SPECS
|
|
|
|
WORKDIR /root/rpmbuild/SPECS
|
2016-03-21 20:37:31 -04:00
|
|
|
RUN tar -r -C /usr/src -f /root/rpmbuild/SOURCES/${rpmName}.tar ${rpmName}
|
|
|
|
RUN tar -r -C /go/src/github.com/docker -f /root/rpmbuild/SOURCES/${rpmName}.tar containerd
|
|
|
|
RUN tar -r -C /go/src/github.com/opencontainers -f /root/rpmbuild/SOURCES/${rpmName}.tar runc
|
|
|
|
RUN gzip /root/rpmbuild/SOURCES/${rpmName}.tar
|
2015-11-23 14:00:43 -05:00
|
|
|
RUN { cat /usr/src/${rpmName}/contrib/builder/rpm/${PACKAGE_ARCH}/changelog; } >> ${rpmName}.spec && tail >&2 ${rpmName}.spec
|
2015-11-14 17:47:13 -05:00
|
|
|
RUN rpmbuild -ba \
|
2016-01-15 18:46:56 -05:00
|
|
|
--define '_gitcommit $DOCKER_GITCOMMIT' \
|
2015-11-14 17:47:13 -05:00
|
|
|
--define '_release $rpmRelease' \
|
|
|
|
--define '_version $rpmVersion' \
|
|
|
|
--define '_origversion $VERSION' \
|
|
|
|
--define '_experimental ${DOCKER_EXPERIMENTAL:-0}' \
|
|
|
|
${rpmName}.spec
|
2015-04-30 18:30:42 -04:00
|
|
|
EOF
|
2015-08-25 15:46:35 -04:00
|
|
|
# selinux policy referencing systemd things won't work on non-systemd versions
|
|
|
|
# of centos or rhel, which we don't support anyways
|
2015-09-15 16:13:22 -04:00
|
|
|
if [ "${suite%.*}" -gt 6 ] && [[ "$version" != opensuse* ]]; then
|
2015-08-25 15:46:35 -04:00
|
|
|
cat >> "$DEST/$version/Dockerfile.build" <<-EOF
|
|
|
|
RUN tar -cz -C /usr/src/${rpmName}/contrib -f /root/rpmbuild/SOURCES/${rpmName}-selinux.tar.gz ${rpmName}-selinux
|
2015-10-30 21:16:29 -04:00
|
|
|
RUN rpmbuild -ba \
|
|
|
|
--define '_gitcommit $DOCKER_GITCOMMIT' \
|
|
|
|
--define '_release $rpmRelease' \
|
|
|
|
--define '_version $rpmVersion' \
|
|
|
|
--define '_origversion $VERSION' \
|
|
|
|
${rpmName}-selinux.spec
|
2015-08-25 15:46:35 -04:00
|
|
|
EOF
|
|
|
|
fi
|
2015-04-30 18:30:42 -04:00
|
|
|
tempImage="docker-temp/build-rpm:$version"
|
|
|
|
( set -x && docker build -t "$tempImage" -f $DEST/$version/Dockerfile.build . )
|
|
|
|
docker run --rm "$tempImage" bash -c 'cd /root/rpmbuild && tar -c *RPMS' | tar -xvC "$DEST/$version"
|
|
|
|
docker rmi "$tempImage"
|
|
|
|
done
|
|
|
|
|
|
|
|
source "$(dirname "$BASH_SOURCE")/.integration-daemon-stop"
|
|
|
|
) 2>&1 | tee -a $DEST/test.log
|