build-linux.sh 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. #!/bin/bash
  2. #
  3. # Copyright (c) Contributors to the Open 3D Engine Project.
  4. # For complete copyright and license terms please see the LICENSE at the root of this distribution.
  5. #
  6. # SPDX-License-Identifier: Apache-2.0 OR MIT
  7. #
  8. # TEMP_FOLDER and TARGET_INSTALL_ROOT get set from the pull_and_build_from_git.py script
  9. # Make sure docker is installed
  10. DOCKER_VERSION=$(docker --version)
  11. if [ $? -ne 0 ]
  12. then
  13. echo "Required package docker is not installed"
  14. echo "Follow instructions on https://docs.docker.com/engine/install/ubuntu/ to install docker properly"
  15. exit 1
  16. fi
  17. echo "Detected Docker Version $DOCKER_VERSION"
  18. DOCKER_BUILD_SCRIPT=docker_build_googlebenchmark_linux.sh
  19. DOCKER_IMAGE_NAME=google_benchmark_linux_3p
  20. if [ ! -f $DOCKER_BUILD_SCRIPT ]
  21. then
  22. echo "Invalid docker build script ${DOCKER_BUILD_SCRIPT}"
  23. exit 1
  24. fi
  25. # Prepare the docker file and use the temp folder as the context root
  26. cp -f ${DOCKER_BUILD_SCRIPT} temp/
  27. pushd temp
  28. # Build the Docker Image
  29. echo "Building the docker build script for ${DOCKER_IMAGE_NAME}"
  30. docker build --build-arg DOCKER_BUILD_SCRIPT=$DOCKER_BUILD_SCRIPT -f ../Dockerfile -t ${DOCKER_IMAGE_NAME}:latest .
  31. if [ $? -ne 0 ]
  32. then
  33. echo "Error occurred creating Docker image ${DOCKER_IMAGE_NAME}:latest."
  34. exit 1
  35. fi
  36. # Capture the Docker Image ID
  37. IMAGE_ID=$(docker images -q ${DOCKER_IMAGE_NAME}:latest)
  38. if [ -z $IMAGE_ID ]
  39. then
  40. echo "Error: Cannot find Image ID for ${DOCKER_IMAGE_NAME}"
  41. exit 1
  42. fi
  43. # Run the Docker Image
  44. echo "Running build script in the docker image"
  45. echo docker run -v $TEMP_FOLDER/src:/data/workspace/src --tty ${DOCKER_IMAGE_NAME}:latest /data/workspace/${DOCKER_BUILD_SCRIPT}
  46. docker run -v $TEMP_FOLDER/src:/data/workspace/src --tty ${DOCKER_IMAGE_NAME}:latest /data/workspace/${DOCKER_BUILD_SCRIPT}
  47. if [ $? -ne 0 ]
  48. then
  49. echo Failed to build from docker image ${DOCKER_IMAGE_NAME}:latest
  50. exit 1
  51. fi
  52. # Capture the container ID
  53. echo "Capturing the Container ID"
  54. CONTAINER_ID=$(docker container ls -l -q --filter "ancestor=${DOCKER_IMAGE_NAME}:latest")
  55. if [ -z $CONTAINER_ID ]
  56. then
  57. echo "Error: Cannot find Container ID for Image ${DOCKER_IMAGE_NAME}"
  58. exit 1
  59. fi
  60. # Copy the build artifacts from the Docker Container
  61. echo "Copying the built contents from the docker container for image ${DOCKER_IMAGE_NAME}"
  62. mkdir -p build
  63. docker cp $CONTAINER_ID:/data/workspace/package/. build
  64. if [ $? -ne 0 ]
  65. then
  66. echo "Error occurred copying build artifacts from Docker image ${DOCKER_IMAGE_NAME}:latest."
  67. exit 1
  68. fi
  69. # Clean up the docker image and container
  70. echo "Cleaning up container"
  71. docker container rm $CONTAINER_ID || (echo "Warning: unable to clean up container for image ${DOCKER_IMAGE_NAME}")
  72. echo "Cleaning up image"
  73. docker rmi --force $IMAGE_ID || (echo "Warning: unable to clean up image ${DOCKER_IMAGE_NAME}")
  74. popd
  75. exit 0