Skip to content

Commit c1a086f

Browse files
feat: add check/fix for docker currentContext is colima (#200)
Co-authored-by: Joshua Li <[email protected]>
1 parent 4bae0ad commit c1a086f

File tree

3 files changed

+74
-54
lines changed

3 files changed

+74
-54
lines changed

ci/devenv-bootstrap.sh

Lines changed: 24 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -53,58 +53,32 @@ export VIRTUAL_ENV="${HOME}/code/sentry/.venv"
5353
# overwrite sentry's devenv config and resync
5454
# so we don't break when upstream config is updated
5555
cat <<EOF > "devenv/config.ini"
56-
[venv.sentry]
57-
python = 3.13.1
58-
path = .venv
59-
requirements = requirements-dev.txt
60-
editable =
61-
.
62-
# sourced by direnv
63-
# bins =
64-
65-
[python3.13.1]
66-
darwin_x86_64 = https://github.com/astral-sh/python-build-standalone/releases/download/20250106/cpython-3.13.1+20250106-x86_64-apple-darwin-install_only.tar.gz
67-
darwin_x86_64_sha256 = 4c4dafe2d59bb58e8d3ad26af637b7ae9c8141bb79738966752976861bdb103d
68-
darwin_arm64 = https://github.com/astral-sh/python-build-standalone/releases/download/20250106/cpython-3.13.1+20250106-aarch64-apple-darwin-install_only.tar.gz
69-
darwin_arm64_sha256 = bbfc96038d0b6922fd783f6eb2c9bf9abb648531d23d236bc1a0c16bdd061944
70-
linux_x86_64 = https://github.com/astral-sh/python-build-standalone/releases/download/20250106/cpython-3.13.1+20250106-x86_64-unknown-linux-gnu-install_only.tar.gz
71-
linux_x86_64_sha256 = bb4696825039a2b5dc7fea2c6aeb085c89fd397016b44165ec73b4224ccc83e2
72-
linux_arm64 = https://github.com/astral-sh/python-build-standalone/releases/download/20250106/cpython-3.13.1+20250106-aarch64-unknown-linux-gnu-install_only.tar.gz
73-
linux_arm64_sha256 = d37aef7bdf5c27f7d006918f7cedb31f4ba07c88f61baac4ffbe0bee6d4b5248
56+
[devenv]
57+
minimum_version = 1.22.1
58+
59+
[uv]
60+
darwin_arm64 = https://github.com/astral-sh/uv/releases/download/0.8.2/uv-aarch64-apple-darwin.tar.gz
61+
darwin_arm64_sha256 = 954d24634d5f37fa26c7af75eb79893d11623fc81b4de4b82d60d1ade4bfca22
62+
darwin_x86_64 = https://github.com/astral-sh/uv/releases/download/0.8.2/uv-x86_64-apple-darwin.tar.gz
63+
darwin_x86_64_sha256 = ae755df53c8c2c1f3dfbee6e3d2e00be0dfbc9c9b4bdffdb040b96f43678b7ce
64+
linux_arm64 = https://github.com/astral-sh/uv/releases/download/0.8.2/uv-aarch64-unknown-linux-gnu.tar.gz
65+
linux_arm64_sha256 = 27da35ef54e9131c2e305de67dd59a07c19257882c6b1f3cf4d8d5fbb8eaf4ca
66+
linux_x86_64 = https://github.com/astral-sh/uv/releases/download/0.8.2/uv-x86_64-unknown-linux-gnu.tar.gz
67+
linux_x86_64_sha256 = 6dcb28a541868a455aefb2e8d4a1283dd6bf888605a2db710f0530cec888b0ad
68+
# used for autoupdate
69+
version = 0.8.2
7470
7571
[node]
76-
darwin_x86_64 = https://storage.googleapis.com/sentry-dev-infra-assets/node/node-v20.13.1-darwin-x64.tar.xz
77-
darwin_x86_64_sha256 = c83bffeb4eb793da6cb61a44c422b399048a73d7a9c5eb735d9c7f5b0e8659b6
78-
darwin_arm64 = https://storage.googleapis.com/sentry-dev-infra-assets/node/node-v20.13.1-darwin-arm64.tar.xz
79-
darwin_arm64_sha256 = e8a8e78b91485bc95d20f2aa86201485593685c828ee609245ce21c5680d07ce
80-
linux_x86_64 = https://storage.googleapis.com/sentry-dev-infra-assets/node/node-v20.13.1-linux-x64.tar.xz
81-
linux_x86_64_sha256 = efc0f295dd878e510ab12ea36bbadc3db03c687ab30c07e86c7cdba7eed879a9
82-
# used for autoupdate
83-
version = v20.13.1
84-
85-
[colima]
86-
darwin_x86_64 = https://github.com/abiosoft/colima/releases/download/v0.7.5/colima-Darwin-x86_64
87-
darwin_x86_64_sha256 = 53f78b4aaef5fb5dab65cae19fba4504047de1fdafa152fba90435d8a7569c2b
88-
darwin_arm64 = https://github.com/abiosoft/colima/releases/download/v0.7.5/colima-Darwin-arm64
89-
darwin_arm64_sha256 = 267696d6cb28eaf6daa3ea9622c626697b4baeb847b882d15b26c732e841913c
90-
linux_x86_64 = https://github.com/abiosoft/colima/releases/download/v0.7.5/colima-Linux-x86_64
91-
linux_x86_64_sha256 = a3d440033776b2fb0cdd6139a2dbebf6764aabf78a671d4aa13b45c26df21a8a
92-
linux_arm64 = https://github.com/abiosoft/colima/releases/download/v0.7.5/colima-Linux-aarch64
93-
linux_arm64_sha256 = 330e11a4b2e5ce69ee6253635308c9f0f49195f236da01718ede35cdb2729901
94-
# used for autoupdate
95-
version = v0.7.5
96-
97-
[lima]
98-
# upstream github releases aren't built for macOS 14, so we use homebrew binaries
99-
# from https://formulae.brew.sh/api/formula/lima.json
100-
darwin_x86_64 = https://ghcr.io/v2/homebrew/core/lima/blobs/sha256:c2e69a572afa3a3cf895643ede988c87dc0622dae4aebc539d5564d820845841
101-
darwin_x86_64_sha256 = c2e69a572afa3a3cf895643ede988c87dc0622dae4aebc539d5564d820845841
102-
darwin_arm64 = https://ghcr.io/v2/homebrew/core/lima/blobs/sha256:be8e2b92961eca2f862f1a994dbef367e86d36705a705ebfa16d21c7f1366c35
103-
darwin_arm64_sha256 = be8e2b92961eca2f862f1a994dbef367e86d36705a705ebfa16d21c7f1366c35
104-
linux_x86_64 = https://ghcr.io/v2/homebrew/core/lima/blobs/sha256:741e9c7345e15f04b8feaf5034868f00fc3ff792226c485ab2e7679803411e0c
105-
linux_x86_64_sha256 = 741e9c7345e15f04b8feaf5034868f00fc3ff792226c485ab2e7679803411e0c
72+
# upstream (https://nodejs.org/dist/) is not reliable enough
73+
# ask someone in team-devinfra to upload for you
74+
darwin_x86_64 = https://storage.googleapis.com/sentry-dev-infra-assets/node/node-v22.16.0-darwin-x64.tar.xz
75+
darwin_x86_64_sha256 = 5c34638f2c0e3f3aaa7b3a94b58304765a169730da1896ebba8515ea4d987a9c
76+
darwin_arm64 = https://storage.googleapis.com/sentry-dev-infra-assets/node/node-v22.16.0-darwin-arm64.tar.xz
77+
darwin_arm64_sha256 = aaf7fc3c936f1b359bc312b63638e41f258689ac2303966ad932cda18c54ea00
78+
linux_x86_64 = https://storage.googleapis.com/sentry-dev-infra-assets/node/node-v22.16.0-linux-x64.tar.xz
79+
linux_x86_64_sha256 = f4cb75bb036f0d0eddf6b79d9596df1aaab9ddccd6a20bf489be5abe9467e84e
10680
# used for autoupdate
107-
version = 0.23.2
81+
version = v22.16.0
10882
EOF
10983

11084
devenv sync
@@ -117,7 +91,7 @@ if [[ "$got" != "$expected" ]]; then
11791
fi
11892

11993
# devenv-bootstrap.sh overrides sentry devenv config.ini with this version
120-
expected="v20.13.1"
94+
expected="v22.16.0"
12195
# more rigorous check than node --version
12296
got=$(node -e 'console.log(process.version);')
12397
if [[ "$got" != "$expected" ]]; then

devenv/checks/dockerConfig.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,14 @@ def check() -> tuple[bool, str]:
3232
"cliPluginsExtraDirs exists, which overshadows the default plugin path",
3333
)
3434

35+
# Ensure the current context is set to colima
36+
current_context = config.get("currentContext", "")
37+
if current_context != "colima":
38+
return (
39+
False,
40+
f"currentContext is '{current_context}', should be 'colima'",
41+
)
42+
3543
return True, ""
3644

3745

@@ -43,6 +51,7 @@ def fix() -> tuple[bool, str]:
4351

4452
config.pop("credsStore", None)
4553
config.pop("cliPluginsExtraDirs", None)
54+
config["currentContext"] = "colima"
4655

4756
with open(os.path.expanduser("~/.docker/config.json"), "w") as f:
4857
json.dump(config, f)

tests/checks/test_dockerConfig.py

Lines changed: 41 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,12 +24,14 @@ def new_expanduser(s: str) -> str:
2424

2525

2626
def test_no_credsStore_ok(fake_config: pathlib.Path) -> None:
27-
fake_config.write_text("{}")
27+
fake_config.write_text('{"currentContext": "colima"}')
2828
assert dockerConfig.check() == (True, "")
2929

3030

3131
def test_binary_ok(fake_config: pathlib.Path) -> None:
32-
fake_config.write_text('{"credsStore": "example"}')
32+
fake_config.write_text(
33+
'{"credsStore": "example", "currentContext": "colima"}'
34+
)
3335
with mock.patch.object(shutil, "which", return_value="/fake/exe"):
3436
assert dockerConfig.check() == (True, "")
3537

@@ -47,10 +49,45 @@ def test_binary_missing(fake_config: pathlib.Path, name: str) -> None:
4749
def test_fix_credsStore(fake_config: pathlib.Path) -> None:
4850
fake_config.write_text('{"credsStore": "bad"}')
4951
assert dockerConfig.fix() == (True, "")
50-
assert fake_config.read_text() == "{}"
52+
assert fake_config.read_text() == '{"currentContext": "colima"}'
5153

5254

5355
def test_fix_cliPluginsExtraDirs(fake_config: pathlib.Path) -> None:
5456
fake_config.write_text('{"cliPluginsExtraDirs": ["foo/"]}')
5557
assert dockerConfig.fix() == (True, "")
56-
assert fake_config.read_text() == "{}"
58+
assert fake_config.read_text() == '{"currentContext": "colima"}'
59+
60+
61+
def test_currentContext_missing(fake_config: pathlib.Path) -> None:
62+
fake_config.write_text('{"auths": {}}')
63+
assert dockerConfig.check() == (
64+
False,
65+
"currentContext is '', should be 'colima'",
66+
)
67+
68+
69+
def test_currentContext_wrong(fake_config: pathlib.Path) -> None:
70+
fake_config.write_text('{"currentContext": "desktop"}')
71+
assert dockerConfig.check() == (
72+
False,
73+
"currentContext is 'desktop', should be 'colima'",
74+
)
75+
76+
77+
def test_currentContext_correct(fake_config: pathlib.Path) -> None:
78+
fake_config.write_text('{"currentContext": "colima"}')
79+
assert dockerConfig.check() == (True, "")
80+
81+
82+
def test_fix_currentContext_missing(fake_config: pathlib.Path) -> None:
83+
fake_config.write_text('{"auths": {}}')
84+
assert dockerConfig.fix() == (True, "")
85+
assert (
86+
fake_config.read_text() == '{"auths": {}, "currentContext": "colima"}'
87+
)
88+
89+
90+
def test_fix_currentContext_wrong(fake_config: pathlib.Path) -> None:
91+
fake_config.write_text('{"currentContext": "docker-desktop"}')
92+
assert dockerConfig.fix() == (True, "")
93+
assert fake_config.read_text() == '{"currentContext": "colima"}'

0 commit comments

Comments
 (0)