package.sh 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. #!/usr/bin/env bash
  2. set -o errexit
  3. set -o nounset
  4. set -o pipefail
  5. ROOT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd -P)"
  6. source "${ROOT_DIR}/hack/lib/init.sh"
  7. PACKAGE_NAMESPACE=${PACKAGE_NAMESPACE:-gpustack}
  8. PACKAGE_REPOSITORY=${PACKAGE_REPOSITORY:-gpustack}
  9. PACKAGE_ARCH=${PACKAGE_ARCH:-$(uname -m | sed 's/aarch64/arm64/' | sed 's/x86_64/amd64/')}
  10. PACKAGE_TAG=${PACKAGE_TAG:-dev}
  11. PACKAGE_WITH_CACHE=${PACKAGE_WITH_CACHE:-true}
  12. PACKAGE_PUSH=${PACKAGE_PUSH:-false}
  13. function pack() {
  14. if ! command -v docker &>/dev/null; then
  15. gpustack::log::fatal "Docker is not installed. Please install Docker to use this target."
  16. exit 1
  17. fi
  18. if ! docker buildx inspect --builder "gpustack" &>/dev/null; then
  19. gpustack::log::info "Creating new buildx builder 'gpustack'"
  20. docker run --rm --privileged tonistiigi/binfmt:qemu-v9.2.2-52 --uninstall qemu-*
  21. docker run --rm --privileged tonistiigi/binfmt:qemu-v9.2.2-52 --install all
  22. docker buildx create \
  23. --name "gpustack" \
  24. --driver "docker-container" \
  25. --driver-opt "network=host,default-load=true,env.BUILDKIT_STEP_LOG_MAX_SIZE=-1,env.BUILDKIT_STEP_LOG_MAX_SPEED=-1" \
  26. --buildkitd-flags "--allow-insecure-entitlement=security.insecure --allow-insecure-entitlement=network.host --oci-worker-net=host --oci-worker-gc-keepstorage=204800" \
  27. --bootstrap
  28. fi
  29. LABELS=("org.opencontainers.image.source=https://github.com/gpustack/gpustack" "org.opencontainers.image.version=main" "org.opencontainers.image.revision=$(git rev-parse HEAD 2>/dev/null || echo "unknown")" "org.opencontainers.image.created=$(date +"%Y-%m-%dT%H:%M:%S.%s")");
  30. TAG="${PACKAGE_NAMESPACE}/${PACKAGE_REPOSITORY}:${PACKAGE_TAG}"
  31. EXTRA_ARGS=()
  32. if [[ "${PACKAGE_WITH_CACHE}" == "true" ]]; then
  33. EXTRA_ARGS+=("--cache-from=type=registry,ref=gpustack/build-cache:gpustack-main")
  34. fi
  35. if [[ "${PACKAGE_PUSH}" == "true" ]]; then
  36. EXTRA_ARGS+=("--push")
  37. fi
  38. for label in "${LABELS[@]}"; do
  39. EXTRA_ARGS+=("--label" "${label}")
  40. done
  41. gpustack::log::info "Building '${TAG}' platform 'linux/${PACKAGE_ARCH}'"
  42. set -x
  43. docker buildx build \
  44. --pull \
  45. --allow network.host \
  46. --allow security.insecure \
  47. --builder "gpustack" \
  48. --platform "linux/${PACKAGE_ARCH}" \
  49. --tag "${TAG}" \
  50. --file "${ROOT_DIR}/pack/Dockerfile" \
  51. --ulimit nofile=65536:65536 \
  52. --shm-size 16G \
  53. --progress plain \
  54. --build-arg "GPUSTACK_RUNTIME_DOCKER_MIRRORED_NAME_FILTER_LABELS=$(printf "%s;" "${LABELS[@]}")" \
  55. "${EXTRA_ARGS[@]}" \
  56. "${ROOT_DIR}"
  57. set +x
  58. }
  59. gpustack::log::info "+++ PACKAGE +++"
  60. pack
  61. gpustack::log::info "--- PACKAGE ---"