build_image.sh 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. #!/bin/bash
  2. # Licensed to the LF AI & Data foundation under one
  3. # or more contributor license agreements. See the NOTICE file
  4. # distributed with this work for additional information
  5. # regarding copyright ownership. The ASF licenses this file
  6. # to you under the Apache License, Version 2.0 (the
  7. # "License"); you may not use this file except in compliance
  8. # with 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. # Exit immediately for non zero status
  18. set -e
  19. # Print commands
  20. set -x
  21. # Absolute path to the toplevel milvus directory.
  22. toplevel=$(dirname "$(cd "$(dirname "${0}")"; pwd)")
  23. if [[ -f "$toplevel/.env" ]]; then
  24. set -a # automatically export all variables from .env
  25. source $toplevel/.env
  26. set +a # stop automatically exporting
  27. fi
  28. OS_NAME="${OS_NAME:-ubuntu20.04}"
  29. MILVUS_IMAGE_REPO="${MILVUS_IMAGE_REPO:-milvusdb/milvus}"
  30. MILVUS_IMAGE_TAG="${MILVUS_IMAGE_TAG:-latest}"
  31. if [ -z "$IMAGE_ARCH" ]; then
  32. MACHINE=$(uname -m)
  33. if [ "$MACHINE" = "x86_64" ]; then
  34. IMAGE_ARCH="amd64"
  35. else
  36. IMAGE_ARCH="arm64"
  37. fi
  38. fi
  39. echo ${IMAGE_ARCH}
  40. BUILD_ARGS="${BUILD_ARGS:---build-arg TARGETARCH=${IMAGE_ARCH}}"
  41. pushd "${toplevel}"
  42. docker build --network host ${BUILD_ARGS} --platform linux/${IMAGE_ARCH} -f "./build/docker/milvus/${OS_NAME}/Dockerfile" -t "${MILVUS_IMAGE_REPO}:${MILVUS_IMAGE_TAG}" .
  43. image_size=$(docker inspect ${MILVUS_IMAGE_REPO}:${MILVUS_IMAGE_TAG} -f '{{.Size}}'| awk '{ byte =$1 /1024/1024/1024; print byte " GB" }')
  44. echo "Image Size for ${MILVUS_IMAGE_REPO}:${MILVUS_IMAGE_TAG} is ${image_size}"
  45. popd