start-build-env.sh 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. #!/usr/bin/env bash
  2. #
  3. # Licensed to the Apache Software Foundation (ASF) under one or more
  4. # contributor license agreements. See the NOTICE file distributed with
  5. # this work for additional information regarding copyright ownership.
  6. # The ASF licenses this file to You under the Apache License, Version 2.0
  7. # (the "License"); you may not use this file except in compliance with
  8. # the License. You may obtain a copy of the License at
  9. #
  10. # http://www.apache.org/licenses/LICENSE-2.0
  11. #
  12. # Unless required by applicable law or agreed to in writing, software
  13. # distributed under the License is distributed on an "AS IS" BASIS,
  14. # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  15. # See the License for the specific language governing permissions and
  16. # limitations under the License.
  17. # Start a Docker-based build environment
  18. set -e -u
  19. cd "$(dirname "$0")"
  20. # OS to build on
  21. : ${BUILD_OS:=centos7}
  22. # Directory with Ambari source
  23. : ${AMBARI_DIR:=$(pwd -P)}
  24. # Maven version
  25. : ${MAVEN_VERSION:=3.6.0}
  26. docker build -t ambari-build-base:${BUILD_OS} dev-support/docker/${BUILD_OS}
  27. docker build -t ambari-build:${BUILD_OS} --build-arg BUILD_OS="${BUILD_OS}" --build-arg MAVEN_VERSION="${MAVEN_VERSION}" dev-support/docker/common
  28. USER_NAME=${SUDO_USER:=$USER}
  29. USER_ID=$(id -u "${USER_NAME}")
  30. GROUP_ID=$(id -g "${USER_NAME}")
  31. USER_TAG="ambari-build-${USER_NAME}-${USER_ID}:${BUILD_OS}"
  32. docker build -t "$USER_TAG" - <<UserSpecificDocker
  33. FROM ambari-build:${BUILD_OS}
  34. RUN groupadd --non-unique -g ${GROUP_ID} ${USER_NAME}
  35. RUN useradd -g ${GROUP_ID} -u ${USER_ID} -k /root -m ${USER_NAME}
  36. ENV HOME /home/${USER_NAME}
  37. UserSpecificDocker
  38. TTY_MODE="-t -i"
  39. if [ "$#" -gt 0 ]; then
  40. TTY_MODE=""
  41. fi
  42. # By mapping the .m2 directory you can do an mvn install from
  43. # within the container and use the result on your normal
  44. # system. This also allows a significant speedup in subsequent
  45. # builds, because the dependencies are downloaded only once.
  46. docker run --rm=true $TTY_MODE \
  47. -u "${USER_NAME}" \
  48. -h "${BUILD_OS}" \
  49. -v "${AMBARI_DIR}:/home/${USER_NAME}/src:delegated" \
  50. -v "${HOME}/.m2:/home/${USER_NAME}/.m2:cached" \
  51. -w "/home/${USER_NAME}/src" \
  52. "$USER_TAG" \
  53. "$@"