Skip to content

Commit

Permalink
Merge #729
Browse files Browse the repository at this point in the history
729: Refactor code to use install_packages and purge_packages. r=otavio a=Alexhuszagh

Remove all local use of installing manually via the package manager, using `install_packages` and `purge_packages` rather than use redundant code. Simplifies our shell scripts to build docker images.

Still a draft because I'm currently testing it on all images.

Co-authored-by: Alex Huszagh <ahuszagh@gmail.com>
  • Loading branch information
bors[bot] and Alexhuszagh authored Jun 2, 2022
2 parents 1689de1 + 1534e69 commit 1312fca
Show file tree
Hide file tree
Showing 11 changed files with 93 additions and 191 deletions.
1 change: 1 addition & 0 deletions docker/Dockerfile.x86_64-unknown-linux-gnu
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
FROM ubuntu:16.04
ARG DEBIAN_FRONTEND=noninteractive

COPY lib.sh /
COPY linux-image.sh /
RUN /linux-image.sh x86_64

Expand Down
22 changes: 5 additions & 17 deletions docker/android-ndk.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,26 +3,16 @@
set -x
set -euo pipefail

# shellcheck disable=SC1091
. lib.sh

NDK_URL=https://dl.google.com/android/repository/android-ndk-r21d-linux-x86_64.zip

main() {
local arch="${1}" \
api="${2}"

local dependencies=(
curl
unzip
python
)

apt-get update
local purge_list=()
for dep in "${dependencies[@]}"; do
if ! dpkg -L "${dep}"; then
apt-get install --assume-yes --no-install-recommends "${dep}"
purge_list+=( "${dep}" )
fi
done
install_packages curl unzip python

local td
td="$(mktemp -d)"
Expand All @@ -37,9 +27,7 @@ main() {
--arch "${arch}" \
--api "${api}"

if (( ${#purge_list[@]} )); then
apt-get purge --assume-yes --auto-remove "${purge_list[@]}"
fi
purge_packages

popd
popd
Expand Down
43 changes: 17 additions & 26 deletions docker/android-system.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,27 +3,15 @@
set -x
set -euo pipefail

# shellcheck disable=SC1091
. lib.sh

main() {
local arch="${1}"
local td
td="$(mktemp -d)"
pushd "${td}"

local dependencies=(
ca-certificates
curl
gcc-multilib
git
g++-multilib
libncurses5
libtinfo5
make
openssh-client
python
python3
xz-utils
)

# fake java and javac, it is not necessary for what we build, but the build
# script ask for it
cat << EOF > /usr/bin/java
Expand All @@ -46,14 +34,19 @@ EOF
mkdir /tmp/lib/
touch /tmp/lib/tools.jar

apt-get update
local purge_list=(default-jre)
for dep in "${dependencies[@]}"; do
if ! dpkg -L "${dep}"; then
apt-get install --assume-yes --no-install-recommends "${dep}"
purge_list+=( "${dep}" )
fi
done
install_packages ca-certificates \
curl \
gcc-multilib \
git \
g++-multilib \
libncurses5 \
libtinfo5 \
make \
openssh-client \
python \
python3 \
xz-utils
purge_list+=(default-jre)

curl --retry 3 -sSfL https://storage.googleapis.com/git-repo-downloads/repo -O
chmod +x repo
Expand Down Expand Up @@ -160,9 +153,7 @@ EOF

echo "127.0.0.1 localhost" > /system/etc/hosts

if (( ${#purge_list[@]} )); then
apt-get purge --auto-remove -y "${purge_list[@]}"
fi
purge_packages

popd

Expand Down
34 changes: 12 additions & 22 deletions docker/disabled/dragonfly.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,32 +3,24 @@
set -x
set -euo pipefail

# shellcheck disable=SC1091
. lib.sh

main() {
local binutils=2.25.1 \
dragonfly=4.6.1_REL \
gcc=5.3.0 \
target=x86_64-unknown-dragonfly

local dependencies=(
bsdtar
bzip2
ca-certificates
curl
g++
make
patch
wget
install_packages bsdtar \
bzip2 \
ca-certificates \
curl \
g++ \
make \
patch \
wget \
xz-utils
)

apt-get update
local purge_list=()
for dep in "${dependencies[@]}"; do
if ! dpkg -L "${dep}"; then
apt-get install --no-install-recommends --assume-yes "${dep}"
purge_list+=( "${dep}" )
fi
done

local td
td="$(mktemp -d)"
Expand Down Expand Up @@ -140,9 +132,7 @@ EOF
# clean up
popd

if (( ${#purge_list[@]} )); then
apt-get purge --assume-yes --auto-remove "${purge_list[@]}"
fi
purge_packages

rm -rf "${td}"
rm "${0}"
Expand Down
26 changes: 8 additions & 18 deletions docker/emscripten.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,23 +3,15 @@
set -x
set -euo pipefail

# shellcheck disable=SC1091
. lib.sh

main() {
local dependencies=(
ca-certificates
curl
git
libxml2
install_packages ca-certificates \
curl \
git \
libxml2 \
python
)

apt-get update
local purge_list=()
for dep in "${dependencies[@]}"; do
if ! dpkg -L "${dep}"; then
apt-get install --no-install-recommends --assume-yes "${dep}"
purge_list+=( "${dep}" )
fi
done

cd /
git clone https://github.com/emscripten-core/emsdk.git /emsdk-portable
Expand All @@ -40,9 +32,7 @@ main() {
# Make emsdk usable by any user
chmod a+rwX -R "${EMSDK}"

if (( ${#purge_list[@]} )); then
apt-get purge --assume-yes --auto-remove "${purge_list[@]}"
fi
purge_packages

rm "${0}"
}
Expand Down
27 changes: 8 additions & 19 deletions docker/freebsd.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ set -euo pipefail
export ARCH="${1}"
# shellcheck disable=SC1091
. freebsd-common.sh
# shellcheck disable=SC1091
. lib.sh

max_freebsd() {
local best=
Expand Down Expand Up @@ -50,23 +52,12 @@ main() {
gcc=6.4.0 \
target="${ARCH}-unknown-freebsd${BSD_MAJOR}"

local dependencies=(
ca-certificates
curl
g++
make
wget
install_packages ca-certificates \
curl \
g++ \
make \
wget \
xz-utils
)

apt-get update
local purge_list=()
for dep in "${dependencies[@]}"; do
if ! dpkg -L "${dep}"; then
apt-get install --no-install-recommends --assume-yes "${dep}"
purge_list+=( "${dep}" )
fi
done

local td
td="$(mktemp -d)"
Expand Down Expand Up @@ -144,9 +135,7 @@ main() {
# clean up
popd

if (( ${#purge_list[@]} )); then
apt-get purge --assume-yes --auto-remove "${purge_list[@]}"
fi
purge_packages

# store the version info for the FreeBSD release
bsd_revision=$(curl --retry 3 -sSfL "${bsd_http}/REVISION")
Expand Down
26 changes: 8 additions & 18 deletions docker/linux-image.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@
set -x
set -euo pipefail

# shellcheck disable=SC1091
. lib.sh

main() {
# arch in the rust target
local arch="${1}" \
Expand Down Expand Up @@ -94,22 +97,11 @@ main() {
;;
esac

local dependencies=(
ca-certificates
curl
cpio
sharutils
install_packages ca-certificates \
curl \
cpio \
sharutils \
gnupg
)

local purge_list=()
apt-get update
for dep in "${dependencies[@]}"; do
if ! dpkg -L "${dep}" >/dev/null 2>/dev/null; then
apt-get install --assume-yes --no-install-recommends "${dep}"
purge_list+=( "${dep}" )
fi
done

# Download packages
mv /etc/apt/sources.list /etc/apt/sources.list.bak
Expand Down Expand Up @@ -274,9 +266,7 @@ EOF
dpkg --remove-architecture "${arch}" || true
apt-get update

if (( ${#purge_list[@]} )); then
apt-get purge --assume-yes --auto-remove "${purge_list[@]}"
fi
purge_packages

ls -lh /qemu
}
Expand Down
15 changes: 5 additions & 10 deletions docker/mingw.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@
set -x
set -euo pipefail

# shellcheck disable=SC1091
. lib.sh

main() {
# Ubuntu mingw packages for i686 uses sjlj exceptions, but rust target
# i686-pc-windows-gnu uses dwarf exceptions. So we build mingw packages
Expand All @@ -20,13 +23,7 @@ main() {
while IFS='' read -r dep; do dependencies+=("${dep}"); done < \
<(apt-cache showsrc gcc-mingw-w64-i686 | grep Build | cut -d: -f2 | tr , '\n' | cut -d' ' -f2 | sort | uniq)

local purge_list=()
for dep in "${dependencies[@]}"; do
if ! dpkg -L "${dep}" > /dev/null; then
apt-get install --assume-yes --no-install-recommends "${dep}"
purge_list+=( "${dep}" )
fi
done
install_packages "${dependencies[@]}"

local td
td="$(mktemp -d)"
Expand Down Expand Up @@ -118,9 +115,7 @@ EOF
# Replace installed mingw packages with the new ones
dpkg -i ../g*-mingw-w64-i686*.deb ../gcc-mingw-w64-base*.deb

if (( ${#purge_list[@]} )); then
apt-get purge --assume-yes --auto-remove "${purge_list[@]}"
fi
purge_packages

popd
popd
Expand Down
22 changes: 5 additions & 17 deletions docker/musl.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@
set -x
set -euo pipefail

# shellcheck disable=SC1091
. lib.sh

hide_output() {
set +x
trap "
Expand All @@ -21,20 +24,7 @@ hide_output() {
main() {
local version=0.9.9

local dependencies=(
ca-certificates
curl
build-essential
)

apt-get update
local purge_list=()
for dep in "${dependencies[@]}"; do
if ! dpkg -L "${dep}"; then
apt-get install --assume-yes --no-install-recommends "${dep}"
purge_list+=( "${dep}" )
fi
done
install_packages ca-certificates curl build-essential

local td
td="$(mktemp -d)"
Expand All @@ -55,9 +45,7 @@ main() {
OUTPUT=/usr/local/ \
"${@}"

if (( ${#purge_list[@]} )); then
apt-get purge --assume-yes --auto-remove "${purge_list[@]}"
fi
purge_packages

popd

Expand Down
Loading

0 comments on commit 1312fca

Please sign in to comment.