use-colima.sh 2.4 KB

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