build_linux.sh 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  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. DOCKER_BUILD_SCRIPT=build_vulkan_validation_linux.sh
  10. DOCKER_IMAGE_NAME=vulkan_validation_layer_3p
  11. # Make sure docker is installed
  12. DOCKER_VERSION=$(docker --version)
  13. if [ $? -ne 0 ]
  14. then
  15. echo "Required package docker is not installed"
  16. echo "Follow instructions on https://docs.docker.com/engine/install/ubuntu/ to install docker properly"
  17. exit 1
  18. fi
  19. echo "Detected Docker Version $DOCKER_VERSION"
  20. # Copy the custom build script to docker context folder
  21. cp $DOCKER_BUILD_SCRIPT temp/
  22. pushd temp
  23. # Build the Docker Image
  24. echo "Creating docker image ${DOCKER_IMAGE_NAME}"
  25. docker build --build-arg DOCKER_BUILD_SCRIPT=${DOCKER_BUILD_SCRIPT} -f ../Dockerfile.linux -t ${DOCKER_IMAGE_NAME}:latest .
  26. if [ $? -ne 0 ]
  27. then
  28. echo "Error occurred creating Docker image ${DOCKER_IMAGE_NAME}:latest."
  29. exit 1
  30. fi
  31. # Capture the Docker Image ID
  32. IMAGE_ID=$(docker images -q ${DOCKER_IMAGE_NAME}:latest)
  33. if [ -z $IMAGE_ID ]
  34. then
  35. echo "Error: Cannot find Image ID for ${DOCKER_IMAGE_NAME}"
  36. exit 1
  37. fi
  38. # Run the Docker Image
  39. echo "Running build script in the docker image ${DOCKER_IMAGE_NAME}"
  40. docker run -v $TEMP_FOLDER/src:/data/workspace/src --tty ${DOCKER_IMAGE_NAME}:latest /data/workspace/$DOCKER_BUILD_SCRIPT
  41. if [ $? -ne 0 ]
  42. then
  43. echo Failed to build from docker image ${DOCKER_IMAGE_NAME}:latest
  44. exit 1
  45. fi
  46. # Capture the container ID
  47. echo "Capturing the Container ID"
  48. CONTAINER_ID=$(docker container ls -l -q --filter "ancestor=${DOCKER_IMAGE_NAME}:latest")
  49. if [ -z $CONTAINER_ID ]
  50. then
  51. echo "Error: Cannot find Container ID for Image ${DOCKER_IMAGE_NAME}"
  52. exit 1
  53. fi
  54. # Copy the build artifacts from the Docker Container
  55. echo "Copying the built contents from the docker container for image ${DOCKER_IMAGE_NAME}"
  56. mkdir -p build
  57. docker cp --quiet $CONTAINER_ID:/data/workspace/build/. build
  58. if [ $? -ne 0 ]
  59. then
  60. echo "Error occurred copying build artifacts from Docker image ${DOCKER_IMAGE_NAME}:latest."
  61. exit 1
  62. fi
  63. # Clean up the docker image and container
  64. echo "Cleaning up container"
  65. docker container rm $CONTAINER_ID || (echo "Warning: unable to clean up container for image ${DOCKER_IMAGE_NAME}")
  66. echo "Cleaning up image"
  67. docker rmi --force $IMAGE_ID || (echo "Warning: unable to clean up image ${DOCKER_IMAGE_NAME}")
  68. popd
  69. exit 0