Skip to content

Commit 408623e

Browse files
authored
fix: try to use mirror fallbacks for docker images (#1942)
1 parent 57724b1 commit 408623e

File tree

3 files changed

+162
-15
lines changed

3 files changed

+162
-15
lines changed

Dockerfile-15

Lines changed: 54 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,56 @@ ARG wal_g_release=2.0.1
4040

4141
FROM ubuntu:noble as base
4242

43-
RUN apt update -y && apt install -y \
43+
# Create reusable apt mirror fallback function
44+
RUN echo '#!/bin/bash\n\
45+
apt_update_with_fallback() {\n\
46+
local sources_file="/etc/apt/sources.list.d/ubuntu.sources"\n\
47+
local max_attempts=2\n\
48+
local attempt=1\n\
49+
local mirrors="archive.ubuntu.com us.archive.ubuntu.com"\n\
50+
\n\
51+
for mirror in $mirrors; do\n\
52+
echo "========================================="\n\
53+
echo "Attempting apt-get update with mirror: ${mirror}"\n\
54+
echo "Attempt ${attempt} of ${max_attempts}"\n\
55+
echo "========================================="\n\
56+
\n\
57+
if [ -f "${sources_file}" ]; then\n\
58+
sed -i "s|http://[^/]*/ubuntu/|http://${mirror}/ubuntu/|g" "${sources_file}"\n\
59+
fi\n\
60+
\n\
61+
if timeout 300 apt-get update 2>&1; then\n\
62+
echo "========================================="\n\
63+
echo "✓ Successfully updated apt cache using mirror: ${mirror}"\n\
64+
echo "========================================="\n\
65+
return 0\n\
66+
else\n\
67+
local exit_code=$?\n\
68+
echo "========================================="\n\
69+
echo "✗ Failed to update using mirror: ${mirror}"\n\
70+
echo "Exit code: ${exit_code}"\n\
71+
echo "========================================="\n\
72+
\n\
73+
apt-get clean\n\
74+
rm -rf /var/lib/apt/lists/*\n\
75+
\n\
76+
if [ ${attempt} -lt ${max_attempts} ]; then\n\
77+
local sleep_time=$((attempt * 5))\n\
78+
echo "Waiting ${sleep_time} seconds before trying next mirror..."\n\
79+
sleep ${sleep_time}\n\
80+
fi\n\
81+
fi\n\
82+
\n\
83+
attempt=$((attempt + 1))\n\
84+
done\n\
85+
\n\
86+
echo "========================================="\n\
87+
echo "ERROR: All mirror tiers failed after ${max_attempts} attempts"\n\
88+
echo "========================================="\n\
89+
return 1\n\
90+
}' > /usr/local/bin/apt-update-fallback.sh && chmod +x /usr/local/bin/apt-update-fallback.sh
91+
92+
RUN bash -c 'source /usr/local/bin/apt-update-fallback.sh && apt_update_with_fallback' && apt install -y \
4493
curl \
4594
gnupg \
4695
lsb-release \
@@ -96,13 +145,13 @@ RUN chown -R postgres:postgres /usr/lib/postgresql
96145
RUN ln -sf /usr/lib/postgresql/share/postgresql/timezonesets /usr/share/postgresql/timezonesets
97146

98147

99-
RUN apt-get update && \
148+
RUN bash -c 'source /usr/local/bin/apt-update-fallback.sh && apt_update_with_fallback' && \
100149
apt-get install -y --no-install-recommends tzdata
101150

102151
RUN ln -fs /usr/share/zoneinfo/Etc/UTC /etc/localtime && \
103152
dpkg-reconfigure --frontend noninteractive tzdata
104153

105-
RUN apt-get update && \
154+
RUN bash -c 'source /usr/local/bin/apt-update-fallback.sh && apt_update_with_fallback' && \
106155
apt-get install -y --no-install-recommends \
107156
build-essential \
108157
checkinstall \
@@ -143,7 +192,7 @@ WORKDIR /
143192
FROM base as gosu
144193
ARG TARGETARCH
145194
# Install dependencies
146-
RUN apt-get update && apt-get install -y --no-install-recommends \
195+
RUN bash -c 'source /usr/local/bin/apt-update-fallback.sh && apt_update_with_fallback' && apt-get install -y --no-install-recommends \
147196
gnupg \
148197
ca-certificates \
149198
&& rm -rf /var/lib/apt/lists/*
@@ -219,7 +268,7 @@ EXPOSE 5432
219268
ENV POSTGRES_HOST=/var/run/postgresql
220269
ENV POSTGRES_USER=supabase_admin
221270
ENV POSTGRES_DB=postgres
222-
RUN apt-get update && apt-get install -y --no-install-recommends \
271+
RUN bash -c 'source /usr/local/bin/apt-update-fallback.sh && apt_update_with_fallback' && apt-get install -y --no-install-recommends \
223272
locales \
224273
&& rm -rf /var/lib/apt/lists/* && \
225274
localedef -i en_US -c -f UTF-8 -A /usr/share/locale/locale.alias en_US.UTF-8 \

Dockerfile-17

Lines changed: 54 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,56 @@ ARG wal_g_release=3.0.5
4141

4242
FROM 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
100149
RUN 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

106155
RUN 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 /
148197
FROM base as gosu
149198
ARG 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
233282
ENV POSTGRES_USER=supabase_admin
234283
ENV POSTGRES_DB=postgres
235284
ENV 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 \

Dockerfile-orioledb-17

Lines changed: 54 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,56 @@ ARG wal_g_release=3.0.5
4141

4242
FROM 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
100149
RUN 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

106155
RUN 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 /
148197
FROM base as gosu
149198
ARG 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/*
@@ -244,7 +293,7 @@ ENV POSTGRES_HOST=/var/run/postgresql
244293
ENV POSTGRES_USER=supabase_admin
245294
ENV POSTGRES_DB=postgres
246295
ENV POSTGRES_INITDB_ARGS="--allow-group-access --locale-provider=icu --encoding=UTF-8 --icu-locale=en_US.UTF-8"
247-
RUN apt-get update && apt-get install -y --no-install-recommends \
296+
RUN bash -c 'source /usr/local/bin/apt-update-fallback.sh && apt_update_with_fallback' && apt-get install -y --no-install-recommends \
248297
locales \
249298
&& rm -rf /var/lib/apt/lists/* && \
250299
localedef -i en_US -c -f UTF-8 -A /usr/share/locale/locale.alias en_US.UTF-8 \

0 commit comments

Comments
 (0)