diff --git a/Dockerfile.mri.erb b/Dockerfile.mri.erb index 5350b51f..db82e689 100644 --- a/Dockerfile.mri.erb +++ b/Dockerfile.mri.erb @@ -23,11 +23,13 @@ RUN rm -f /usr/local/bin/sudo && \ echo "%sudo ALL=(ALL) ALL" >> /etc/sudoers <% else %> ENV DEBIAN_FRONTEND noninteractive -RUN dpkg --add-architecture <%= foreign_dpkg_arch %> && \ - apt-get -y update && \ - apt-get install -y sudo wget autoconf cmake curl git-core pkg-config build-essential xz-utils unzip gnupg2 dirmngr && \ - apt-get install -y zlib1g-dev:<%= foreign_dpkg_arch %> libreadline-dev:<%= foreign_dpkg_arch %> libsqlite0-dev:<%= foreign_dpkg_arch %> libssl-dev:<%= foreign_dpkg_arch %> libyaml-dev:<%= foreign_dpkg_arch %> libffi-dev:<%= foreign_dpkg_arch %> && \ - rm -rf /var/lib/apt/lists/* +COPY ./build/setup_dpkg_multiarch_for_target.sh / +RUN /setup_dpkg_multiarch_for_target.sh <%= foreign_dpkg_arch %>; + +RUN apt-get -y -qq update && \ + apt-get -y -qq install sudo wget autoconf cmake curl git-core pkg-config build-essential xz-utils unzip gnupg2 dirmngr && \ + apt-get -y -qq install zlib1g-dev:<%= foreign_dpkg_arch %> libreadline-dev:<%= foreign_dpkg_arch %> libsqlite0-dev:<%= foreign_dpkg_arch %> libssl-dev:<%= foreign_dpkg_arch %> libyaml-dev:<%= foreign_dpkg_arch %> libffi-dev:<%= foreign_dpkg_arch %> && \ + rm -rf /var/lib/apt/lists/*; <% end %> # Add "rvm" as system group, to avoid conflicts with host GIDs typically starting with 1000 @@ -92,7 +94,6 @@ RUN apt-get -y update && \ apt-get install -y <% if platform=~/darwin/ %> clang python lzma-dev libxml2-dev libssl-dev libc++-10-dev <% end %><% if platform=~/aarch64-linux/ %> gcc-aarch64-linux-gnu g++-aarch64-linux-gnu <% end %><% -if platform=~/x86_64-linux/ %> gcc-x86-64-linux-gnu g++-x86-64-linux-gnu <% end %><% if platform=~/arm-linux/ %> gcc-arm-linux-gnueabihf g++-arm-linux-gnueabihf <% end %><% if platform=~/x86-mingw32/ %> gcc-mingw-w64-i686 g++-mingw-w64-i686 <% end %><% if platform=~/x64-mingw32/ %> gcc-mingw-w64-x86-64 g++-mingw-w64-x86-64 <% end %> && \ diff --git a/build/setup_dpkg_multiarch_for_target.sh b/build/setup_dpkg_multiarch_for_target.sh new file mode 100755 index 00000000..657899cf --- /dev/null +++ b/build/setup_dpkg_multiarch_for_target.sh @@ -0,0 +1,43 @@ +#!/bin/bash + +set -exuo pipefail +IFS=$'\n\t' + +main() { + local to_uninstall=() + + if ! command -v dpkg-architecture; then + echo "dpkg-architecture not found, installing" >&2 + apt-get -qq -y update + apt-get -qq -y install --no-install-recommends debhelper lsb-release + rm -rf /var/lib/apt/lists/* + to_uninstall+=("debhelper" "lsb-release") + fi + + deb_host_arch="$(dpkg-architecture --query DEB_HOST_ARCH)" + deb_target_arch="$1" + + if [ "$deb_target_arch" != "$deb_host_arch" ]; then + echo "Setting up multiarch support for $deb_target_arch" >&2 + + # Add arch support for target so we can install libs + dpkg --add-architecture "$deb_target_arch" + # Qualify our current source lists to make sure debian doesn't infer stuff + sed -i "s/^deb http/deb [arch=$deb_host_arch] http/" /etc/apt/sources.list + # Add sources for ported target libs + sh -c "echo \"deb [arch=$deb_target_arch] http://ports.ubuntu.com/ubuntu-ports $(lsb_release -cs) main universe restricted multiverse\" >> /etc/apt/sources.list" + sh -c "echo \"deb [arch=$deb_target_arch] http://ports.ubuntu.com/ubuntu-ports $(lsb_release -cs)-updates main universe restricted multiverse\" >> /etc/apt/sources.list" + sh -c "echo \"deb [arch=$deb_target_arch] http://ports.ubuntu.com/ubuntu-ports $(lsb_release -cs)-security main universe restricted multiverse\" >> /etc/apt/sources.list" + apt-get update + else + echo "No need to set up multiarch support for $deb_target_arch" + fi + + if [ "${#to_uninstall[@]}" -gt 0 ]; then + apt-get remove -y "${to_uninstall[@]}" + fi + + rm "$0" +} + +main "$@"