start-build-env.sh 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  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 # exit on error
  17. cd "$(dirname "$0")" # connect to root
  18. docker build -t hadoop-build dev-support/docker
  19. if [ "$(uname -s)" == "Linux" ]; then
  20. USER_NAME=${SUDO_USER:=$USER}
  21. USER_ID=$(id -u "${USER_NAME}")
  22. GROUP_ID=$(id -g "${USER_NAME}")
  23. else # boot2docker uid and gid
  24. USER_NAME=$USER
  25. USER_ID=1000
  26. GROUP_ID=50
  27. fi
  28. docker build -t "hadoop-build-${USER_NAME}" - <<UserSpecificDocker
  29. FROM hadoop-build
  30. RUN groupadd --non-unique -g ${GROUP_ID} ${USER_NAME}
  31. RUN useradd -g ${GROUP_ID} -u ${USER_ID} -k /root -m ${USER_NAME}
  32. ENV HOME /home/${USER_NAME}
  33. UserSpecificDocker
  34. # By mapping the .m2 directory you can do an mvn install from
  35. # within the container and use the result on your normal
  36. # system. And this also is a significant speedup in subsequent
  37. # builds because the dependencies are downloaded only once.
  38. docker run --rm=true -t -i \
  39. -v "${PWD}:/home/${USER_NAME}/hadoop" \
  40. -w "/home/${USER_NAME}/hadoop" \
  41. -v "${HOME}/.m2:/home/${USER_NAME}/.m2" \
  42. -u "${USER_NAME}" \
  43. "hadoop-build-${USER_NAME}"