Skip to content

Commit

Permalink
debian/ubuntu: fix apt sources list location
Browse files Browse the repository at this point in the history
Signed-off-by: CrazyMax <[email protected]>
  • Loading branch information
crazy-max committed Dec 21, 2023
1 parent c4d7d31 commit 7634789
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 10 deletions.
4 changes: 4 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,10 @@ jobs:
image: ubuntu:22.04
typ: debian
allow-failure: false
-
image: ubuntu:24.04
typ: debian
allow-failure: false
-
image: redhat/ubi8
typ: rhel
Expand Down
24 changes: 16 additions & 8 deletions src/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -26,15 +26,23 @@ WORKDIR /work

FROM ${TEST_BASE_IMAGE} AS test-base-debian
ARG APT_MIRROR=deb.debian.org
RUN --mount=type=cache,target=/pkg-cache \
rm -rf /var/cache/apt/archives && \
ln -s /pkg-cache /var/cache/apt/archives && \
rm /etc/apt/apt.conf.d/docker-clean && \
echo 'Binary::apt::APT::Keep-Downloaded-Packages "1";' > /etc/apt/apt.conf.d/keep-downloads && \
touch /etc/apt/sources.list && \
sed -ri "s/(httpredir|deb).debian.org/${APT_MIRROR:-deb.debian.org}/g" /etc/apt/sources.list && \
sed -ri "s/(security).debian.org/${APT_MIRROR:-security.debian.org}/g" /etc/apt/sources.list && \
RUN --mount=type=cache,target=/pkg-cache <<EOT
set -ex
rm -rf /var/cache/apt/archives
ln -s /pkg-cache /var/cache/apt/archives
rm /etc/apt/apt.conf.d/docker-clean
echo 'Binary::apt::APT::Keep-Downloaded-Packages "1";' > /etc/apt/apt.conf.d/keep-downloads
aptsourcesfile=/etc/apt/sources.list
if [ -f /etc/apt/sources.list.d/debian.sources ]; then
aptsourcesfile=/etc/apt/sources.list.d/debian.sources
elif [ -f /etc/apt/sources.list.d/ubuntu.sources ]; then
aptsourcesfile=/etc/apt/sources.list.d/ubuntu.sources
fi
touch $aptsourcesfile
sed -ri "s/(httpredir|deb).debian.org/${APT_MIRROR:-deb.debian.org}/g" $aptsourcesfile
sed -ri "s/(security).debian.org/${APT_MIRROR:-security.debian.org}/g" $aptsourcesfile
apt update && apt install --no-install-recommends -y bats vim
EOT
WORKDIR /work

FROM ${TEST_BASE_IMAGE} AS test-base-rhel
Expand Down
14 changes: 12 additions & 2 deletions src/xx-apt
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,16 @@ checkpkg() {
apt show "$@"
}

aptsourcesfile() {
if [ -f /etc/apt/sources.list.d/debian.sources ]; then
echo /etc/apt/sources.list.d/debian.sources
elif [ -f /etc/apt/sources.list.d/ubuntu.sources ]; then
echo /etc/apt/sources.list.d/ubuntu.sources
else
echo /etc/apt/sources.list
fi
}

exitnolinux() {
if [ "${TARGETOS}" != "linux" ]; then
echo >&2 "skipping packages installation on ${XX_OS}"
Expand All @@ -37,7 +47,7 @@ case "${TARGETARCH}" in
riscv*)
case "${XX_VENDOR}" in
debian)
if ! grep "sid main" /etc/apt/sources.list >/dev/null; then
if ! grep "sid main" "$(aptsourcesfile)" >/dev/null; then
echo >&2 "skipping packages installation on ${XX_ARCH}. riscv64 currently only supported on sid"
exit 0
fi
Expand All @@ -64,7 +74,7 @@ fi
fixubuntusources() {
# fix all current sources to native arch
nativearch="$(TARGETPLATFORM="" TARGETPAIR="" TARGETARCH="" TARGETOS="" xx-info arch)"
sed -E "/arch=/! s/^(# )?(deb|deb-src) /\1\2 [arch=$nativearch] /" -i /etc/apt/sources.list
sed -E "/arch=/! s/^(# )?(deb|deb-src) /\1\2 [arch=$nativearch] /" -i "$(aptsourcesfile)"

if ! xx-info is-cross; then return; fi

Expand Down

0 comments on commit 7634789

Please sign in to comment.