@@ -41,7 +41,56 @@ ARG wal_g_release=3.0.5
4141
4242FROM ubuntu:noble as base
4343
44- RUN apt update -y && apt install -y \
44+ # Create reusable apt mirror fallback function
45+ RUN echo '#!/bin/bash\n\
46+ apt_update_with_fallback() {\n\
47+ local sources_file="/etc/apt/sources.list.d/ubuntu.sources"\n\
48+ local max_attempts=2\n\
49+ local attempt=1\n\
50+ local mirrors="archive.ubuntu.com us.archive.ubuntu.com"\n\
51+ \n\
52+ for mirror in $mirrors; do\n\
53+ echo "========================================="\n\
54+ echo "Attempting apt-get update with mirror: ${mirror}"\n\
55+ echo "Attempt ${attempt} of ${max_attempts}"\n\
56+ echo "========================================="\n\
57+ \n\
58+ if [ -f "${sources_file}" ]; then\n\
59+ sed -i "s|http://[^/]*/ubuntu/|http://${mirror}/ubuntu/|g" "${sources_file}"\n\
60+ fi\n\
61+ \n\
62+ if timeout 300 apt-get update 2>&1; then\n\
63+ echo "========================================="\n\
64+ echo "✓ Successfully updated apt cache using mirror: ${mirror}"\n\
65+ echo "========================================="\n\
66+ return 0\n\
67+ else\n\
68+ local exit_code=$?\n\
69+ echo "========================================="\n\
70+ echo "✗ Failed to update using mirror: ${mirror}"\n\
71+ echo "Exit code: ${exit_code}"\n\
72+ echo "========================================="\n\
73+ \n\
74+ apt-get clean\n\
75+ rm -rf /var/lib/apt/lists/*\n\
76+ \n\
77+ if [ ${attempt} -lt ${max_attempts} ]; then\n\
78+ local sleep_time=$((attempt * 5))\n\
79+ echo "Waiting ${sleep_time} seconds before trying next mirror..."\n\
80+ sleep ${sleep_time}\n\
81+ fi\n\
82+ fi\n\
83+ \n\
84+ attempt=$((attempt + 1))\n\
85+ done\n\
86+ \n\
87+ echo "========================================="\n\
88+ echo "ERROR: All mirror tiers failed after ${max_attempts} attempts"\n\
89+ echo "========================================="\n\
90+ return 1\n\
91+ }' > /usr/local/bin/apt-update-fallback.sh && chmod +x /usr/local/bin/apt-update-fallback.sh
92+
93+ RUN bash -c 'source /usr/local/bin/apt-update-fallback.sh && apt_update_with_fallback' && apt install -y \
4594 curl \
4695 gnupg \
4796 lsb-release \
@@ -100,13 +149,13 @@ RUN chown -R postgres:postgres /usr/lib/postgresql
100149RUN ln -sf /usr/lib/postgresql/share/postgresql/timezonesets /usr/share/postgresql/timezonesets
101150
102151
103- RUN apt-get update && \
152+ RUN bash -c 'source /usr/local/bin/apt- update-fallback.sh && apt_update_with_fallback' && \
104153 apt-get install -y --no-install-recommends tzdata
105154
106155RUN ln -fs /usr/share/zoneinfo/Etc/UTC /etc/localtime && \
107156 dpkg-reconfigure --frontend noninteractive tzdata
108157
109- RUN apt-get update && \
158+ RUN bash -c 'source /usr/local/bin/apt- update-fallback.sh && apt_update_with_fallback' && \
110159 apt-get install -y --no-install-recommends \
111160 build-essential \
112161 checkinstall \
@@ -148,7 +197,7 @@ WORKDIR /
148197FROM base as gosu
149198ARG TARGETARCH
150199# Install dependencies
151- RUN apt-get update && apt-get install -y --no-install-recommends \
200+ RUN bash -c 'source /usr/local/bin/apt- update-fallback.sh && apt_update_with_fallback' && apt-get install -y --no-install-recommends \
152201 gnupg \
153202 ca-certificates \
154203 && rm -rf /var/lib/apt/lists/*
@@ -233,7 +282,7 @@ ENV POSTGRES_HOST=/var/run/postgresql
233282ENV POSTGRES_USER=supabase_admin
234283ENV POSTGRES_DB=postgres
235284ENV POSTGRES_INITDB_ARGS="--allow-group-access --locale-provider=icu --encoding=UTF-8 --icu-locale=en_US.UTF-8"
236- RUN apt-get update && apt-get install -y --no-install-recommends \
285+ RUN bash -c 'source /usr/local/bin/apt- update-fallback.sh && apt_update_with_fallback' && apt-get install -y --no-install-recommends \
237286 locales \
238287 && rm -rf /var/lib/apt/lists/* && \
239288 localedef -i en_US -c -f UTF-8 -A /usr/share/locale/locale.alias en_US.UTF-8 \
0 commit comments