run.sh 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. #!/bin/bash
  2. # Licensed to the Apache Software Foundation (ASF) under one or more
  3. # contributor license agreements. See the NOTICE file distributed with
  4. # this work for additional information regarding copyright ownership.
  5. # The ASF licenses this file to You under the Apache License, Version 2.0
  6. # (the "License"); you may not use this file except in compliance with
  7. # the License. You may obtain a copy of the License at
  8. #
  9. # http://www.apache.org/licenses/LICENSE-2.0
  10. #
  11. # Unless required by applicable law or agreed to in writing, software
  12. # distributed under the License is distributed on an "AS IS" BASIS,
  13. # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  14. # See the License for the specific language governing permissions and
  15. # limitations under the License.
  16. set -e -x -u
  17. SCRIPT_DIR=$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )
  18. export IMAGE_NAME="zookeeper/dev"
  19. pushd ${SCRIPT_DIR}
  20. docker build --rm=true -t ${IMAGE_NAME} .
  21. popd
  22. if [ "$(uname -s)" == "Linux" ]; then
  23. USER_NAME=${SUDO_USER:=$USER}
  24. USER_ID=$(id -u "${USER_NAME}")
  25. GROUP_ID=$(id -g "${USER_NAME}")
  26. LOCAL_HOME=$(realpath ~)
  27. else # boot2docker uid and gid
  28. USER_NAME=$USER
  29. USER_ID=1000
  30. GROUP_ID=50
  31. LOCAL_HOME="/Users/${USER_NAME}"
  32. fi
  33. docker build -t "${IMAGE_NAME}-${USER_NAME}" - <<UserSpecificDocker
  34. FROM ${IMAGE_NAME}
  35. RUN groupadd --non-unique -g ${GROUP_ID} ${USER_NAME} && \
  36. useradd -g ${GROUP_ID} -u ${USER_ID} -k /root -m ${USER_NAME}
  37. ENV HOME /home/${USER_NAME}
  38. UserSpecificDocker
  39. ZOOKEEPER_ROOT=${SCRIPT_DIR}/../..
  40. CMD="
  41. echo
  42. echo 'Welcome to Apache ZooKeeper Development Env'
  43. echo 'To build, execute'
  44. echo ' mvn clean install'
  45. echo
  46. bash
  47. "
  48. pushd ${ZOOKEEPER_ROOT}
  49. docker run -i -t \
  50. --rm=true \
  51. -w ${ZOOKEEPER_ROOT} \
  52. -u "${USER}" \
  53. -v "$(realpath $ZOOKEEPER_ROOT):${ZOOKEEPER_ROOT}" \
  54. -v "${LOCAL_HOME}:/home/${USER_NAME}" \
  55. ${IMAGE_NAME}-${USER_NAME} \
  56. bash -c "${CMD}"
  57. popd