File tree Expand file tree Collapse file tree 2 files changed +26
-3
lines changed Expand file tree Collapse file tree 2 files changed +26
-3
lines changed Original file line number Diff line number Diff line change @@ -25,12 +25,16 @@ RUN apt update && apt install -y \
2525 patch \
2626 pkg-config \
2727 python3.12 \
28- python3-aiohttp \
28+ python3-pip \
2929 libpython3-dev \
3030 texinfo \
3131 wget \
3232 xz-utils
3333
34+ # We require aiohttp >= 3.12 (For client middleware support), which is newer than the currently
35+ # available python3-aiohttp's version in Ubuntu.
36+ RUN python3.12 -m pip install --break-system-packages aiohttp
37+
3438COPY src/docker_utils/download_musl_toolchains.py .
3539RUN python3.12 -u download_musl_toolchains.py
3640
Original file line number Diff line number Diff line change 11#!/usr/bin/env python3.12
22
3- from typing import List
43from pathlib import Path
4+ from typing import List
55
66import tarfile
77import tempfile
1010import asyncio
1111
1212import aiohttp
13+ import aiohttp .client_exceptions
1314
1415ARCHS = {
1516 "x86_64" : "https://more.musl.cc/11/x86_64-linux-musl/x86_64-linux-musl-cross.tgz" ,
2324MUSL_TOOLCHAINS_DIR = Path ("/musl-toolchains" )
2425ENTRYPOINT = Path ("/entrypoint.sh" )
2526
27+ NUM_RETRIES = 5
28+ RETRY_WAIT = 2
29+
30+ # Basically copied from aiohttp docs: Simple Retry Middleware
31+ async def retry_middleware (req : aiohttp .ClientRequest , handler : aiohttp .ClientHandlerType ) -> aiohttp .ClientResponse :
32+ for _ in range (NUM_RETRIES ):
33+ try :
34+ resp = await handler (req )
35+ if resp .ok :
36+ return resp
37+ except aiohttp .client_exceptions .ConnectionTimeoutError :
38+ pass
39+
40+ await asyncio .sleep (RETRY_WAIT )
41+
42+ return resp
43+
2644async def download_file (url : str , filename : str ):
27- async with aiohttp .ClientSession () as session :
45+ async with aiohttp .ClientSession (middlewares = ( retry_middleware ,) ) as session :
2846 async with session .get (url ) as response :
47+ response .raise_for_status ()
2948 with open (filename , 'wb' ) as f :
3049 async for data in response .content .iter_chunked (CHUNK_SIZE ):
3150 f .write (data )
You can’t perform that action at this time.
0 commit comments