History

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.

Eliah Kagan committed 1 year ago

Commit c3ea44b1 parent a203bf43 files · +36 −53Browse files

Unified · Split

3 files
  1. etc/docker/Dockerfile.test-cross +3 −34
  2. etc/docker/test-cross-context/customize.sh +30 −17
  3. justfile +3 −2
etc/docker/Dockerfile.test-cross+3−34
@@ -1,38 +1,7 @@
1ARG TARGET1ARG TARGET
2
3FROM ghcr.io/cross-rs/${TARGET}:latest2FROM ghcr.io/cross-rs/${TARGET}:latest
4 3
5ARG TARGET4ARG TARGET
6 5COPY customize.sh /usr/local/bin/
7RUN set -uC && \6RUN chmod +x /usr/local/bin/customize.sh && \
8 export DEBIAN_FRONTEND=noninteractive TZ=UTC && \7 /usr/local/bin/customize.sh "$TARGET"
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
etc/docker/test-cross-context/customize.shrenamed from etc/docker/customize-test-cross-image.sh+30−17
@@ -2,6 +2,7 @@ · 1 unmodified line
2set -euxC2set -euxC
3 3
4target="$1"4target="$1"
5test -n "$target"
5 6
6# Arrange for the indirect `tzdata` dependency to be installed and configured7# Arrange for the indirect `tzdata` dependency to be installed and configured
7# without prompting for the time zone. (Passing `-y` is not enough.)8# without prompting for the time zone. (Passing `-y` is not enough.)
@@ -14,16 +15,30 @@ apt-get install --no-install-recommends -y apt-utils · 6 unmodified lines
14apt-get install --no-install-recommends -y apt-transport-https dpkg-dev gnupg15apt-get install --no-install-recommends -y apt-transport-https dpkg-dev gnupg
15type dpkg-architecture # Make sure we really have this.16type dpkg-architecture # Make sure we really have this.
16 17
17# Decide what architecture to use for `git`, shared libraries for gitoxide when18# Decide what architecture to use for `git`, shared libraries `git` links to,
18# attempting to build `max`, and shared libraries used by `git` itself.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.
19apt_suffix=26apt_suffix=
20if target_arch="$(dpkg-architecture --host-type "$target" --query DEB_HOST_ARCH)"; then27if target_arch="$(dpkg-architecture --host-type "$target" --query DEB_HOST_ARCH)"
28then
21 dpkg --add-architecture "$target_arch"29 dpkg --add-architecture "$target_arch"
22 apt_suffix=":$target_arch"30 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"
33else
34 apt_suffix=''
35 printf 'WARNING: Using HOST architecture for `git` and libs in container.\n'
23fi36fi
24 37
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.)
26release="$(sed -n 's/^VERSION_CODENAME=//p' /etc/os-release)"39release="$(sed -n 's/^VERSION_CODENAME=//p' /etc/os-release)"
40
41# Add the git-core PPA manually. (Faster than installing `add-apt-repository`.)
27echo "deb https://ppa.launchpadcontent.net/git-core/ppa/ubuntu $release main" \42echo "deb https://ppa.launchpadcontent.net/git-core/ppa/ubuntu $release main" \
28 >/etc/apt/sources.list.d/git-core-ubuntu-ppa.list43 >/etc/apt/sources.list.d/git-core-ubuntu-ppa.list
29apt-key adv --keyserver keyserver.ubuntu.com \44apt-key adv --keyserver keyserver.ubuntu.com \
@@ -94,19 +109,17 @@ file -- "$git" · 64 unmodified lines
94apt-get clean109apt-get clean
95rm -rf /tmp/dl /var/lib/apt/lists/*110rm -rf /tmp/dl /var/lib/apt/lists/*
96 111
97# If this is an Android-related image or otherwise has a runner script `cross`112# If this image has a runner script `cross` uses for Android, patch the script
98# uses for Android, then patch the script to add the ability to suppress its113# to add the ability to suppress its customization of `LD_PRELOAD`. The runner
99# customization of `LD_PRELOAD`. This runner script sets `LD_PRELOAD` to the114# script sets `LD_PRELOAD` to the path of `libc++_shared.so` in the Android NDK
100# path of `libc++_shared.so` in the vendored Android NDK. But this causes a115# (https://github.com/cross-rs/cross/blob/v0.2.5/docker/android-runner#L34).
101# problem for us because, when a non-Android (i.e. a host-architecture) program116# But this causes a problem for us. When a host-architecture program is run,
102# is run, `ld.so` shows a message about the "wrong ELF class". Such programs117# `ld.so` shows a message about the "wrong ELF class". Such programs can still
103# can still run, but when we make an assertion about, parse, or otherwise rely118# run, but when we rely on their specific output to stderr, fixtures and tests
104# on their output to standard error, we get test failures. (That especially119# fail. The change we make here lets us set `NO_PRELOAD_CXX=1` to avoid that.
105# affects fixtures.) This change lets us pass `NO_PRELOAD_CXX=1` to avoid that.120runner=/android-runner
106if test -f /android-runner; then121patch='s/^[[:blank:]]*export LD_PRELOAD=/test "${NO_PRELOAD_CXX:-0}" != 0 || &/'
107 sed -i.orig 's/^export LD_PRELOAD=/test "${NO_PRELOAD_CXX:-0}" != 0 || &/'122if test -f "$runner"; then sed -i.orig "$patch" -- "$runner"; fi
108 /android-runner
109fi
110 123
111# Ensure a nonempty Git `system` scope (for the `installation_config` tests).124# Ensure a nonempty Git `system` scope (for the `installation_config` tests).
112git config --system gitoxide.imaginary.arbitraryVariable arbitraryValue125git config --system gitoxide.imaginary.arbitraryVariable arbitraryValue
justfile+3−2
@@ -226,8 +226,9 @@ journey-tests-async: dbg · 225 unmodified lines
226 226
227# Build a customized `cross` container image for testing227# Build a customized `cross` container image for testing
228cross-image target:228cross-image target:
229 docker build --build-arg "TARGET={{ target }}" -t "cross-rs-gitoxide:{{ target }}" \229 docker build --build-arg "TARGET={{ target }}" \
230 - <etc/docker/Dockerfile.test-cross230 -t "cross-rs-gitoxide:{{ target }}" \
231 -f etc/docker/Dockerfile.test-cross etc/docker/test-cross-context
231 232
232# Test another platform with `cross`233# Test another platform with `cross`
233cross-test target *cargo-test-args: (cross-image target)234cross-test target *cargo-test-args: (cross-image target)