Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

debian/ubuntu: fix apt sources list location #132

Merged
merged 4 commits into from
Jan 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,9 @@ ARG TARGETPLATFORM
RUN xx-apt-get install -y libc6-dev zlib1g-dev
```

> [!NOTE]
> `xx-apt --print-source-file` can be used to print the path of the main [Apt sources configuration file](https://manpages.debian.org/bookworm/apt/sources.list.5.en.html)

Installing two meta-libraries, `xx-c-essentials`, `xx-cxx-essentials` is also allowed that expand the minimum necessary packages for either base image.

## `xx-verify` - Verifying compilation results
Expand All @@ -146,8 +149,7 @@ RUN xx-clang --static -o /out/myapp app.c && \
xx-verify --static /out/myapp
```

> **Note**
>
> [!NOTE]
> `XX_VERIFY_STATIC=1` environment variable can be defined to make `xx-verify`
> always verify that the compiler produced a static binary.

Expand Down Expand Up @@ -372,8 +374,7 @@ RUN cargo build --target=$(xx-cargo --print-target-triple) --release --target-di
xx-verify ./build/$(xx-cargo --print-target-triple)/release/hello_cargo
```

> **Note**
>
> [!NOTE]
> `xx-cargo --print-target-triple` does not always have the same value as
> `xx-clang --print-target-triple`. This is because prebuilt Rust and C
> libraries sometimes use a different value.
Expand All @@ -400,8 +401,7 @@ RUN --mount=type=cache,target=/root/.cargo/git/db \
xx-verify ./build/$(xx-cargo --print-target-triple)/release/hello_cargo
```

> **Note**
>
> [!NOTE]
> By calling `cargo fetch` before `ARG TARGETPLATFORM` your packages are
> fetched only once for the whole build while the building happens separately
> for each target architecture.
Expand Down
1 change: 0 additions & 1 deletion docker-bake.hcl
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ target "test-alpine" {
target "test-debian" {
inherits = ["test-src"]
args = {
APT_MIRROR = "cdn-fastly.deb.debian.org"
TEST_BASE_TYPE = "debian"
TEST_BASE_IMAGE = "debian:bookworm"
}
Expand Down
4 changes: 0 additions & 4 deletions src/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -25,15 +25,11 @@ RUN --mount=type=cache,target=/pkg-cache \
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 && \
apt update && apt install --no-install-recommends -y bats vim
WORKDIR /work

Expand Down
9 changes: 9 additions & 0 deletions src/test-apt.bats
Original file line number Diff line number Diff line change
Expand Up @@ -219,3 +219,12 @@ load 'assert'
run apt show wget-notexist
assert_failure
}

@test "print-source-file" {
run xx-apt --print-source-file
assert_success
assert_output --partial "/etc/apt/sources.list"

run test -e "$(xx-apt --print-source-file)"
assert_success
}
28 changes: 26 additions & 2 deletions src/xx-apt
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,37 @@ 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}"
exit 0
fi
}

n=$#
for a in "$@"; do
if [ $# = $n ]; then set --; fi
case "$a" in
"--print-source-file")
aptsourcesfile
exit 0
;;
*)
set -- "$@" "$a"
;;
esac
done

# these are not supported yet
case "${TARGETARCH}" in
mips*)
Expand All @@ -37,7 +61,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 +88,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
Loading