run.sh 1.9 KB

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