release_dockerhub.sh 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. #!/usr/bin/env bash
  2. # This script builds the official docker images and pushes them to dockerhub
  3. # after checking with the user.
  4. # bash strict mode
  5. set -euo pipefail
  6. # Check if exactly one argument is supplied
  7. if [ "$#" -ne 1 ]; then
  8. echo "Usage: $0 <version>" >&2
  9. exit 1
  10. fi
  11. VERSION_STR=${1}
  12. # The argument should be in the form of x.x.x where each x can be one or more digits
  13. if [[ $1 =~ ^[0-9]+\.[0-9]+\.[0-9]+$ ]]; then
  14. echo "Validated version number"
  15. else
  16. echo "Argument must be in the form x.x.x, where x is one or more numbers." >&2
  17. exit 2
  18. fi
  19. echo "------------------------------------------"
  20. echo "Building swe-agent"
  21. echo "------------------------------------------"
  22. docker build -t sweagent/swe-agent:${VERSION_STR} --build-arg MINICONDA_URL=https://repo.anaconda.com/miniconda/Miniconda3-py39_23.11.0-1-Linux-aarch64.sh -f docker/swe.Dockerfile .
  23. docker build -t sweagent/swe-agent:latest --build-arg MINICONDA_URL=https://repo.anaconda.com/miniconda/Miniconda3-py39_23.11.0-1-Linux-aarch64.sh -f docker/swe.Dockerfile .
  24. echo "------------------------------------------"
  25. echo "Building swe-eval"
  26. echo "------------------------------------------"
  27. docker build -t sweagent/swe-eval:${VERSION_STR} -f docker/eval.Dockerfile .
  28. docker build -t sweagent/swe-eval:latest -f docker/eval.Dockerfile .
  29. echo "------------------------------------------"
  30. echo "Building swe-agent-run"
  31. echo "------------------------------------------"
  32. docker build -t sweagent/swe-agent-run:${VERSION_STR} .
  33. docker build -t sweagent/swe-agent-run:latest .
  34. echo "------------------------------------------"
  35. echo "Building of all images done"
  36. echo "------------------------------------------"
  37. read -p "Do you want to push to dockerhub and add the tag to github? (yes to proceed) " answer
  38. if [ "$answer" != "yes" ]; then
  39. echo "Abort; Bye" >&2
  40. exit 3
  41. fi
  42. # Check if the tags already exist on Docker Hub
  43. IMAGES=("sweagent/swe-agent:${VERSION_STR}" "sweagent/swe-agent:latest" "sweagent/swe-eval:${VERSION_STR}" "sweagent/swe-eval:latest" "sweagent/swe-agent-run:${VERSION_STR}" "sweagent/swe-agent-run:latest")
  44. for image in "${IMAGES[@]}"; do
  45. if [[ $image == *"latest"* ]]; then
  46. continue
  47. fi
  48. IMAGE_NAME="${image%:*}"
  49. TAG="${image##*:}"
  50. URL="https://hub.docker.com/v2/repositories/${IMAGE_NAME}/tags/${TAG}/"
  51. HTTP_STATUS=$(curl -s -o /dev/null -w "%{http_code}" "${URL}")
  52. if [ "$HTTP_STATUS" -eq 200 ]; then
  53. echo "The tag '${TAG}' exists for '${IMAGE_NAME}' on Docker Hub." >&2
  54. echo "Abort" >&2
  55. exit 4
  56. fi
  57. done
  58. docker login || {
  59. echo "Failed to login to dockerhub" >&2
  60. exit 8
  61. }
  62. # Let's get serious
  63. # Function to execute upon exit
  64. on_error() {
  65. echo "====> ERROR!!! IMPORTANT: Make sure if you've already pushed something to dockerhub or pushed the tag to github!" >&2
  66. }
  67. trap on_error ERR
  68. git tag v${VERSION_STR} || {
  69. echo "Failed to create a tag in git" >&2
  70. exit 5
  71. }
  72. echo "🔥 Tag v${VERSION_STR} created in git!"
  73. git push origin v${VERSION_STR} || {
  74. echo "Failed to push the tag to github" >&2
  75. exit 6
  76. }
  77. echo "🔥 Tag v${VERSION_STR} pushed to github"
  78. for image in "${IMAGES[@]}"; do
  79. docker push ${image}
  80. echo "🔥 Pushed ${image} to dockerhub"
  81. done