Skip to content

Commit 7402730

Browse files
committed
Finish moving the dense RUN to a commented script
- Clarify and expand comments. - Adjust style for greater consistency within the script. - Have the script tolerate leading whitespace when it patches the Android runner script, since it looks like future releases of `cross` may have it undented under an `if` check for the Android version (not all versions have a C++ library in the NDK). - Move the script into a subdirectory that will be used as context. - Replace the old `RUN` step with a command to run the script. - Modify the build command in the `justfile` to use the context.
1 parent 572e63d commit 7402730

File tree

3 files changed

+36
-53
lines changed

3 files changed

+36
-53
lines changed

etc/docker/Dockerfile.test-cross

Lines changed: 3 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1,38 +1,7 @@
11
ARG TARGET
2-
32
FROM ghcr.io/cross-rs/${TARGET}:latest
43

54
ARG TARGET
6-
7-
RUN set -uC && \
8-
export DEBIAN_FRONTEND=noninteractive TZ=UTC && \
9-
apt-get update && \
10-
apt-get install --no-install-recommends -y apt-utils && \
11-
apt-get install --no-install-recommends -y apt-transport-https dpkg-dev gnupg && \
12-
type dpkg-architecture && \
13-
apt_suffix= && \
14-
if target_arch="$(dpkg-architecture --host-type "$TARGET" --query DEB_HOST_ARCH)"; then \
15-
dpkg --add-architecture "$target_arch" && \
16-
apt_suffix=":$target_arch"; \
17-
fi && \
18-
release="$(sed -n 's/^VERSION_CODENAME=//p' /etc/os-release)" && \
19-
echo "deb https://ppa.launchpadcontent.net/git-core/ppa/ubuntu $release main" \
20-
>/etc/apt/sources.list.d/git-core-ubuntu-ppa.list && \
21-
apt-key adv --keyserver keyserver.ubuntu.com \
22-
--recv-keys F911AB184317630C59970973E363C90F8F1B6217 && \
23-
apt-get update && \
24-
apt-get purge --autoremove -y git && \
25-
apt-get install --no-install-recommends -y "libc6$apt_suffix" "libcurl3-gnutls$apt_suffix" \
26-
"libexpat1$apt_suffix" "libpcre2-8-0$apt_suffix" "zlib1g$apt_suffix" perl liberror-perl \
27-
git-man ca-certificates cmake "curl$apt_suffix" file jq "libc-dev$apt_suffix" \
28-
"libssl-dev$apt_suffix" patch pkgconf && \
29-
mkdir /tmp/dl && chown _apt /tmp/dl && \
30-
(cd /tmp/dl && apt-get download "git$apt_suffix") && \
31-
dpkg --ignore-depends="perl$apt_suffix,liberror-perl$apt_suffix" -i /tmp/dl/git[-_]*.deb && \
32-
git version --build-options && git="$(command -v git)" && file -- "$git" && \
33-
apt-get clean && rm -rf /tmp/dl /var/lib/apt/lists/* && \
34-
if test -f /android-runner; then \
35-
sed -i.orig 's/^export LD_PRELOAD=/test "${NO_PRELOAD_CXX:-0}" != 0 || &/' \
36-
/android-runner; \
37-
fi && \
38-
git config --system gitoxide.imaginary.arbitraryVariable arbitraryValue
5+
COPY customize.sh /usr/local/bin/
6+
RUN chmod +x /usr/local/bin/customize.sh && \
7+
/usr/local/bin/customize.sh "$TARGET"

etc/docker/customize-test-cross-image.sh renamed to etc/docker/test-cross-context/customize.sh

Lines changed: 30 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
set -euxC
33

44
target="$1"
5+
test -n "$target"
56

67
# Arrange for the indirect `tzdata` dependency to be installed and configured
78
# without prompting for the time zone. (Passing `-y` is not enough.)
@@ -14,16 +15,30 @@ apt-get install --no-install-recommends -y apt-utils
1415
apt-get install --no-install-recommends -y apt-transport-https dpkg-dev gnupg
1516
type dpkg-architecture # Make sure we really have this.
1617

17-
# Decide what architecture to use for `git`, shared libraries for gitoxide when
18-
# attempting to build `max`, and shared libraries used by `git` itself.
18+
# Decide what architecture to use for `git`, shared libraries `git` links to,
19+
# and shared libraries gitoxide links to when building `max`. Instead of this
20+
# custom logic, we could use `$CROSS_DEB_ARCH`, which `cross` tries to provide
21+
# (https://github.com/cross-rs/cross/blob/v0.2.5/src/lib.rs#L268), and which is
22+
# available for roughly the same architectures where this logic gets a nonempty
23+
# value. But using `$CROSS_DEB_ARCH` may make it harder to build and test the
24+
# image manually. In particular, if it is not passed, we would conclude that we
25+
# should install the versions of those packages with the host's architecture.
1926
apt_suffix=
20-
if target_arch="$(dpkg-architecture --host-type "$target" --query DEB_HOST_ARCH)"; then
27+
if target_arch="$(dpkg-architecture --host-type "$target" --query DEB_HOST_ARCH)"
28+
then
2129
dpkg --add-architecture "$target_arch"
2230
apt_suffix=":$target_arch"
31+
printf 'INFO: Using target architecture for `git` and libs in container.\n'
32+
printf 'INFO: This architecture is %s.\n' "$target_arch"
33+
else
34+
apt_suffix=''
35+
printf 'WARNING: Using HOST architecture for `git` and libs in container.\n'
2336
fi
2437

25-
# Add the git-core PPA manually. (Faster than installing `add-apt-repository`.)
38+
# Get release codename. Like `lsb_release -sc`. (`lsb_release` may be absent.)
2639
release="$(sed -n 's/^VERSION_CODENAME=//p' /etc/os-release)"
40+
41+
# Add the git-core PPA manually. (Faster than installing `add-apt-repository`.)
2742
echo "deb https://ppa.launchpadcontent.net/git-core/ppa/ubuntu $release main" \
2843
>/etc/apt/sources.list.d/git-core-ubuntu-ppa.list
2944
apt-key adv --keyserver keyserver.ubuntu.com \
@@ -94,19 +109,17 @@ file -- "$git"
94109
apt-get clean
95110
rm -rf /tmp/dl /var/lib/apt/lists/*
96111

97-
# If this is an Android-related image or otherwise has a runner script `cross`
98-
# uses for Android, then patch the script to add the ability to suppress its
99-
# customization of `LD_PRELOAD`. This runner script sets `LD_PRELOAD` to the
100-
# path of `libc++_shared.so` in the vendored Android NDK. But this causes a
101-
# problem for us because, when a non-Android (i.e. a host-architecture) program
102-
# is run, `ld.so` shows a message about the "wrong ELF class". Such programs
103-
# can still run, but when we make an assertion about, parse, or otherwise rely
104-
# on their output to standard error, we get test failures. (That especially
105-
# affects fixtures.) This change lets us pass `NO_PRELOAD_CXX=1` to avoid that.
106-
if test -f /android-runner; then
107-
sed -i.orig 's/^export LD_PRELOAD=/test "${NO_PRELOAD_CXX:-0}" != 0 || &/'
108-
/android-runner
109-
fi
112+
# If this image has a runner script `cross` uses for Android, patch the script
113+
# to add the ability to suppress its customization of `LD_PRELOAD`. The runner
114+
# script sets `LD_PRELOAD` to the path of `libc++_shared.so` in the Android NDK
115+
# (https://github.com/cross-rs/cross/blob/v0.2.5/docker/android-runner#L34).
116+
# But this causes a problem for us. When a host-architecture program is run,
117+
# `ld.so` shows a message about the "wrong ELF class". Such programs can still
118+
# run, but when we rely on their specific output to stderr, fixtures and tests
119+
# fail. The change we make here lets us set `NO_PRELOAD_CXX=1` to avoid that.
120+
runner=/android-runner
121+
patch='s/^[[:blank:]]*export LD_PRELOAD=/test "${NO_PRELOAD_CXX:-0}" != 0 || &/'
122+
if test -f "$runner"; then sed -i.orig "$patch" -- "$runner"; fi
110123

111124
# Ensure a nonempty Git `system` scope (for the `installation_config` tests).
112125
git config --system gitoxide.imaginary.arbitraryVariable arbitraryValue

justfile

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -226,8 +226,9 @@ journey-tests-async: dbg
226226

227227
# Build a customized `cross` container image for testing
228228
cross-image target:
229-
docker build --build-arg "TARGET={{ target }}" -t "cross-rs-gitoxide:{{ target }}" \
230-
- <etc/docker/Dockerfile.test-cross
229+
docker build --build-arg "TARGET={{ target }}" \
230+
-t "cross-rs-gitoxide:{{ target }}" \
231+
-f etc/docker/Dockerfile.test-cross etc/docker/test-cross-context
231232

232233
# Test another platform with `cross`
233234
cross-test target *cargo-test-args: (cross-image target)

0 commit comments

Comments
 (0)