build-image.sh 1.6 KB

123456789101112131415161718192021222324252627282930313233343536
  1. #!/usr/bin/env bash
  2. set -euo pipefail
  3. if [[ "${1:-}" == "--help" || "${1:-}" == "-h" ]]; then
  4. echo "usage: $0"
  5. echo 'Environment: PROD2U_PULL_POLICY (missing), PROD2U_CACHE_DIR (/data/prod2u/cache),'
  6. echo 'PROD2U_PIP_WHEELHOUSE (optional offline wheel directory), DEBIAN_MIRROR,'
  7. echo 'DEBIAN_SECURITY_MIRROR, PYPI_INDEX_URL, CONTAINERS_REGISTRIES_CONF.'
  8. exit 0
  9. fi
  10. if [[ $# -ne 0 ]]; then echo "unexpected build arguments" >&2; exit 2; fi
  11. root="$(cd "$(dirname "$0")/../.." && pwd)"
  12. export CONTAINERS_REGISTRIES_CONF="${CONTAINERS_REGISTRIES_CONF:-$root/tools/remote/registries-cn.conf}"
  13. pull_policy="${PROD2U_PULL_POLICY:-missing}"
  14. cache_base="${PROD2U_CACHE_DIR:-/data/prod2u/cache}"
  15. mkdir -p "$cache_base/apt/archives/partial"
  16. extra_args=()
  17. if [[ -n "${PROD2U_PIP_WHEELHOUSE:-}" ]]; then
  18. if [[ ! -d "$PROD2U_PIP_WHEELHOUSE" ]]; then
  19. echo "OFFLINE_CACHE_MISS: $PROD2U_PIP_WHEELHOUSE" >&2
  20. exit 4
  21. fi
  22. extra_args+=(
  23. --volume "$PROD2U_PIP_WHEELHOUSE:/opt/prod2u/wheelhouse:ro"
  24. --env PIP_NO_INDEX=1
  25. --env PIP_FIND_LINKS=/opt/prod2u/wheelhouse
  26. )
  27. fi
  28. exec podman build --pull="$pull_policy" \
  29. --volume "$cache_base/apt:/var/cache/apt:rw" \
  30. "${extra_args[@]}" \
  31. --build-arg DEBIAN_MIRROR="${DEBIAN_MIRROR:-http://mirrors.aliyun.com/debian}" \
  32. --build-arg DEBIAN_SECURITY_MIRROR="${DEBIAN_SECURITY_MIRROR:-http://mirrors.aliyun.com/debian-security}" \
  33. --build-arg PYPI_INDEX_URL="${PYPI_INDEX_URL:-https://mirrors.aliyun.com/pypi/simple}" \
  34. -t localhost/prod2u-6400-dev:locked \
  35. -f "$root/containers/6400-dev/Containerfile" \
  36. "$root/containers/6400-dev"