|
1 | 1 | from argparse import ArgumentParser |
2 | 2 | from pathlib import Path |
3 | | -import json |
4 | | -from urllib.request import urlopen |
5 | 3 |
|
6 | 4 | import i18n |
7 | 5 |
|
@@ -105,13 +103,6 @@ def install(): |
105 | 103 | docker_compose.download( |
106 | 104 | install_path / "docker-compose.yml", version=args.version |
107 | 105 | ) |
108 | | - location = check_location() |
109 | | - try: |
110 | | - docker_config = get_docker_config() |
111 | | - except Exception: |
112 | | - print_utils.warning_translate("install.fail-to-load-docker-config") |
113 | | - else: |
114 | | - update_docker_mirror(location=location, docker_config=docker_config) |
115 | 106 |
|
116 | 107 | print_utils.translate("install.downloading-images") |
117 | 108 | docker_compose.run(install_path, ["pull"]) |
@@ -197,45 +188,3 @@ def _parse_args(): |
197 | 188 | ) |
198 | 189 |
|
199 | 190 | return subcommand_parse_args(parser) |
200 | | - |
201 | | - |
202 | | -def check_location() -> str: |
203 | | - url = "http://ipinfo.io/json" |
204 | | - try: |
205 | | - response = urlopen(url, timeout=5) |
206 | | - except Exception: |
207 | | - return "US" |
208 | | - data = json.load(response) |
209 | | - return data["country"] |
210 | | - |
211 | | - |
212 | | -def get_docker_config() -> dict: |
213 | | - with open("/etc/docker/daemon.json") as docker_config_file: |
214 | | - docker_config = json.load(docker_config_file) |
215 | | - return docker_config |
216 | | - |
217 | | - |
218 | | -def update_docker_mirror(docker_config: dict, location: str): |
219 | | - docker_mirror_host = {"CN": "USTC", "US": "Docker Hub"} |
220 | | - if location == "CN" and ( |
221 | | - "registry-mirrors" not in docker_config.keys() |
222 | | - or docker_config["registry-mirrors"] |
223 | | - != ["https://docker.mirrors.ustc.edu.cn/"] |
224 | | - ): |
225 | | - docker_config["registry-mirrors"] = [ |
226 | | - "https://docker.mirrors.ustc.edu.cn/" |
227 | | - ] |
228 | | - elif location != "CN" and "registry-mirrors" in docker_config.keys(): |
229 | | - del docker_config["registry-mirrors"] |
230 | | - else: |
231 | | - return |
232 | | - if print_utils.ask_yes_no( |
233 | | - "install.change-docker-mirror", |
234 | | - location=location, |
235 | | - mirror_host=docker_mirror_host[location], |
236 | | - ): |
237 | | - with open("/etc/docker/daemon.json", "w") as docker_config_file: |
238 | | - json.dump( |
239 | | - docker_config, docker_config_file, indent=4, sort_keys=True |
240 | | - ) |
241 | | - os_utils.restart_docker() |
0 commit comments