use-colima.sh 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. #!/bin/bash
  2. POSTGRES_CONTAINER="sentry_postgres"
  3. USE_NEW_DEVSERVICES=${USE_NEW_DEVSERVICES:-"0"}
  4. if [ "$USE_NEW_DEVSERVICES" == "1" ]; then
  5. POSTGRES_CONTAINER="sentry-postgres-1"
  6. fi
  7. if ! [[ -x ~/.local/share/sentry-devenv/bin/colima ]]; then
  8. echo "You need to install devenv! https://github.com/getsentry/devenv/#install"
  9. exit 1
  10. fi
  11. if [[ "$(sysctl -n machdep.cpu.brand_string)" != Intel* ]]; then
  12. case "$(sw_vers -productVersion)" in
  13. *12.*|*13.*)
  14. echo "Your ARM Mac is on a version incompatible with colima."
  15. echo "Use Docker Desktop for now until you upgrade to at least MacOS 14."
  16. exit 1
  17. ;;
  18. esac
  19. fi
  20. echo "Copying your postgres volume for use with colima. Will take a few minutes."
  21. tmpdir=$(mktemp -d)
  22. docker context use desktop-linux
  23. docker run --rm -v $POSTGRES_CONTAINER:/from -v "${tmpdir}:/to" alpine ash -c "cd /from ; cp -a . /to" || { echo "You need to start Docker Desktop."; exit 1; }
  24. echo "Stopping Docker.app. If a 'process terminated unexpectedly' dialog appears, dismiss it."
  25. osascript - <<'EOF' || exit
  26. quit application "Docker"
  27. EOF
  28. # We aren't uninstalling for now - this makes rolling back to docker desktop faster.
  29. # Also, less breakage as people may be using things like docker-credential-desktop.
  30. # echo "Uninstalling docker cask (which includes Docker Desktop)."
  31. # brew uninstall --cask docker
  32. # We do want to get people on just the docker cli though, to enable uninstalling the cask.
  33. echo "Installing docker (cli only)."
  34. brew install docker
  35. # Unlinks docker (cask).
  36. brew unlink docker
  37. brew link --overwrite docker
  38. # This removes credsStore, saving it under oldCredsStore so it can be restored later.
  39. # The right value under colima for this is "colima", but I think vast majority of people
  40. # are authing their docker through gcloud, not docker cli.
  41. python3 <<'EOF'
  42. import os
  43. import json
  44. with open(os.path.expanduser("~/.docker/config.json"), "rb") as f:
  45. config = json.loads(f.read())
  46. credsStore = config.get("credsStore")
  47. if credsStore is None:
  48. exit(0)
  49. config["oldCredsStore"] = credsStore
  50. del config["credsStore"]
  51. with open(os.path.expanduser("~/.docker/config.json"), "w") as f:
  52. f.write(json.dumps(config))
  53. EOF
  54. echo "Starting colima."
  55. devenv colima start
  56. echo "Recreating your postgres volume for use with colima. May take a few minutes."
  57. docker volume create --name $POSTGRES_CONTAINER
  58. docker run --rm -v "${tmpdir}:/from" -v $POSTGRES_CONTAINER:/to alpine ash -c "cd /from ; cp -a . /to"
  59. rm -rf "$tmpdir"
  60. echo "-----------------------------------------------"
  61. echo "All done. Start devservices at your discretion."