Skip to content

Commit a203bf4

Browse files
committed
Start toward moving the dense RUN to a commented script
1 parent 6e3e068 commit a203bf4

File tree

1 file changed

+112
-0
lines changed

1 file changed

+112
-0
lines changed
Lines changed: 112 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,112 @@
1+
#!/bin/bash
2+
set -euxC
3+
4+
target="$1"
5+
6+
# Arrange for the indirect `tzdata` dependency to be installed and configured
7+
# without prompting for the time zone. (Passing `-y` is not enough.)
8+
export DEBIAN_FRONTEND=noninteractive TZ=UTC
9+
10+
# Install tools for setting up APT repositores. Install `apt-utils` before the
11+
# others, so the installation of `gnupg` can use it for debconf.
12+
apt-get update
13+
apt-get install --no-install-recommends -y apt-utils
14+
apt-get install --no-install-recommends -y apt-transport-https dpkg-dev gnupg
15+
type dpkg-architecture # Make sure we really have this.
16+
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.
19+
apt_suffix=
20+
if target_arch="$(dpkg-architecture --host-type "$target" --query DEB_HOST_ARCH)"; then
21+
dpkg --add-architecture "$target_arch"
22+
apt_suffix=":$target_arch"
23+
fi
24+
25+
# Add the git-core PPA manually. (Faster than installing `add-apt-repository`.)
26+
release="$(sed -n 's/^VERSION_CODENAME=//p' /etc/os-release)"
27+
echo "deb https://ppa.launchpadcontent.net/git-core/ppa/ubuntu $release main" \
28+
>/etc/apt/sources.list.d/git-core-ubuntu-ppa.list
29+
apt-key adv --keyserver keyserver.ubuntu.com \
30+
--recv-keys F911AB184317630C59970973E363C90F8F1B6217
31+
apt-get update
32+
33+
# Remove the old `git` and associated packages.
34+
apt-get purge --autoremove -y git
35+
36+
# Git dependencies. These are for the desired architecture, except `git-man` is
37+
# the same package for all architectures, and we can't always install `perl` or
38+
# `liberror-perl` for the desired architecture (at least in s390x).
39+
# TODO(maint): Resolve these dynamically to support future `cross` base images.
40+
git_deps=(
41+
git-man
42+
"libc6$apt_suffix"
43+
"libcurl3-gnutls$apt_suffix"
44+
"libexpat1$apt_suffix"
45+
liberror-perl
46+
"libpcre2-8-0$apt_suffix"
47+
"zlib1g$apt_suffix"
48+
perl
49+
)
50+
51+
# Other dependencies for running the gitoxide test suite and fixture scripts,
52+
# and for building and testing gitoxide for feature sets beyond `max-pure`.
53+
gix_test_deps=(
54+
ca-certificates
55+
cmake
56+
"curl$apt_suffix"
57+
jq
58+
"libc-dev$apt_suffix"
59+
"libssl-dev$apt_suffix"
60+
patch
61+
pkgconf
62+
)
63+
64+
# Install everything we need except `git` (and what we already have). We can't
65+
# necessarily install `git` this way, because it insists on `perl` and
66+
# `liberror-perl` dependencies of the same architecture as it. These may not be
67+
# possible to install in a mixed environment, where most packages are a
68+
# different architecture, and where `perl` is a dependency of other important
69+
# packages. So we will install everything else first (then manually add `git`).
70+
apt-get install --no-install-recommends -y \
71+
"${git_deps[@]}" "${gix_test_deps[@]}" file
72+
73+
# Add `git` by manually downloading it and installing it with `dpkg`, forcing
74+
# installation to proceed even if its `perl` and `liberror-perl` dependencies,
75+
# as declared by `git`, are absent. (We have already installed them, but in a
76+
# possibly different architecture. `git` can still use them, because its use is
77+
# to run scripts, rather than to link to a shared library they provide.) It is
78+
# preferred to let `apt-get download` drop privileges to the `_apt` user during
79+
# download, so we download it inside `/tmp`. But we create a subdirectory so it
80+
# is safe to make assumptions about what files globs can expand to, even if
81+
# `/tmp` is mounted to an outside share temp dir on a multi-user system.
82+
mkdir /tmp/dl # Don't use `-p`; if it exists already, we cannot trust it.
83+
chown _apt /tmp/dl # Use owner, as the container may not have an `_apt` group.
84+
(cd /tmp/dl && apt-get download "git$apt_suffix")
85+
dpkg --ignore-depends="perl$apt_suffix,liberror-perl$apt_suffix" \
86+
-i /tmp/dl/git[-_]*.deb
87+
88+
# Show information about the newly installed `git` (and ensure it can run).
89+
git version --build-options
90+
git="$(command -v git)"
91+
file -- "$git"
92+
93+
# Clean up files related to package management that we won't need anymore.
94+
apt-get clean
95+
rm -rf /tmp/dl /var/lib/apt/lists/*
96+
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
110+
111+
# Ensure a nonempty Git `system` scope (for the `installation_config` tests).
112+
git config --system gitoxide.imaginary.arbitraryVariable arbitraryValue

0 commit comments

Comments
 (0)