Skip to content

Commit

Permalink
[improve][build] Change UBUNTU_MIRROR default value (apache#21520)
Browse files Browse the repository at this point in the history
  • Loading branch information
lhotari authored Nov 7, 2023
1 parent eebd821 commit 44abba9
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 13 deletions.
26 changes: 18 additions & 8 deletions build/pulsar_ci_tool.sh
Original file line number Diff line number Diff line change
Expand Up @@ -55,22 +55,32 @@ function ci_dependency_check() {
_ci_mvn -Pmain,skip-all,skipDocker,owasp-dependency-check initialize verify -pl '!pulsar-client-tools-test' "$@"
}

function ci_pick_ubuntu_mirror() {
echo "Choosing fastest up-to-date ubuntu mirror based on download speed..."
UBUNTU_MIRROR=$({
# Finds fastest up-to-date ubuntu mirror based on download speed
function ci_find_fast_ubuntu_mirror() {
local ubuntu_release=${1:-"$(lsb_release -c 2>/dev/null | cut -f2 || echo "jammy")"}
local ubuntu_arch=${2:-"$(dpkg --print-architecture 2>/dev/null || echo "amd64")"}
{
# choose mirrors that are up-to-date by checking the Last-Modified header for
{
# randomly choose up to 10 mirrors using http:// protocol
# (https isn't supported in docker containers that don't have ca-certificates installed)
curl -s http://mirrors.ubuntu.com/mirrors.txt | grep '^http://' | shuf -n 10
# also consider Azure's Ubuntu mirror
echo http://azure.archive.ubuntu.com/ubuntu/
} | xargs -I {} sh -c 'echo "$(curl -m 5 -sI {}dists/$(lsb_release -c | cut -f2)-security/Contents-$(dpkg --print-architecture).gz|sed s/\\r\$//|grep Last-Modified|awk -F": " "{ print \$2 }" | LANG=C date -f- -u +%s)" "{}"' | sort -rg | awk '{ if (NR==1) TS=$1; if ($1 == TS) print $2 }'
} | xargs -I {} sh -c "ubuntu_release=$ubuntu_release ubuntu_arch=$ubuntu_arch;"'echo "$(curl -m 5 -sI {}dists/${ubuntu_release}/Contents-${ubuntu_arch}.gz|sed s/\\r\$//|grep Last-Modified|awk -F": " "{ print \$2 }" | LANG=C date -f- -u +%s)" "{}"' | sort -rg | awk '{ if (NR==1) TS=$1; if ($1 == TS) print $2 }'
} | xargs -I {} sh -c 'echo `curl -r 0-102400 -m 5 -s -w %{speed_download} -o /dev/null {}ls-lR.gz` {}' \
|sort -g -r |head -1| awk '{ print $2 }')
|sort -g -r |head -1| awk '{ print $2 }'
}

function ci_pick_ubuntu_mirror() {
echo "Choosing fastest up-to-date ubuntu mirror based on download speed..."
UBUNTU_MIRROR=$(ci_find_fast_ubuntu_mirror)
if [ -z "$UBUNTU_MIRROR" ]; then
# fallback to full mirrors list
UBUNTU_MIRROR="mirror://mirrors.ubuntu.com/mirrors.txt"
# fallback to no mirror
UBUNTU_MIRROR="http://archive.ubuntu.com/ubuntu/"
UBUNTU_SECURITY_MIRROR="http://security.ubuntu.com/ubuntu/"
else
UBUNTU_SECURITY_MIRROR="${UBUNTU_MIRROR}"
fi
OLD_MIRROR=$(cat /etc/apt/sources.list | grep '^deb ' | head -1 | awk '{ print $2 }')
echo "Picked '$UBUNTU_MIRROR'. Current mirror is '$OLD_MIRROR'."
Expand All @@ -81,7 +91,7 @@ function ci_pick_ubuntu_mirror() {
# set the chosen mirror also in the UBUNTU_MIRROR and UBUNTU_SECURITY_MIRROR environment variables
# that can be used by docker builds
export UBUNTU_MIRROR
export UBUNTU_SECURITY_MIRROR=$UBUNTU_MIRROR
export UBUNTU_SECURITY_MIRROR
# make environment variables available for later GitHub Actions steps
if [ -n "$GITHUB_ENV" ]; then
echo "UBUNTU_MIRROR=$UBUNTU_MIRROR" >> $GITHUB_ENV
Expand Down
4 changes: 2 additions & 2 deletions docker/pulsar/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -52,12 +52,12 @@ RUN chmod g+w /pulsar/trino
FROM ubuntu:22.04

ARG DEBIAN_FRONTEND=noninteractive
ARG UBUNTU_MIRROR=mirror://mirrors.ubuntu.com/mirrors.txt
ARG UBUNTU_MIRROR=http://archive.ubuntu.com/ubuntu/
ARG UBUNTU_SECURITY_MIRROR=http://security.ubuntu.com/ubuntu/
ARG JDK_MAJOR_VERSION=17

# Install some utilities
RUN sed -i -e "s|http://archive\.ubuntu\.com/ubuntu/|${UBUNTU_MIRROR:-mirror://mirrors.ubuntu.com/mirrors.txt}|g" \
RUN sed -i -e "s|http://archive\.ubuntu\.com/ubuntu/|${UBUNTU_MIRROR:-http://archive.ubuntu.com/ubuntu/}|g" \
-e "s|http://security\.ubuntu\.com/ubuntu/|${UBUNTU_SECURITY_MIRROR:-http://security.ubuntu.com/ubuntu/}|g" /etc/apt/sources.list \
&& echo 'Acquire::http::Timeout "30";\nAcquire::ftp::Timeout "30";\nAcquire::Retries "3";' > /etc/apt/apt.conf.d/99timeout_and_retries \
&& apt-get update \
Expand Down
2 changes: 1 addition & 1 deletion docker/pulsar/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@
</dependencies>

<properties>
<UBUNTU_MIRROR>mirror://mirrors.ubuntu.com/mirrors.txt</UBUNTU_MIRROR>
<UBUNTU_MIRROR>http://archive.ubuntu.com/ubuntu/</UBUNTU_MIRROR>
<UBUNTU_SECURITY_MIRROR>http://security.ubuntu.com/ubuntu/</UBUNTU_SECURITY_MIRROR>
<IMAGE_JDK_MAJOR_VERSION>17</IMAGE_JDK_MAJOR_VERSION>
</properties>
Expand Down
4 changes: 2 additions & 2 deletions tests/docker-images/java-test-image/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,11 @@ RUN chmod a+rx /pulsar/bin/*
WORKDIR /pulsar

ARG DEBIAN_FRONTEND=noninteractive
ARG UBUNTU_MIRROR=mirror://mirrors.ubuntu.com/mirrors.txt
ARG UBUNTU_MIRROR=http://archive.ubuntu.com/ubuntu/
ARG UBUNTU_SECURITY_MIRROR=http://security.ubuntu.com/ubuntu/
ARG JDK_MAJOR_VERSION=17

RUN sed -i -e "s|http://archive\.ubuntu\.com/ubuntu/|${UBUNTU_MIRROR:-mirror://mirrors.ubuntu.com/mirrors.txt}|g" \
RUN sed -i -e "s|http://archive\.ubuntu\.com/ubuntu/|${UBUNTU_MIRROR:-http://archive.ubuntu.com/ubuntu/}|g" \
-e "s|http://security\.ubuntu\.com/ubuntu/|${UBUNTU_SECURITY_MIRROR:-http://security.ubuntu.com/ubuntu/}|g" /etc/apt/sources.list \
&& apt-get update \
&& apt-get -y dist-upgrade \
Expand Down

0 comments on commit 44abba9

Please sign in to comment.