You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mesos.apache.org by ji...@apache.org on 2018/02/12 00:01:55 UTC

[2/2] mesos git commit: Updated the docker build script for building distro in Docker.

Updated the docker build script for building distro in Docker.


Project: http://git-wip-us.apache.org/repos/asf/mesos/repo
Commit: http://git-wip-us.apache.org/repos/asf/mesos/commit/42010716
Tree: http://git-wip-us.apache.org/repos/asf/mesos/tree/42010716
Diff: http://git-wip-us.apache.org/repos/asf/mesos/diff/42010716

Branch: refs/heads/master
Commit: 420107161c6277830a0adbe34b93da2c277e2820
Parents: 934681e
Author: Jie Yu <yu...@gmail.com>
Authored: Fri Feb 9 17:03:17 2018 -0800
Committer: Jie Yu <yu...@gmail.com>
Committed: Sun Feb 11 16:01:47 2018 -0800

----------------------------------------------------------------------
 support/packaging/centos/build-docker-image.sh | 45 +++++++++++++--------
 1 file changed, 28 insertions(+), 17 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/mesos/blob/42010716/support/packaging/centos/build-docker-image.sh
----------------------------------------------------------------------
diff --git a/support/packaging/centos/build-docker-image.sh b/support/packaging/centos/build-docker-image.sh
index bca6ea5..6965cc0 100755
--- a/support/packaging/centos/build-docker-image.sh
+++ b/support/packaging/centos/build-docker-image.sh
@@ -1,49 +1,60 @@
 #!/usr/bin/env bash
 
+set -o errexit -o nounset -o pipefail -o verbose
+
 # This script builds a CentOS based docker image with Mesos installed
 # using the current head of the source tree.
 
 CENTOS_DIR="$(cd "$(dirname "$0")"; pwd -P)"
-SOURCE_DIR="$(cd $CENTOS_DIR/../../..; pwd -P)"
+SOURCE_DIR="$(cd ${CENTOS_DIR}/../../..; pwd -P)"
 
-BUILD_IMAGE="mesos/packaging-centos7"
-MESOS_IMAGE="mesos"
+DOCKER_IMAGE_PACKAGING=${DOCKER_IMAGE_PACKAGING:-"mesos/mesos-centos-packaging"}
+DOCKER_IMAGE_DISTRO=${DOCKER_IMAGE_DISTRO:-"mesos/mesos-centos"}
+DOCKER_IMAGE_TAG=${DOCKER_IMAGE_TAG:-"latest"}
 
 if ! [ -x "$(command -v docker)" ]; then
   echo 'Error: docker is not installed.' >&2
   exit 1
 fi
 
-if [ -d "$SOURCE_DIR/centos7" ]; then
+if [ -d "${SOURCE_DIR}/centos7" ]; then
   echo "Please cleanup 'centos7' under your Mesos source directory"
   exit 1
 fi
 
+TMP_BUILD_DIR=$(mktemp -d)
+
+function cleanup {
+  rm -rf "${TMP_BUILD_DIR}"
+  rm -rf "${SOURCE_DIR}/centos7"
+}
+
+trap cleanup EXIT
+
 # Build the image for building Mesos packages.
 docker build \
   --rm \
-  -t $BUILD_IMAGE \
-  -f $SOURCE_DIR/support/packaging/centos/centos7.dockerfile \
-  $SOURCE_DIR/support/packaging/centos/
+  -t ${DOCKER_IMAGE_PACKAGING}:${DOCKER_IMAGE_TAG} \
+  -f "${SOURCE_DIR}/support/packaging/centos/centos7.dockerfile" \
+  "${SOURCE_DIR}/support/packaging/centos/"
 
 # Build the RPM.
+USER_ID=`id -u`
+GROUP_ID=`id -g`
+
 docker run \
   --rm \
-  -v $SOURCE_DIR:$SOURCE_DIR \
-  $BUILD_IMAGE \
-  $SOURCE_DIR/support/packaging/centos/build_rpm.sh
+  -v "${SOURCE_DIR}:${SOURCE_DIR}" \
+  ${DOCKER_IMAGE_PACKAGING}:${DOCKER_IMAGE_TAG} \
+  /bin/bash -c "${SOURCE_DIR}/support/packaging/centos/build_rpm.sh && chown -R ${USER_ID}:${GROUP_ID} ${SOURCE_DIR}/centos7"
 
 # Build the image for running Mesos.
-TMP_BUILD_DIR=$(mktemp -d)
+cp "${SOURCE_DIR}"/centos7/rpmbuild/RPMS/x86_64/*.rpm "${TMP_BUILD_DIR}"
 
-cp $SOURCE_DIR/centos7/rpmbuild/RPMS/x86_64/*.rpm $TMP_BUILD_DIR
-
-cat <<EOF > $TMP_BUILD_DIR/Dockerfile
+cat <<EOF > "${TMP_BUILD_DIR}/Dockerfile"
 FROM centos:7
 ADD mesos-?.?.?-*.rpm /
 RUN yum --nogpgcheck -y localinstall /mesos-*.rpm
 EOF
 
-docker build --rm -t $MESOS_IMAGE $TMP_BUILD_DIR
-
-rm -rf $TMP_BUILD_DIR
+docker build --rm -t ${DOCKER_IMAGE_DISTRO}:${DOCKER_IMAGE_TAG} ${TMP_BUILD_DIR}